diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2019-03-19 20:34:41 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-19 20:34:41 +0530 |
| commit | 94bf103b337d9df1d6232d85f5edf4673ede651c (patch) | |
| tree | 84c3971b0f95f0586923b5e3a8262137236a2b80 /app/src/main/java/com/zeapo/pwdstore/utils | |
| parent | 59ac91ebbc9f1d63c0377890902cc5c12f0af4c6 (diff) | |
| parent | 2ca59d95f962d333f56c714f1e0b97d38db4785a (diff) | |
| download | HardenedPass-94bf103b337d9df1d6232d85f5edf4673ede651c.tar.gz HardenedPass-94bf103b337d9df1d6232d85f5edf4673ede651c.zip | |
Merge pull request #491 from igaryhe/master
Read OTP digits, algorithm, period from URI, support Steam Guard
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/utils/Otp.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java b/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java index 35e773e4..0bacd684 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java @@ -12,17 +12,17 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; public class Otp { - public static final int TIME_WINDOW = 30; - - private static final String ALGORITHM = "HmacSHA1"; - private static final int CODE_DIGITS = 6; private static final Base32 BASE_32 = new Base32(); private Otp() { } - public static String calculateCode(String secret, long counter) { + public static String calculateCode(String secret, long counter, String algorithm, String digits) { + String[] steam = {"2", "3", "4", "5", "6", "7", "8", "9", "B", "C", + "D", "F", "G", "H", "J", "K", "M", "N", "P", "Q", + "R", "T", "V", "W", "X", "Y"}; + String ALGORITHM = "Hmac" + algorithm.toUpperCase(); SecretKeySpec signingKey = new SecretKeySpec(BASE_32.decode(secret), ALGORITHM); Mac mac; @@ -42,6 +42,15 @@ public class Otp { byte[] code = Arrays.copyOfRange(digest, offset, offset + 4); code[0] = (byte) (0x7f & code[0]); String strCode = new BigInteger(code).toString(); - return strCode.substring(strCode.length() - CODE_DIGITS); + if (digits.equals("s")) { + String output = ""; + int bigInt = new BigInteger(code).intValue(); + for (int i = 0; i != 5; i++) { + output += steam[bigInt % 26]; + bigInt /= 26; + } + return output; + } + else return strCode.substring(strCode.length() - Integer.parseInt(digits)); } } |
