f2e81de54b37
fix: remove plaintext duressConfigured from Android settings and use authenticated payload state (PB-26-004, v2.17.4)
- time
- 2026-09-08 03:54 UTC · 2 months ago
- machine
- koh2
- agent
- claude-opus-5
- session
- duress settings
- parent
- 0c748759a92d
↓ peach-android-f2e81de5.tar.gzatlas at this save
files changed5 files
VERSION+1 −1app/src/main/java/com/peachpasswords/ui/settings/SettingsViewModel.kt+1 −4app/src/main/java/com/peachpasswords/vault/VaultRepository.kt+34 −17app/src/main/java/com/peachpasswords/vault/VaultSettings.kt+0 −1app/src/test/java/com/peachpasswords/vault/VaultSettingsDefaultsTest.kt+6 −0app/src/main/java/com/peachpasswords/ui/settings/SettingsViewModel.kt+1 −4
@@ -67,8 +67,7 @@6767 @ApplicationContext private val appContext: Context,6868 ) : ViewModel() {6969 70- private val _duressConfigured = MutableStateFlow(duress.isConfigured())71- val duressConfigured: StateFlow<Boolean> = _duressConfigured.asStateFlow()70+ val duressConfigured: StateFlow<Boolean> = vault.duressConfigured7271 7372 private val _pinEnabled = MutableStateFlow(pinUnlock.isConfigured())7473 val pinEnabled: StateFlow<Boolean> = _pinEnabled.asStateFlow()@@ -80,14 +79,12 @@8079 suspend fun saveDuress(password: String, action: com.peachpasswords.vault.DuressAction): Boolean {8180 if (!vault.setDuressPassphrase(password)) return false8281 val ok = duress.enable(action)83- if (ok) _duressConfigured.value = true8482 return ok8583 }8684 8785 fun disableDuress() {8886 viewModelScope.launch { vault.clearDuress() }8987 duress.clear()90- _duressConfigured.value = false9188 }9289 9390 private val _feedbackState = MutableStateFlow<FeedbackState>(FeedbackState.Idle)app/src/main/java/com/peachpasswords/vault/VaultRepository.kt+34 −17
@@ -180,7 +180,7 @@180180 private var derivedKey: ByteArray? = null181181 private var rootKey: ByteArray? = null182182 private var entryList: MutableList<VaultEntry> = mutableListOf()183- private var duressConfigured: Boolean = false183+ private var authenticatedDuressConfigured: Boolean = false184184 private var recoveryWordHash: String? = null185185 private var recoveryWordsSet: Boolean = false186186 /** True when an authenticated vault payload is available for local reads. */@@ -191,7 +191,11 @@191191 private val _isUnlocked = MutableStateFlow(false)192192 val isUnlocked: StateFlow<Boolean> = _isUnlocked.asStateFlow()193193 194+ private val _duressConfigured = MutableStateFlow(false)195+ /** Authenticated payload state; never loaded from plaintext settings. */196+ val duressConfigured: StateFlow<Boolean> = _duressConfigured.asStateFlow()194197 198+195199 /**196200 * UI-only gate for sync-retained background mode. The vault stays unlocked197201 * in memory (sync can proceed) but the UI shows the lock screen until the@@ -219,7 +223,8 @@219223 derivedKey = null220224 rootKey = null221225 entryList = mutableListOf()222- duressConfigured = false226+ authenticatedDuressConfigured = false227+ _duressConfigured.value = false223228 recoveryWordHash = null224229 recoveryWordsSet = false225230 sessionDataAvailable = false@@ -469,7 +474,8 @@469474 key = VaultCrypto.deriveKey(password, salt)470475 if (mutateIfCurrentEpoch(expectedEpoch) {471476 entryList = mutableListOf()472- duressConfigured = false477+ authenticatedDuressConfigured = false478+ _duressConfigured.value = false473479 recoveryWordHash = null474480 recoveryWordsSet = false475481 decoyMode = false@@ -489,7 +495,7 @@489495 try {490496 if (!writeMatchingNoiseSlotB(slotA)) throw java.io.IOException("noise_slot_b_commit_failed")491497 // H-04: duress slot must be present from the start so its492- // existence on disk is independent of duressConfigured.498+ // existence on disk is independent of authenticatedDuressConfigured.493499 if (!writeFakeDuressSlot(slotA)) throw java.io.IOException("duress_slot_commit_failed")494500 store.stampLocalMutation()495501 if (!store.writeSettings(_settings.value)) throw java.io.IOException("settings_commit_failed")@@ -564,7 +570,7 @@564570 try {565571 if (!writeMatchingNoiseSlotB(slotA)) throw java.io.IOException("noise_slot_b_commit_failed")566572 // H-04: duress slot must be present from the start so its567- // existence on disk is independent of duressConfigured.573+ // existence on disk is independent of authenticatedDuressConfigured.568574 if (!writeFakeDuressSlot(slotA)) throw java.io.IOException("duress_slot_commit_failed")569575 store.stampLocalMutation()570576 if (!store.writeSettings(_settings.value)) throw java.io.IOException("settings_commit_failed")@@ -584,7 +590,8 @@584590 nextDerivedKey = null585591 sessionRootKey = null586592 entryList = mutableListOf()587- duressConfigured = false593+ authenticatedDuressConfigured = false594+ _duressConfigured.value = false588595 recoveryWordHash = null589596 recoveryWordsSet = false590597 decoyMode = false@@ -759,7 +766,8 @@759766 derivedKey = key760767 decoyMode = false761768 entryList = payload.entries.toMutableList()762- duressConfigured = payload.duressConfigured769+ authenticatedDuressConfigured = payload.duressConfigured770+ _duressConfigured.value = payload.duressConfigured763771 recoveryWordHash = payload.recoveryWordHash764772 recoveryWordsSet = payload.recoveryWordsSet765773 sessionDataAvailable = true@@ -920,7 +928,8 @@920928 derivedKey = key921929 decoyMode = true922930 entryList = unlock.payload.entries.toMutableList()923- duressConfigured = false931+ authenticatedDuressConfigured = false932+ _duressConfigured.value = false924933 recoveryWordHash = unlock.payload.recoveryWordHash925934 recoveryWordsSet = unlock.payload.recoveryWordsSet926935 sessionDataAvailable = true@@ -1002,7 +1011,10 @@10021011 val ok = withEpochCommit(expectedEpoch) {10031012 store.writeDecoySlot(StoredVault(version = 1, salt = b64(salt), blob = blob))10041013 } ?: false1005- if (ok && mutateIfCurrentEpoch(expectedEpoch) { duressConfigured = true } != null) {1014+ if (ok && mutateIfCurrentEpoch(expectedEpoch) {1015+ authenticatedDuressConfigured = true1016+ _duressConfigured.value = true1017+ } != null) {10061018 runCatching { persistSlotA(bumpVersion = false, expectedEpoch = expectedEpoch) }10071019 } else if (ok) {10081020 return false@@ -1029,7 +1041,7 @@10291041 * or any conversion failure occurs. Never decrypts.10301042 */10311043 suspend fun exportDuressSlotForAdoption(): String? = mutex.withLock {1032- if (!duressConfigured) return null1044+ if (!authenticatedDuressConfigured) return null10331045 val slot = store.loadDecoySlot() ?: return null10341046 return runCatching { androidDuressSlotToBrowserJson(slot) }.getOrNull()10351047 }@@ -1136,10 +1148,13 @@11361148 } ?: false11371149 if (!replaced) return@withLock false11381150 // H-03: stateLock-fence the derivedKey/decoyMode read AND the1139- // duressConfigured write so a concurrent lock() cannot land between them.1151+ // authenticatedDuressConfigured write so a concurrent lock() cannot land between them.11401152 if (!isSessionEpochCurrent(expectedEpoch)) return false11411153 val shouldClear = mutateIfCurrentEpoch(expectedEpoch) { derivedKey != null && !decoyMode } == true1142- if (shouldClear && mutateIfCurrentEpoch(expectedEpoch) { duressConfigured = false } != null) {1154+ if (shouldClear && mutateIfCurrentEpoch(expectedEpoch) {1155+ authenticatedDuressConfigured = false1156+ _duressConfigured.value = false1157+ } != null) {11431158 runCatching { persistSlotA(bumpVersion = false, expectedEpoch = expectedEpoch) }11441159 }11451160 true@@ -2267,7 +2282,8 @@22672282 val adopted = mutateIfCurrentEpoch(expectedEpoch) {22682283 clearSessionStateLocked()22692284 entryList = payload.entries.toMutableList()2270- duressConfigured = payload.duressConfigured2285+ authenticatedDuressConfigured = payload.duressConfigured2286+ _duressConfigured.value = payload.duressConfigured22712287 recoveryWordHash = payload.recoveryWordHash22722288 recoveryWordsSet = payload.recoveryWordsSet22732289 rootKey = candidateRoot@@ -2313,7 +2329,8 @@23132329 val adopted = mutateIfCurrentEpoch(expectedEpoch) {23142330 clearSessionStateLocked()23152331 entryList = mutableListOf()2316- duressConfigured = false2332+ authenticatedDuressConfigured = false2333+ _duressConfigured.value = false23172334 recoveryWordHash = recoveryWordsHash(words)23182335 recoveryWordsSet = true23192336 rootKey = candidateRoot@@ -2737,7 +2754,7 @@27372754 private fun currentPayloadLocked(): VaultPayload =27382755 VaultPayload(27392756 entries = entryList.toList(),2740- duressConfigured = duressConfigured,2757+ duressConfigured = authenticatedDuressConfigured,27412758 rootKeyB64 = rootKey?.let(::b64) ?: "",27422759 recoveryWordHash = recoveryWordHash,27432760 recoveryWordsSet = recoveryWordsSet,@@ -2792,7 +2809,7 @@27922809 /** H-04: a decoy-shaped StoredVault with a random blob of [matchingCiphertextLength]27932810 * bytes. Replaces a real decoy when the user clears duress, and is the27942811 * initial duress slot when no decoy is configured — so the record's2795- * PRESENCE on disk is independent of duressConfigured, and its SIZE2812+ * PRESENCE on disk is independent of authenticatedDuressConfigured, and its SIZE27962813 * matches slot A's blob length. */27972814 private fun writeFakeDuressSlot(slotA: StoredVault): Boolean {27982815 val blobSize = VaultCrypto.NONCE_SIZE + matchingCiphertextLength(slotA) + 16@@ -2808,7 +2825,7 @@28082825 * pair the same length after slot A crosses a padding bucket28092826 * (PAI-2026-004). No real decoy → a fresh fake of slot A's size. */28102827 private fun writeCompanionDuressSlot(slotA: StoredVault): Boolean {2811- val isConfigured = mutateState { duressConfigured }2828+ val isConfigured = mutateState { authenticatedDuressConfigured }28122829 return if (isConfigured) true else writeFakeDuressSlot(slotA)28132830 }28142831 app/src/main/java/com/peachpasswords/vault/VaultSettings.kt+0 −1
@@ -26,7 +26,6 @@2626 // setting is preserved on load, so anyone who explicitly disabled it stays2727 // off until they re-enable it in Settings → Passkeys.2828 val passkeyProviderEnabled: Boolean = true,29- val duressConfigured: Boolean = false,3029 val shortcuts: Map<String, ShortcutBinding> = emptyMap(),3130 val allowScreenshots: Boolean = false,3231 )app/src/test/java/com/peachpasswords/vault/VaultSettingsDefaultsTest.kt+6 −0
@@ -21,6 +21,12 @@2121 )2222 }2323 24+ @Test fun plaintext_settings_do_not_contain_duress_configuration() {25+ val encoded = VaultCodec.encodeSettings(VaultSettings())26+27+ assertFalse(encoded.contains("duressConfigured"))28+ }29+2430 @Test fun explicitly_disabled_setting_round_trips_through_codec() {2531 val original = VaultSettings(passkeyProviderEnabled = false)2632 val encoded = VaultCodec.encodeSettings(original)