aboutsummaryrefslogtreecommitdiffstats
path: root/format-common/src/main/kotlin/dev/msfjarvis/aps/data
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-07-17 03:13:16 +0530
committerGitHub <noreply@github.com>2021-07-17 03:13:16 +0530
commit921e9f96b9bec5e2bf8633947792d6991956507f (patch)
tree6de848fc6edaf962b71277e704519cd90bcd0b8e /format-common/src/main/kotlin/dev/msfjarvis/aps/data
parentfd6d0e52fc378eefd3de35bc9e7778897ccc396f (diff)
downloadHardenedPass-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/data')
-rw-r--r--format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt24
1 files changed, 14 insertions, 10 deletions
diff --git a/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt b/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt
index 4fc9667d..0e8f6d2e 100644
--- a/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt
+++ b/format-common/src/main/kotlin/dev/msfjarvis/aps/data/passfile/PasswordEntry.kt
@@ -68,10 +68,7 @@ constructor(
* and usernames stripped.
*/
public val extraContentWithoutAuthData: String
- private val digits: String
private val totpSecret: String?
- private val totpPeriod: Long
- private val totpAlgorithm: String
init {
val (foundPassword, passContent) = findAndStripPassword(content.split("\n".toRegex()))
@@ -80,17 +77,18 @@ constructor(
extraContentWithoutAuthData = generateExtraContentWithoutAuthData()
extraContent = generateExtraContentPairs()
username = findUsername()
- digits = totpFinder.findDigits(content)
totpSecret = totpFinder.findSecret(content)
- totpPeriod = totpFinder.findPeriod(content)
- totpAlgorithm = totpFinder.findAlgorithm(content)
if (totpSecret != null) {
scope.launch {
- updateTotp(clock.millis())
+ val digits = totpFinder.findDigits(content)
+ val totpPeriod = totpFinder.findPeriod(content)
+ val totpAlgorithm = totpFinder.findAlgorithm(content)
+ val issuer = totpFinder.findIssuer(content)
val remainingTime = totpPeriod - (clock.millis() % totpPeriod)
+ updateTotp(clock.millis(), totpPeriod, totpAlgorithm, digits, issuer)
delay(Duration.seconds(remainingTime))
repeat(Int.MAX_VALUE) {
- updateTotp(clock.millis())
+ updateTotp(clock.millis(), totpPeriod, totpAlgorithm, digits, issuer)
delay(Duration.seconds(totpPeriod))
}
}
@@ -186,9 +184,15 @@ constructor(
return null
}
- private fun updateTotp(millis: Long) {
+ private fun updateTotp(
+ millis: Long,
+ totpPeriod: Long,
+ totpAlgorithm: String,
+ digits: String,
+ issuer: String?,
+ ) {
if (totpSecret != null) {
- Otp.calculateCode(totpSecret, millis / (1000 * totpPeriod), totpAlgorithm, digits)
+ Otp.calculateCode(totpSecret, millis / (1000 * totpPeriod), totpAlgorithm, digits, issuer)
.mapBoth({ code -> _totp.value = code }, { throwable -> throw throwable })
}
}