diff options
author | agrahn <agrahn@users.noreply.github.com> | 2024-07-28 21:33:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-28 19:33:16 +0000 |
commit | 57866a9895e98e43b15a9de0926c9c04e966bd4f (patch) | |
tree | 3987f5020c8ebf12c79d691d14521422e6d69720 /app | |
parent | 7010ee85b4bdfa0c8120f15597a9471151576b2c (diff) |
fix crash due to passphrase caching after biom. authentication expired (#3141)
* fix crash due to passphrase caching after biom. authentication expired
* fix: add missing imports
---------
Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt | 15 | ||||
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt | 23 |
2 files changed, 24 insertions, 14 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt b/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt index 9601d75e..943553a0 100644 --- a/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt @@ -44,6 +44,7 @@ import javax.inject.Inject import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import logcat.LogPriority.ERROR +import logcat.asLog import logcat.logcat @AndroidEntryPoint @@ -192,8 +193,6 @@ class AutofillDecryptActivity : BasePGPActivity() { Intent().apply { putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset) }, ) } - if (features.isEnabled(EnablePGPPassphraseCache)) - settings.edit { putBoolean(PreferenceKeys.CLEAR_PASSPHRASE_CACHE, clearCache) } } withContext(dispatcherProvider.main()) { finish() } } @@ -218,9 +217,15 @@ class AutofillDecryptActivity : BasePGPActivity() { } .onSuccess { result -> return runCatching { - if (features.isEnabled(EnablePGPPassphraseCache)) { - passphraseCache.cachePassphrase(this, identifiers.first(), password) - } + runCatching { + if (features.isEnabled(EnablePGPPassphraseCache)) { + passphraseCache.cachePassphrase(this, identifiers.first(), password) + settings.edit { + putBoolean(PreferenceKeys.CLEAR_PASSPHRASE_CACHE, clearCache) + } + } + } + .onFailure { e -> logcat { e.asLog() } } val entry = passwordEntryFactory.create(result.toByteArray()) AutofillPreferences.credentialsFromStoreEntry(this, file, entry, directoryStructure) } diff --git a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt index c25b5d1a..fcf03781 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt @@ -31,6 +31,8 @@ import app.passwordstore.util.features.Feature.EnablePGPPassphraseCache import app.passwordstore.util.features.Features import app.passwordstore.util.settings.Constants import app.passwordstore.util.settings.PreferenceKeys +import com.github.michaelbull.result.onFailure +import com.github.michaelbull.result.runCatching import dagger.hilt.android.AndroidEntryPoint import java.io.ByteArrayOutputStream import java.io.File @@ -41,6 +43,7 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import logcat.LogPriority.ERROR +import logcat.asLog import logcat.logcat @AndroidEntryPoint @@ -214,13 +217,17 @@ class DecryptActivity : BasePGPActivity() { clearCache = bundle.getBoolean(PasswordDialog.PASSWORD_CLEAR_KEY) lifecycleScope.launch(dispatcherProvider.main()) { decryptWithPassphrase(passphrase, gpgIdentifiers, authResult) { - if (authResult is BiometricResult.Success) { - passphraseCache.cachePassphrase( - this@DecryptActivity, - gpgIdentifiers.first(), - passphrase, - ) - } + runCatching { + if (authResult is BiometricResult.Success) { + passphraseCache.cachePassphrase( + this@DecryptActivity, + gpgIdentifiers.first(), + passphrase, + ) + settings.edit { putBoolean(PreferenceKeys.CLEAR_PASSPHRASE_CACHE, clearCache) } + } + } + .onFailure { e -> logcat { e.asLog() } } } } } @@ -237,8 +244,6 @@ class DecryptActivity : BasePGPActivity() { val outputStream = ByteArrayOutputStream() val result = repository.decrypt(passphrase, identifiers, message, outputStream) if (result.isOk) { - if (features.isEnabled(EnablePGPPassphraseCache)) - settings.edit { putBoolean(PreferenceKeys.CLEAR_PASSPHRASE_CACHE, clearCache) } val entry = passwordEntryFactory.create(result.value.toByteArray()) passwordEntry = entry createPasswordUI(entry) |