diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2021-07-17 03:13:16 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-17 03:13:16 +0530 |
| commit | 921e9f96b9bec5e2bf8633947792d6991956507f (patch) | |
| tree | 6de848fc6edaf962b71277e704519cd90bcd0b8e /format-common/src/main/kotlin/dev/msfjarvis/aps/util | |
| parent | fd6d0e52fc378eefd3de35bc9e7778897ccc396f (diff) | |
| download | HardenedPass-921e9f96b9bec5e2bf8633947792d6991956507f.tar.gz HardenedPass-921e9f96b9bec5e2bf8633947792d6991956507f.zip | |
Refactor TOTP implementation and expand SteamGuard hacks (#1460)
* UriTotpFinder: commonize query parameter handling
* gitignore: add more IDEA files
* TotpFinder: add `findIssuer`
* PasswordEntry: don't eagerly fetch TOTP related fields
* format-common: expand SteamGuard workaround
* CHANGELOG: add SteamGuard workaround
Diffstat (limited to 'format-common/src/main/kotlin/dev/msfjarvis/aps/util')
| -rw-r--r-- | format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt | 14 | ||||
| -rw-r--r-- | format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/TotpFinder.kt | 3 |
2 files changed, 13 insertions, 4 deletions
diff --git a/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt b/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt index 65284441..f1f71e00 100644 --- a/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt +++ b/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/Otp.kt @@ -23,8 +23,13 @@ internal object Otp { check(STEAM_ALPHABET.size == 26) } - fun calculateCode(secret: String, counter: Long, algorithm: String, digits: String) = - runCatching { + fun calculateCode( + secret: String, + counter: Long, + algorithm: String, + digits: String, + issuer: String?, + ) = runCatching { val algo = "Hmac${algorithm.uppercase(Locale.ROOT)}" val decodedSecret = BASE_32.decode(secret) val secretKey = SecretKeySpec(decodedSecret, algo) @@ -40,8 +45,9 @@ internal object Otp { code[0] = (0x7f and code[0].toInt()).toByte() val codeInt = ByteBuffer.wrap(code).int check(codeInt > 0) - if (digits == "s") { - // Steam + // SteamGuard is a horrible OTP implementation that generates non-standard 5 digit OTPs as well + // as uses a custom character set. + if (digits == "s" || issuer == "Steam") { var remainingCodeInt = codeInt buildString { repeat(5) { diff --git a/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/TotpFinder.kt b/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/TotpFinder.kt index 64f22065..1cb7de97 100644 --- a/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/TotpFinder.kt +++ b/format-common/src/main/kotlin/dev/msfjarvis/aps/util/totp/TotpFinder.kt @@ -20,6 +20,9 @@ public interface TotpFinder { /** Get the algorithm for the TOTP secret. */ public fun findAlgorithm(content: String): String + /** Get the issuer for the TOTP secret, if any. */ + public fun findIssuer(content: String): String? + public companion object { public val TOTP_FIELDS: Array<String> = arrayOf("otpauth://totp", "totp:") } |
