summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-05-27 20:59:20 +0530
committerGitHub <noreply@github.com>2024-05-27 15:29:20 +0000
commit0f9540a645ef66f3cf67294f75ba2c5d9d80078e (patch)
tree1f6e94f6565de5ee147b1fdcd694343cc6004d20 /app/src/main
parent1877c6ab5a987e08797b13e4dc619294d03d4c02 (diff)
feat(pgpainless): add detection for passphrase-less messages (#3069)
* WIP: feat(pgpainless): add detection for passphrase-less messages * refactor: test keys instead of the message This makes more logical sense
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt5
-rw-r--r--app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt6
-rw-r--r--app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt6
3 files changed, 15 insertions, 2 deletions
diff --git a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt
index 50d7a841..773a355a 100644
--- a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt
+++ b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt
@@ -45,6 +45,11 @@ constructor(
out: ByteArrayOutputStream,
) = withContext(dispatcherProvider.io()) { decryptPgp(password, identities, message, out) }
+ suspend fun isPasswordProtected(identifiers: List<PGPIdentifier>): Boolean {
+ val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
+ return pgpCryptoHandler.isPassphraseProtected(keys)
+ }
+
suspend fun encrypt(
identities: List<PGPIdentifier>,
content: ByteArrayInputStream,
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 1af46a89..4518e62f 100644
--- a/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/autofill/AutofillDecryptActivity.kt
@@ -131,12 +131,16 @@ class AutofillDecryptActivity : BasePGPActivity() {
}
}
- private fun askPassphrase(
+ private suspend fun askPassphrase(
filePath: String,
identifiers: List<PGPIdentifier>,
clientState: Bundle,
action: AutofillAction,
) {
+ if (!repository.isPasswordProtected(identifiers)) {
+ decryptWithPassphrase(File(filePath), identifiers, clientState, action, password = "")
+ return
+ }
val dialog = PasswordDialog()
dialog.show(supportFragmentManager, "PASSWORD_DIALOG")
dialog.setFragmentResultListener(PasswordDialog.PASSWORD_RESULT_KEY) { key, bundle ->
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 b222f2ea..6f14bdea 100644
--- a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt
@@ -179,7 +179,7 @@ class DecryptActivity : BasePGPActivity() {
}
}
- private fun askPassphrase(
+ private suspend fun askPassphrase(
isError: Boolean,
gpgIdentifiers: List<PGPIdentifier>,
authResult: BiometricResult,
@@ -189,6 +189,10 @@ class DecryptActivity : BasePGPActivity() {
} else {
finish()
}
+ if (!repository.isPasswordProtected(gpgIdentifiers)) {
+ decryptWithPassphrase(passphrase = "", gpgIdentifiers, authResult)
+ return
+ }
val dialog = PasswordDialog()
if (isError) {
dialog.setError()