tests for totp
This commit is contained in:
parent
1c286dd2f0
commit
39752b36ec
@ -53,7 +53,29 @@ public class OTPTest {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void totpTest() {
|
@Test
|
||||||
|
public void totpTest() {
|
||||||
|
String expectedValues[] = {
|
||||||
|
"94287082",
|
||||||
|
"46119246",
|
||||||
|
"90693936",
|
||||||
|
"07081804",
|
||||||
|
"68084774",
|
||||||
|
"25091201",
|
||||||
|
"14050471",
|
||||||
|
"67062674",
|
||||||
|
"99943326",
|
||||||
|
"89005924",
|
||||||
|
"91819424",
|
||||||
|
"93441116",
|
||||||
|
"69279037",
|
||||||
|
"90698825",
|
||||||
|
"38618901",
|
||||||
|
"65353130",
|
||||||
|
"77737706",
|
||||||
|
"47863826"
|
||||||
|
};
|
||||||
|
|
||||||
// Seed for HMAC-SHA1 - 20 bytes
|
// Seed for HMAC-SHA1 - 20 bytes
|
||||||
String base16seed = "3132333435363738393031323334353637383930";
|
String base16seed = "3132333435363738393031323334353637383930";
|
||||||
// Seed for HMAC-SHA256 - 32 bytes
|
// Seed for HMAC-SHA256 - 32 bytes
|
||||||
@ -78,21 +100,33 @@ public class OTPTest {
|
|||||||
df.setTimeZone(TimeZone.getTimeZone("UTC"));
|
df.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println("+---------------+-----------------------+--------+--------+");
|
if(VERBOSE) {
|
||||||
System.out.println("| Time(sec) | Time (UTC format) | TOTP | Mode |");
|
System.out.println("+---------------+-----------------------+--------+--------+");
|
||||||
System.out.println("+---------------+-----------------------+--------+--------+");
|
System.out.println("| Time(sec) | Time (UTC format) | TOTP | Mode |");
|
||||||
|
System.out.println("+---------------+-----------------------+--------+--------+");
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < testTime.length; i++) {
|
for (int i = 0; i < testTime.length; i++) {
|
||||||
String fmtTime = String.format("%1$-11s", testTime[i]);
|
String fmtTime = String.format("%1$-11s", testTime[i]);
|
||||||
String utcTime = df.format(new Date(testTime[i] * 1000));
|
String utcTime = df.format(new Date(testTime[i] * 1000));
|
||||||
|
|
||||||
System.out.println(
|
String sha1Pin = testOTP1.getPinAt(testTime[i]);
|
||||||
"| " + fmtTime + " | " + utcTime + " |" + testOTP1.getPinAt(testTime[i]) + "| SHA1 |");
|
String sha256Pin = testOTP256.getPinAt(testTime[i]);
|
||||||
System.out.println(
|
String sha512Pin = testOTP512.getPinAt(testTime[i]);
|
||||||
"| " + fmtTime + " | " + utcTime + " |" + testOTP256.getPinAt(testTime[i]) + "| SHA256 |");
|
|
||||||
System.out.println(
|
|
||||||
"| " + fmtTime + " | " + utcTime + " |" + testOTP512.getPinAt(testTime[i]) + "| SHA512 |");
|
|
||||||
System.out.println("+---------------+-----------------------+--------+--------+");
|
|
||||||
|
if(VERBOSE) {
|
||||||
|
System.out.println("| " + fmtTime + " | " + utcTime + " |" + sha1Pin + "| SHA1 |");
|
||||||
|
System.out.println("| " + fmtTime + " | " + utcTime + " |" + sha256Pin + "| SHA256 |");
|
||||||
|
System.out.println("| " + fmtTime + " | " + utcTime + " |" + sha512Pin + "| SHA512 |");
|
||||||
|
System.out.println("+---------------+-----------------------+--------+--------+");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(expectedValues[i * 3 + 0], sha1Pin);
|
||||||
|
assertEquals(expectedValues[i * 3 + 1], sha256Pin);
|
||||||
|
assertEquals(expectedValues[i * 3 + 2], sha512Pin);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user