summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2023-12-25 15:36:01 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2023-12-25 15:36:01 +0530
commitd8f76b33e9ea74eb567a115dd63559f6b27b2fce (patch)
tree7a54e2d061100edf374204125add9cf3345e296e /app/src/main/java
parent4c09adbe36889b6f4ec784861cbd59c569ed43c7 (diff)
fix: check if passphrase is necessary before asking for it
Updates #2836
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt4
-rw-r--r--app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt10
2 files changed, 13 insertions, 1 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 0ce4b3e3..be3f8da3 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,10 @@ constructor(
out: ByteArrayOutputStream,
) = withContext(dispatcherProvider.io()) { decryptPgp(password, identities, message, out) }
+ fun isPasswordProtected(message: ByteArrayInputStream): Boolean {
+ return pgpCryptoHandler.isPassphraseProtected(message)
+ }
+
suspend fun encrypt(
identities: List<PGPIdentifier>,
content: ByteArrayInputStream,
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 9fb20af2..56ac1fc0 100644
--- a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt
@@ -177,7 +177,7 @@ class DecryptActivity : BasePGPActivity() {
}
}
- private fun askPassphrase(
+ private suspend fun askPassphrase(
isError: Boolean,
gpgIdentifiers: List<PGPIdentifier>,
authResult: Result,
@@ -187,6 +187,14 @@ class DecryptActivity : BasePGPActivity() {
} else {
finish()
}
+ if (
+ !repository.isPasswordProtected(
+ withContext(dispatcherProvider.io()) { File(fullPath).readBytes().inputStream() }
+ )
+ ) {
+ decryptWithPassphrase(password = "", gpgIdentifiers = gpgIdentifiers)
+ return
+ }
val dialog = PasswordDialog()
if (isError) {
dialog.setError()