Skip to content
This repository was archived by the owner on Jan 29, 2021. It is now read-only.

Commit 1380727

Browse files
committed
2step initialization
Implemented 2step according to privacyidea/privacyidea#797 #4 #5 Removed Bcrypt and Scrypt.
1 parent a6d605f commit 1380727

File tree

7 files changed

+109
-848
lines changed

7 files changed

+109
-848
lines changed

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ dependencies {
4848
implementation 'org.mockito:mockito-core:1.10.19'
4949
implementation 'com.android.support:support-v4:25.4.0'
5050
implementation 'com.android.support:support-vector-drawable:25.4.0'
51+
5152
testImplementation 'junit:junit:4.12'
5253
testImplementation 'org.mockito:mockito-core:1.10.19'
54+
5355
androidTestImplementation 'com.android.support:support-annotations:25.4.0'
5456
androidTestImplementation 'com.android.support.test:runner:1.0.1'
5557
androidTestImplementation 'com.android.support.test:rules:1.0.1'

app/src/androidTest/java/it/netknights/androidTest/InstrumentedTest.java

+2-37
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@
2929
import javax.crypto.spec.IvParameterSpec;
3030
import javax.crypto.spec.SecretKeySpec;
3131

32-
import it.netknights.piauthenticator.BCrypt;
3332
import it.netknights.piauthenticator.EncryptionHelper;
34-
import it.netknights.piauthenticator.OTPGenerator;
33+
import it.netknights.piauthenticator.MainActivity;
3534
import it.netknights.piauthenticator.Token;
3635
import it.netknights.piauthenticator.Util;
3736

3837
import static it.netknights.piauthenticator.OTPGenerator.generateHOTP;
3938
import static it.netknights.piauthenticator.OTPGenerator.generatePBKDFKey;
4039
import static it.netknights.piauthenticator.OTPGenerator.byteArrayToHexString;
41-
import static it.netknights.piauthenticator.OTPGenerator.hexStringToByteArray;
4240
import static junit.framework.Assert.assertEquals;
4341
import static junit.framework.Assert.assertTrue;
4442
import static junit.framework.Assert.fail;
@@ -56,10 +54,10 @@ public void testMakeTokenFromURI() throws Exception {
5654
keyStore.deleteEntry("settings");
5755

5856
}
57+
MainActivity utils = new MainActivity(); //TODO update this test
5958
assertTrue(new File(context.getFilesDir() + "/data.dat").delete());
6059
assertTrue(new File(context.getFilesDir() + "/key.key").delete());
6160

62-
Util utils = Util.getInstance();
6361

6462
Token hotp = utils.makeTokenFromURI("otpauth://hotp" +
6563
"/OATH00014BE1?secret=2VKLHJMESGDZDXO7UO5GRH6T34CSYWYY&counter=1&digits=6&issuer=privacyIDEA");
@@ -248,39 +246,6 @@ public void testPBKDF2() throws InvalidKeySpecException, NoSuchAlgorithmExceptio
248246
assertEquals("56fa6aa75548099dcc37d7f03425e0c3", byteArrayToHexString(generatePBKDFKey(p, s, 4096, 128)));
249247
}
250248

