aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-07-24 00:28:42 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-07-24 00:28:42 +0530
commit1c6bbc51c3851218e494656b356b92216a575804 (patch)
treeac28688ec15d5ea656f07a4e0895b6a3b9b37d13
parent8095ee4d6e8d5bbf48a8fde426a9f5e7dd0154da (diff)
fix: use the same decryption flow in autofill
Fixes #3131
-rw-r--r--app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt27
1 files changed, 19 insertions, 8 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 5174fff9..4855d588 100644
--- a/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt
@@ -17,6 +17,7 @@ import androidx.lifecycle.lifecycleScope
import app.passwordstore.Application.Companion.screenWasOff
import app.passwordstore.R
import app.passwordstore.crypto.PGPIdentifier
+import app.passwordstore.crypto.errors.CryptoHandlerException
import app.passwordstore.data.crypto.PGPPassphraseCache
import app.passwordstore.data.passfile.PasswordEntry
import app.passwordstore.data.repo.PasswordRepository
@@ -33,11 +34,14 @@ import app.passwordstore.util.features.Features
import app.passwordstore.util.settings.PreferenceKeys
import com.github.androidpasswordstore.autofillparser.AutofillAction
import com.github.androidpasswordstore.autofillparser.Credentials
+import com.github.michaelbull.result.Result
import com.github.michaelbull.result.getOrElse
+import com.github.michaelbull.result.map
import com.github.michaelbull.result.onFailure
import com.github.michaelbull.result.onSuccess
import com.github.michaelbull.result.runCatching
import dagger.hilt.android.AndroidEntryPoint
+import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import javax.inject.Inject
@@ -209,20 +213,16 @@ class AutofillDecryptActivity : BasePGPActivity() {
return null
}
.onSuccess { encryptedInput ->
- runCatching {
- withContext(dispatcherProvider.io()) {
- val outputStream = ByteArrayOutputStream()
- repository.decrypt(password, identifiers, encryptedInput, outputStream)
- outputStream
- }
- }
+ decryptPGPStream(encryptedInput, password, identifiers)
.onFailure { e ->
logcat(ERROR) { e.asLog("Decryption failed") }
return null
}
.onSuccess { result ->
return runCatching {
- passphraseCache.cachePassphrase(this, identifiers.first(), password)
+ if (features.isEnabled(EnablePGPPassphraseCache)) {
+ passphraseCache.cachePassphrase(this, identifiers.first(), password)
+ }
val entry = passwordEntryFactory.create(result.toByteArray())
AutofillPreferences.credentialsFromStoreEntry(this, file, entry, directoryStructure)
}
@@ -235,6 +235,17 @@ class AutofillDecryptActivity : BasePGPActivity() {
return null
}
+ private suspend fun decryptPGPStream(
+ message: ByteArrayInputStream,
+ passphrase: String,
+ gpgIdentifiers: List<PGPIdentifier>,
+ ): Result<ByteArrayOutputStream, CryptoHandlerException> {
+ val outputStream = ByteArrayOutputStream()
+ return repository.decrypt(passphrase, gpgIdentifiers, message, outputStream).map {
+ outputStream
+ }
+ }
+
companion object {
private const val EXTRA_FILE_PATH = "app.passwordstore.autofill.oreo.EXTRA_FILE_PATH"