@@ -75,11 +75,31 @@ class PGPSettings(
7575 titleRes = R .string.pref_passphrase_cache_auto_clear_title
7676 summaryRes = R .string.pref_passphrase_cache_auto_clear_summary
7777 defaultValue = true
78- /* clear cache once when unchecking; this is to prevent a malicious user
79- * from bypassing cache clearing via the settings */
78+ /* Clear the cache once when unchecking; this is to prevent a malicious user (someone
79+ * knowing the screen-lock pin, but not knowing the PGP passphrase) from bypassing cache
80+ * clearing via the settings. However, clearing EncryptedSharedPreferences requires
81+ * authentication, otherwise the app crashes. Thus, the bad user could still bypass cache
82+ * clearing by dismissing the auhentication dialog. To prevent this, we enforce cache
83+ * clearing to stay enabled in case of any authentication failure. */
8084 onCheckedChange { checked ->
81- if (! checked)
82- activity.lifecycleScope.launch { passphraseCache.clearAllCachedPassphrases(activity) }
85+ if (! checked) {
86+ if (BiometricAuthenticator .canAuthenticate(activity)) {
87+ BiometricAuthenticator .authenticate(
88+ activity,
89+ R .string.pref_passphrase_cache_auto_clear_authenticate_disable,
90+ ) {
91+ if (it is BiometricAuthenticator .Result .Success ) {
92+ activity.lifecycleScope.launch {
93+ passphraseCache.clearAllCachedPassphrases(activity)
94+ }
95+ } else {
96+ activity.sharedPrefs.edit { remove(PreferenceKeys .CLEAR_PASSPHRASE_CACHE ) }
97+ }
98+ }
99+ } else {
100+ activity.sharedPrefs.edit { remove(PreferenceKeys .CLEAR_PASSPHRASE_CACHE ) }
101+ }
102+ }
83103 true
84104 }
85105 }
0 commit comments