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

Commit 1c6bbc5

Browse files
committed
fix: use the same decryption flow in autofill
Fixes #3131
1 parent 8095ee4 commit 1c6bbc5

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.lifecycle.lifecycleScope
1717
import app.passwordstore.Application.Companion.screenWasOff
1818
import app.passwordstore.R
1919
import app.passwordstore.crypto.PGPIdentifier
20+
import app.passwordstore.crypto.errors.CryptoHandlerException
2021
import app.passwordstore.data.crypto.PGPPassphraseCache
2122
import app.passwordstore.data.passfile.PasswordEntry
2223
import app.passwordstore.data.repo.PasswordRepository
@@ -33,11 +34,14 @@ import app.passwordstore.util.features.Features
3334
import app.passwordstore.util.settings.PreferenceKeys
3435
import com.github.androidpasswordstore.autofillparser.AutofillAction
3536
import com.github.androidpasswordstore.autofillparser.Credentials
37+
import com.github.michaelbull.result.Result
3638
import com.github.michaelbull.result.getOrElse
39+
import com.github.michaelbull.result.map
3740
import com.github.michaelbull.result.onFailure
3841
import com.github.michaelbull.result.onSuccess
3942
import com.github.michaelbull.result.runCatching
4043
import dagger.hilt.android.AndroidEntryPoint
44+
import java.io.ByteArrayInputStream
4145
import java.io.ByteArrayOutputStream
4246
import java.io.File
4347
import javax.inject.Inject
@@ -209,20 +213,16 @@ class AutofillDecryptActivity : BasePGPActivity() {
209213
return null
210214
}
211215
.onSuccess { encryptedInput ->
212-
runCatching {
213-
withContext(dispatcherProvider.io()) {
214-
val outputStream = ByteArrayOutputStream()
215-
repository.decrypt(password, identifiers, encryptedInput, outputStream)
216-
outputStream
217-
}
218-
}
216+
decryptPGPStream(encryptedInput, password, identifiers)
219217
.onFailure { e ->
220218
logcat(ERROR) { e.asLog("Decryption failed") }
221219
return null
222220
}
223221
.onSuccess { result ->
224222
return runCatching {
225-
passphraseCache.cachePassphrase(this, identifiers.first(), password)
223+
if (features.isEnabled(EnablePGPPassphraseCache)) {
224+
passphraseCache.cachePassphrase(this, identifiers.first(), password)
225+
}
226226
val entry = passwordEntryFactory.create(result.toByteArray())
227227
AutofillPreferences.credentialsFromStoreEntry(this, file, entry, directoryStructure)
228228
}
@@ -235,6 +235,17 @@ class AutofillDecryptActivity : BasePGPActivity() {
235235
return null
236236
}
237237

238+
private suspend fun decryptPGPStream(
239+
message: ByteArrayInputStream,
240+
passphrase: String,
241+
gpgIdentifiers: List<PGPIdentifier>,
242+
): Result<ByteArrayOutputStream, CryptoHandlerException> {
243+
val outputStream = ByteArrayOutputStream()
244+
return repository.decrypt(passphrase, gpgIdentifiers, message, outputStream).map {
245+
outputStream
246+
}
247+
}
248+
238249
companion object {
239250

240251
private const val EXTRA_FILE_PATH = "app.passwordstore.autofill.oreo.EXTRA_FILE_PATH"

0 commit comments

Comments
 (0)