summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-09-05 20:12:19 +0530
committerGitHub <noreply@github.com>2020-09-05 20:12:19 +0530
commit6713d489746830d83437e6a8f6eb88624070b7c5 (patch)
treeab8b13554daca7e0297e55af6af73e7391851330
parent0b85779eec8cb889bd1fc025bec8425b9386200d (diff)
DecryptActivity: properly calculate remaining OTP time on first pass (#1080)
* DecryptActivity: properly calculate remaining OTP time on first pass We default to 30 seconds for each recalculation but the first run might not have 30 seconds left in its period, making the value stale much earlier. While most websites offer another 30 seconds of validity for TOTP codes, many do not, thus making it hard to enter a correct OTP Signed-off-by: Harsh Shandilya <me@msfjarvis.dev> * Update changelog Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt7
2 files changed, 8 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c762dc2..ae99f685 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
- Git server protocol and authentication mode are only updated when explicitly saved
- Remember HTTPS password during a sync operation
- Unable to use show/hide password option for password/passphrase after first attempt was wrong
+- TOTP values shown might some times be stale and considered invalid by sites
## [1.11.3] - 2020-08-27
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt
index 79f9e6da..f2f50e8e 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt
@@ -194,6 +194,13 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
)
}
launch(Dispatchers.IO) {
+ // Calculate the actual remaining time for the first pass
+ // then return to the standard 30 second affair.
+ val remainingTime = entry.totpPeriod - (System.currentTimeMillis() % entry.totpPeriod)
+ withContext(Dispatchers.Main) {
+ otpText.setText(entry.calculateTotpCode() ?: "Error")
+ }
+ delay(remainingTime.seconds)
repeat(Int.MAX_VALUE) {
val code = entry.calculateTotpCode() ?: "Error"
withContext(Dispatchers.Main) {