aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/utils
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-05-28 22:42:13 +0530
committerGitHub <noreply@github.com>2020-05-28 22:42:13 +0530
commite7463ec24c929860f0a7311b558f496919d54d20 (patch)
treeeb460f7e49e1a71acaceaec305e511bb4c0a9d45 /app/src/main/java/com/zeapo/pwdstore/utils
parentffcbabc2f4ef9766271be5335cec1869fe634646 (diff)
downloadHardenedPass-e7463ec24c929860f0a7311b558f496919d54d20.tar.gz
HardenedPass-e7463ec24c929860f0a7311b558f496919d54d20.zip
Remove HOTP/TOTP support (#806)
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/utils')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/Otp.java63
1 files changed, 0 insertions, 63 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
deleted file mode 100644
index 07f73423..00000000
--- a/app/src/main/java/com/zeapo/pwdstore/utils/Otp.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-package com.zeapo.pwdstore.utils;
-
-import org.apache.commons.codec.binary.Base32;
-
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
-import timber.log.Timber;
-
-public class Otp {
-
- private static final Base32 BASE_32 = new Base32();
-
- private Otp() {
- }
-
- 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;
- try {
- mac = Mac.getInstance(ALGORITHM);
- mac.init(signingKey);
- } catch (NoSuchAlgorithmException e) {
- Timber.tag("TOTP").e(e, "%s unavailable - should never happen", ALGORITHM);
- return null;
- } catch (InvalidKeyException e) {
- Timber.tag("TOTP").e(e, "Key is malformed");
- return null;
- }
-
- byte[] digest = mac.doFinal(ByteBuffer.allocate(8).putLong(counter).array());
- int offset = digest[digest.length - 1] & 0xf;
- byte[] code = Arrays.copyOfRange(digest, offset, offset + 4);
- code[0] = (byte) (0x7f & code[0]);
- String strCode = new BigInteger(code).toString();
- if (digits.equals("s")) {
- StringBuilder output = new StringBuilder();
- int bigInt = new BigInteger(code).intValue();
- for (int i = 0; i != 5; i++) {
- output.append(steam[bigInt % 26]);
- bigInt /= 26;
- }
- return output.toString();
- } else return strCode.substring(strCode.length() - Integer.parseInt(digits));
- }
-}