Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 2767889

Browse files
authored
Fix application crash when disabling cache auto-clear option and potential attack vector (#3136)
prevent app crash upon passphrase cache clearing
1 parent 720dac4 commit 2767889

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
<string name="pref_passphrase_cache_title">Enable passphrase caching</string>
139139
<string name="pref_passphrase_cache_summary">WARNING: this feature is functional but very experimental. Requires an active screen lock.</string>
140140
<string name="pref_passphrase_cache_authenticate_enable">Authenticate to enable cache</string>
141+
<string name="pref_passphrase_cache_auto_clear_authenticate_disable">Authenticate to disable cache clearing</string>
141142
<string name="pref_passphrase_cache_auto_clear_title">Automatically clear passphrase cache</string>
142143
<string name="pref_passphrase_cache_auto_clear_summary">Clears the passphrase cache when the screen is turned off</string>
143144

0 commit comments

Comments
 (0)