715c2bf666ce

fix: clean PIN Keystore state when vault storage is cleared (v2.14.67)

time
2026-08-30 11:49 UTC · 1 month ago
machine
koh2
parent
76e044ae90a1
3 files VERSION+1 −1app/src/main/java/com/peachpasswords/vault/PinUnlockStore.kt+7 −5app/src/main/java/com/peachpasswords/vault/VaultStore.kt+4 −0
VERSION+1 −1
@@ -1 +1 @@1-2.14.661+2.14.67

view file

app/src/main/java/com/peachpasswords/vault/PinUnlockStore.kt+7 −5
@@ -94,7 +94,7 @@9494 9595             val cipher = Cipher.getInstance(TRANSFORM).apply { init(Cipher.ENCRYPT_MODE, vaultKeystoreKey) }9696             wrapped = cipher.doFinal(vaultKey)97-            createAttemptGates(createdAliases)97+            val attemptAliases = createAttemptGates(createdAliases)9898 9999             val saved = prefs.edit()100100                 .putInt(KEY_FORMAT, FORMAT_VERSION)@@ -102,11 +102,13 @@102102                 .putString(KEY_VERIFIER, b64(verifier!!))103103                 .putString(KEY_WRAPPED_KEY, b64(wrapped!!))104104                 .putString(KEY_WRAPPED_IV, b64(cipher.iv))105+                .putString(KEY_ATTEMPT_ALIASES, attemptAliases.joinToString(DELIMITER))105106                 .putBoolean(KEY_PREFERRED, false)106107                 .commit()107108             if (!saved) throw java.io.IOException("pin_storage_commit_failed")108109             true109110         } catch (_: Exception) {111+            createdAliases.forEach(::deleteKey)110112             clear()111113             false112114         } finally {@@ -161,8 +163,8 @@161163         val oldAliases = loadAttemptAliases()162164         val newAliases = mutableListOf<String>()163165         try {164-            createAttemptGates(newAliases)165-            if (!prefs.edit().putString(KEY_ATTEMPT_ALIASES, newAliases.joinToString(DELIMITER)).commit()) {166+            val attemptAliases = createAttemptGates(newAliases)167+            if (!prefs.edit().putString(KEY_ATTEMPT_ALIASES, attemptAliases.joinToString(DELIMITER)).commit()) {166168                 throw java.io.IOException("pin_attempt_gate_commit_failed")167169             }168170             oldAliases.forEach(::deleteKey)@@ -209,14 +211,14 @@209211         return false210212     }211213 212-    private fun createAttemptGates(createdAliases: MutableList<String>) {214+    private fun createAttemptGates(createdAliases: MutableList<String>): List<String> {213215         repeat(ATTEMPT_GATE_COUNT) {214216             val alias = "$ATTEMPT_ALIAS_PREFIX${UUID.randomUUID()}"215217             generateHmacKey(alias, limitedUse = true, createdAliases)216218         }217219         val aliases = createdAliases.filter { it.startsWith(ATTEMPT_ALIAS_PREFIX) }218220         if (aliases.size != ATTEMPT_GATE_COUNT) throw java.io.IOException("pin_attempt_gate_count")219-        prefs.edit().putString(KEY_ATTEMPT_ALIASES, aliases.joinToString(DELIMITER)).commit()221+        return aliases220222     }221223 222224     @Suppress("NewApi")

view file

app/src/main/java/com/peachpasswords/vault/VaultStore.kt+4 −0
@@ -215,6 +215,10 @@215215             .remove(KEY_VERSION).remove(KEY_SETTINGS).remove(KEY_HISTORY)216216             .remove("peach_pin_salt").remove("peach_pin_verifier").remove("peach_pin_wrapped_key")217217             .remove("peach_pin_preferred")218+            .remove("peach_pin_format").remove("peach_pin_salt_v2")219+            .remove("peach_pin_verifier_v2").remove("peach_pin_wrapped_key_v2")220+            .remove("peach_pin_wrapped_iv_v2").remove("peach_pin_attempt_aliases_v2")221+            .remove("peach_pin_preferred_v2")218222             .commit()219223     }220224 

view file