aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-03-12 13:04:32 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-03-12 13:04:32 +0530
commit5082df2f934cf4728cf43ae5dd5a1749de0ba534 (patch)
tree6e57d76dfd7169e3184f5d130c59e03e0d071c78
parent0d7d6eae79dc00500e0988d23094ddaa0d407e07 (diff)
fix: clear passphrase cache when disabling
-rw-r--r--app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt23
-rw-r--r--app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt8
-rw-r--r--app/src/main/res/values/strings.xml1
3 files changed, 30 insertions, 2 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt b/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
index e2b7e5a8..bb045799 100644
--- a/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
+++ b/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
@@ -6,18 +6,25 @@
package app.passwordstore.ui.settings
import androidx.fragment.app.FragmentActivity
+import androidx.lifecycle.lifecycleScope
import app.passwordstore.R
+import app.passwordstore.data.crypto.PGPPassphraseCache
import app.passwordstore.ui.pgp.PGPKeyListActivity
import app.passwordstore.util.auth.BiometricAuthenticator
import app.passwordstore.util.extensions.launchActivity
import app.passwordstore.util.features.Feature
import app.passwordstore.util.settings.PreferenceKeys
import de.Maxr1998.modernpreferences.PreferenceScreen
+import de.Maxr1998.modernpreferences.helpers.onCheckedChange
import de.Maxr1998.modernpreferences.helpers.onClick
import de.Maxr1998.modernpreferences.helpers.pref
import de.Maxr1998.modernpreferences.helpers.switch
+import kotlinx.coroutines.launch
-class PGPSettings(private val activity: FragmentActivity) : SettingsProvider {
+class PGPSettings(
+ private val activity: FragmentActivity,
+ private val passphraseCache: PGPPassphraseCache,
+) : SettingsProvider {
override fun provideSettings(builder: PreferenceScreen.Builder) {
builder.apply {
@@ -38,6 +45,20 @@ class PGPSettings(private val activity: FragmentActivity) : SettingsProvider {
titleRes = R.string.pref_passphrase_cache_title
summaryRes = R.string.pref_passphrase_cache_summary
defaultValue = false
+ onCheckedChange { checked ->
+ if (!checked && BiometricAuthenticator.canAuthenticate(activity)) {
+ BiometricAuthenticator.authenticate(
+ activity,
+ R.string.pref_passphrase_cache_authenticate_clear,
+ ) {
+ if (it is BiometricAuthenticator.Result.Success)
+ activity.lifecycleScope.launch {
+ passphraseCache.clearAllCachedPassphrases(activity)
+ }
+ }
+ }
+ true
+ }
}
}
}
diff --git a/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt b/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt
index a2b078e0..aea6acee 100644
--- a/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt
@@ -11,22 +11,27 @@ import androidx.activity.addCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.BundleCompat
import app.passwordstore.R
+import app.passwordstore.data.crypto.PGPPassphraseCache
import app.passwordstore.databinding.ActivityPreferenceRecyclerviewBinding
import app.passwordstore.util.extensions.viewBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import dagger.hilt.android.AndroidEntryPoint
import de.Maxr1998.modernpreferences.Preference
import de.Maxr1998.modernpreferences.PreferencesAdapter
import de.Maxr1998.modernpreferences.helpers.screen
import de.Maxr1998.modernpreferences.helpers.subScreen
+import javax.inject.Inject
+@AndroidEntryPoint
class SettingsActivity : AppCompatActivity() {
+ @Inject lateinit var passphraseCache: PGPPassphraseCache
private val miscSettings = MiscSettings(this)
private val autofillSettings = AutofillSettings(this)
private val passwordSettings = PasswordSettings(this)
private val repositorySettings = RepositorySettings(this)
private val generalSettings = GeneralSettings(this)
- private val pgpSettings = PGPSettings(this)
+ private lateinit var pgpSettings: PGPSettings
private val binding by viewBinding(ActivityPreferenceRecyclerviewBinding::inflate)
private val preferencesAdapter: PreferencesAdapter
@@ -36,6 +41,7 @@ class SettingsActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(binding.root)
Preference.Config.dialogBuilderFactory = { context -> MaterialAlertDialogBuilder(context) }
+ pgpSettings = PGPSettings(this, passphraseCache)
val screen =
screen(this) {
subScreen {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index acb07b5e..23e2e6e5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -137,6 +137,7 @@
<string name="pref_pgp_ascii_armor_title">Encrypt in ASCII armor mode</string>
<string name="pref_passphrase_cache_title">Enable passphrase caching</string>
<string name="pref_passphrase_cache_summary">WARNING: this feature is functional but very experimental. Requires an active screen lock.</string>
+ <string name="pref_passphrase_cache_authenticate_clear">Authenticate to clear cache</string>
<!-- PasswordGenerator fragment -->
<string name="pwgen_title">Generate Password</string>