summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-04-14 22:50:59 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-04-14 23:19:31 +0530
commit87738477be87afb639509f5ebdf5da979ba0bd04 (patch)
treed2575904de2bd37e23463d8f9831161b38be790b /app/src/main/java
parent312f92d21a5b8925496d5015357c257dace3a028 (diff)
fix: special-case AEAD failure
Fixes #2974 Fixes #2963 Fixes #2921 Fixes #2924 Fixes #2653 Fixes #2461 Fixes #2586 Fixes #2179
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt40
-rw-r--r--app/src/main/java/app/passwordstore/ui/dialogs/BasicBottomSheet.kt20
2 files changed, 45 insertions, 15 deletions
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 895ac50d..d36c1a9f 100644
--- a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt
@@ -13,11 +13,14 @@ import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.lifecycleScope
import app.passwordstore.R
import app.passwordstore.crypto.PGPIdentifier
+import app.passwordstore.crypto.errors.CryptoHandlerException
+import app.passwordstore.crypto.errors.NonStandardAEAD
import app.passwordstore.data.crypto.PGPPassphraseCache
import app.passwordstore.data.passfile.PasswordEntry
import app.passwordstore.data.password.FieldItem
import app.passwordstore.databinding.DecryptLayoutBinding
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.getString
@@ -27,7 +30,8 @@ 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.runCatching
+import com.github.michaelbull.result.Result
+import com.github.michaelbull.result.map
import dagger.hilt.android.AndroidEntryPoint
import java.io.ByteArrayOutputStream
import java.io.File
@@ -198,7 +202,7 @@ class DecryptActivity : BasePGPActivity() {
passphraseCache.cachePassphrase(
this@DecryptActivity,
gpgIdentifiers.first(),
- passphrase
+ passphrase,
)
}
}
@@ -221,24 +225,36 @@ class DecryptActivity : BasePGPActivity() {
onSuccess()
} else {
logcat(ERROR) { result.error.stackTraceToString() }
- decrypt(isError = true, authResult = authResult)
+ when (result.error) {
+ is NonStandardAEAD -> {
+ BasicBottomSheet.Builder(this)
+ .setTitle(getString(R.string.aead_detect_title))
+ .setMessage(getString(R.string.aead_detect_message, result.error.message))
+ .setPositiveButtonClickListener(getString(R.string.dialog_ok)) {
+ setResult(RESULT_CANCELED)
+ finish()
+ }
+ .setOnDismissListener {
+ setResult(RESULT_CANCELED)
+ finish()
+ }
+ .build()
+ .show(supportFragmentManager, "AEAD_INFO_SHEET")
+ }
+ else -> decrypt(isError = true, authResult = authResult)
+ }
}
}
private suspend fun decryptPGPStream(
passphrase: String,
gpgIdentifiers: List<PGPIdentifier>,
- ) = runCatching {
+ ): Result<ByteArrayOutputStream, CryptoHandlerException> {
val message = withContext(dispatcherProvider.io()) { File(fullPath).readBytes().inputStream() }
val outputStream = ByteArrayOutputStream()
- val result =
- repository.decrypt(
- passphrase,
- gpgIdentifiers,
- message,
- outputStream,
- )
- if (result.isOk) outputStream else throw result.error
+ return repository.decrypt(passphrase, gpgIdentifiers, message, outputStream).map {
+ outputStream
+ }
}
private suspend fun createPasswordUI(entry: PasswordEntry) =
diff --git a/app/src/main/java/app/passwordstore/ui/dialogs/BasicBottomSheet.kt b/app/src/main/java/app/passwordstore/ui/dialogs/BasicBottomSheet.kt
index c35985cb..11c23311 100644
--- a/app/src/main/java/app/passwordstore/ui/dialogs/BasicBottomSheet.kt
+++ b/app/src/main/java/app/passwordstore/ui/dialogs/BasicBottomSheet.kt
@@ -6,6 +6,7 @@
package app.passwordstore.ui.dialogs
import android.content.Context
+import android.content.DialogInterface.OnDismissListener
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -33,6 +34,7 @@ private constructor(
val negativeButtonLabel: String?,
val positiveButtonClickListener: View.OnClickListener?,
val negativeButtonClickListener: View.OnClickListener?,
+ val onDismissListener: OnDismissListener?,
) : BottomSheetDialogFragment() {
private val binding by viewBinding(BasicBottomSheetBinding::bind)
@@ -94,6 +96,9 @@ private constructor(
dismiss()
}
}
+ if (onDismissListener != null) {
+ dialog.setOnDismissListener(onDismissListener)
+ }
}
}
)
@@ -112,6 +117,7 @@ private constructor(
private var negativeButtonLabel: String? = null
private var positiveButtonClickListener: View.OnClickListener? = null
private var negativeButtonClickListener: View.OnClickListener? = null
+ private var onDismissListener: OnDismissListener? = null
fun setTitleRes(@StringRes titleRes: Int): Builder {
this.title = context.resources.getString(titleRes)
@@ -135,7 +141,7 @@ private constructor(
fun setPositiveButtonClickListener(
buttonLabel: String? = null,
- listener: View.OnClickListener
+ listener: View.OnClickListener,
): Builder {
this.positiveButtonClickListener = listener
this.positiveButtonLabel = buttonLabel
@@ -144,13 +150,20 @@ private constructor(
fun setNegativeButtonClickListener(
buttonLabel: String? = null,
- listener: View.OnClickListener
+ listener: View.OnClickListener,
): Builder {
this.negativeButtonClickListener = listener
this.negativeButtonLabel = buttonLabel
return this
}
+ fun setOnDismissListener(
+ onDismissListener: OnDismissListener,
+ ): Builder {
+ this.onDismissListener = onDismissListener
+ return this
+ }
+
fun build(): BasicBottomSheet {
require(message != null) { "Message needs to be set" }
return BasicBottomSheet(
@@ -159,7 +172,8 @@ private constructor(
positiveButtonLabel,
negativeButtonLabel,
positiveButtonClickListener,
- negativeButtonClickListener
+ negativeButtonClickListener,
+ onDismissListener,
)
}
}