251-
@Test
252-
public void testBCrypt() {
253-
Object[][] testVectors = {
254-
{"", "144b3d691a7b4ecf39cf735c7fa7a79c", Integer.valueOf(6), "557e94f34bf286e8719a26be94ac1e16d95ef9f819dee092"},
255-
{"00", "144b3d691a7b4ecf39cf735c7fa7a79c", Integer.valueOf(6), "557e94f34bf286e8719a26be94ac1e16d95ef9f819dee092"},
256-
{"00", "26c63033c04f8bcba2fe24b574db6274", Integer.valueOf(8), "56701b26164d8f1bc15225f46234ac8ac79bf5bc16bf48ba"},
257-
{"00", "9b7c9d2ada0fd07091c915d1517701d6", Integer.valueOf(10), "7b2e03106a43c9753821db688b5cc7590b18fdf9ba544632"},
258-
{"6100", "a3612d8c9a37dac2f99d94da03bd4521", Integer.valueOf(6), "e6d53831f82060dc08a2e8489ce850ce48fbf976978738f3"},
259-
{"6100", "7a17b15dfe1c4be10ec6a3ab47818386", Integer.valueOf(8), "a9f3469a61cbff0a0f1a1445dfe023587f38b2c9c40570e1"},
260-
{"6100", "9bef4d04e1f8f92f3de57323f8179190", Integer.valueOf(10), "5169fd39606d630524285147734b4c981def0ee512c3ace1"},
261-
{"61626300", "2a1f1dc70a3d147956a46febe3016017", Integer.valueOf(6), "d9a275b493bcbe1024b0ff80d330253cfdca34687d8f69e5"},
262-
{"61626300", "4ead845a142c9bc79918c8797f470ef5", Integer.valueOf(8), "8d4131a723bfbbac8a67f2e035cae08cc33b69f37331ea91"},
263-
{"61626300", "631c554493327c32f9c26d9be7d18e4c", Integer.valueOf(10), "8cd0b863c3ff0860e31a2b42427974e0283b3af7142969a6"},
264-
{"6162636465666768696a6b6c6d6e6f707172737475767778797a00", "02d1176d74158ee29cffdac6150cf123", Integer.valueOf(6), "4d38b523ce9dc6f2f6ff9fb3c2cd71dfe7f96eb4a3baf19f"},
265-
{"6162636465666768696a6b6c6d6e6f707172737475767778797a00", "715b96caed2ac92c354ed16c1e19e38a", Integer.valueOf(8), "98bf9ffc1f5be485f959e8b1d526392fbd4ed2d5719f506b"},
266-
{"6162636465666768696a6b6c6d6e6f707172737475767778797a00", "85727e838f9049397fbec90566ede0df", Integer.valueOf(10), "cebba53f67bd28af5a44c6707383c231ac4ef244a6f5fb2b"},
267-
{"7e21402324255e262a28292020202020207e21402324255e262a2829504e4246524400", "8512ae0d0fac4ec9a5978f79b6171028", Integer.valueOf(6), "26f517fe5345ad575ba7dfb8144f01bfdb15f3d47c1e146a"},
268-
{"7e21402324255e262a28292020202020207e21402324255e262a2829504e4246524400", "1ace2de8807df18c79fced54678f388f", Integer.valueOf(8), "d51d7cdf839b91a25758b80141e42c9f896ae80fd6cd561f"},
269-
{"7e21402324255e262a28292020202020207e21402324255e262a2829504e4246524400", "36285a6267751b14ba2dc989f6d43126", Integer.valueOf(10), "db4fab24c1ff41c1e2c966f8b3d6381c76e86f52da9e15a9"},
270-
{"c2a300", "144b3d691a7b4ecf39cf735c7fa7a79c", Integer.valueOf(6), "5a6c4fedb23980a7da9217e0442565ac6145b687c7313339"},
271-
};
272-
273-
for (int i = 0; i < testVectors.length; i++) {
274-
byte[] password = hexStringToByteArray((String) testVectors[i][0]);
275-
byte[] salt = hexStringToByteArray((String) testVectors[i][1]);
276-
int rounds = ((Integer) testVectors[i][2]).intValue();
277-
String expected = (String) testVectors[i][3];
278249

279-
String hash = BCrypt.hashpw(byteArrayToHexString(password), byteArrayToHexString(salt), rounds);
280-
if (!hash.equals(expected)) {
281-
fail("Hash for pw: " + byteArrayToHexString(password) + ",exp: " + expected + ",act: " + hash);
282-
}
283-
}
284-
}
285250

286251
}

0 commit comments

Comments
 (0)