Repository navigation
fix(android): recover when the keychain file is restored without its Keystore key - #713
Merged
Merged
Conversation
…eystore key Uninstalling deletes the Android Keystore master key, which is never backed up, but Auto Backup restored shared_prefs/voltius_secrets.xml on reinstall. EncryptedSharedPreferences.create() then threw AEADBadTagException and every keychain read failed with "Java exception was thrown". - Disable Auto Backup and exclude voltius_secrets.xml from cloud backup and device transfer. - When the file can't be decrypted, rename it to voltius_secrets.xml.<unix_millis>.bak (newest 3 kept) and open a fresh store. The Keystore key is left in place. - JNI errors now name the Java exception and its causes.
Once the keychain is reset, secrets.enc can remain without the account_id its password key is derived from. The unlock form could only fail with "No account found"; the vault-unreadable panel lets the user set it aside and sign in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After uninstalling the GitHub/Obtainium APK and installing the Play Store build, entering the master password fails with:
Confirmed on a OnePlus (Android 15) over adb:
FB:08:A9:35…), so Google backup restored the app's data at install (restore_package: [com.voltius.app,19308]).shared_prefs/voltius_secrets.xmlcan't be decrypted with the new key:Fix
allowBackup="false", plusdata_extraction_rules.xmlexcludingvoltius_secrets.xmlfrom cloud backup and device transfer. On Android 12+,allowBackup="false"alone doesn't stop device-to-device transfer.VoltiusKeychain.prefs(): onGeneralSecurityException/IOException, rename the file tovoltius_secrets.xml.<unix_millis>.bak(same naming and keep-newest-3 rule assecrets_quarantine), then open a fresh store. Nothing is deleted and the Keystore alias stays, so a set-aside file can still be recovered if the failure was temporary.@Synchronizedso parallel reads can't set aside a store another thread just created.android_ctx::with_env: errors now name the Java exception and its causes instead of "Java exception was thrown".secrets.encwith noaccount_idin the keychain went to the password form, which could only fail with "No account found", because the password key is derived from that id. It now goes to the existing vault-unreadable panel ("Set aside and start fresh"). Logout deletessecrets.enc, so normal flows never reach this state.Why recover in Kotlin rather than return a typed error to the frontend: about 15 callers read the keychain, and the restored data can never be decrypted (its key never left the old install), so asking the user wouldn't change the outcome.
Testing
On the phone, debug build, with the exact broken state recreated (log in → save app data → uninstall → reinstall → restore the data):
VoltiusKeychain: Could not decrypt voltius_secrets, set it aside as voltius_secrets.xml.1792841115638.bak) and the app starts without a keychain error.shared_prefsmade read-only),keychain_getreturnsKeychain read error: Platform failure: keychain get: javax.crypto.AEADBadTagException, caused by: android.security.KeyStoreException: Signature/MAC verification failed (...).vitest(splash + account suites, 179 tests including 2 new) andtsc --noEmitpass.Users already on 0.63.0 still have backup enabled, so they need this release before an uninstall/reinstall is safe. Until then: Settings → Apps → Voltius → Storage → Clear storage.
🤖 Generated with Claude Code
https://claude.ai/code/session_016Q4DupsYZYovyJ677XMLXB