Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix crash due to passphrase caching after biom. authentication expired
Browse files Browse the repository at this point in the history
  • Loading branch information
agrahn committed Jul 28, 2024
1 parent 7010ee8 commit d1fb603
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,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() }
}
Expand All @@ -218,9 +216,17 @@ 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(ERROR) { e.asLog("Failed to write passphrase to the cache") }
}
val entry = passwordEntryFactory.create(result.toByteArray())
AutofillPreferences.credentialsFromStoreEntry(this, file, entry, directoryStructure)
}
Expand Down
25 changes: 16 additions & 9 deletions app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import app.passwordstore.ui.adapters.FieldItemAdapter
import app.passwordstore.ui.dialogs.BasicBottomSheet
import app.passwordstore.util.auth.BiometricAuthenticator
import app.passwordstore.util.auth.BiometricAuthenticator.Result as BiometricResult
import app.passwordstore.util.extensions.asLog
import app.passwordstore.util.extensions.getString
import app.passwordstore.util.extensions.unsafeLazy
import app.passwordstore.util.extensions.viewBinding
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
Expand Down Expand Up @@ -214,13 +217,19 @@ 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(ERROR) { e.asLog("Failed to write passphrase to the cache") }
}
}
}
}
Expand All @@ -237,8 +246,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)
Expand Down

0 comments on commit d1fb603

Please sign in to comment.