Use Android Keystore for device auth storage - #856
Conversation
1. Encrypt device auth values with a direct Android Keystore AEAD, migrating legacy Tink and DataStore values on read 2. Recover from keystore failures: drop corrupt values, retry transient faults once, reset only this namespace's keystore values 3. Regenerate device keys only when no stored value exists and return synthetic 599 when request signing fails 4. Add missing getPriceAlertAssetIds override in price alerts test fake
bdaba61 to
1a2a9c5
Compare
|
Verified the migration and self-heal end-to-end on an emulator upgrading from 2.114.6 (old-format values), which surfaced a bug — fixed in 64e643a: Bug: after Verification (Pixel 10 Pro AVD, API 37):
Note: |
Summary
Root cause
The exact originating Keystore condition is unknown. The crash happens when
AndroidKeysetManagercannot authenticate its SharedPreferences-wrapped Tink keyset with the Android Keystore master key, which raisesBadPaddingExceptionorAEADBadTagException.GetDeviceIdImplcatches the failed read and generates a new device key pair, but the old implementation then writes through the same unreadable Tink keyset and crashes again. New device-auth writes now use Android Keystore AEAD directly, so regeneration no longer depends on that legacy keyset. Existing readable values migrate on first read.Impact
Fixes the two observed device-auth crash paths. Invalid direct-Keystore data is cleared so the device identity can be regenerated; unrelated Android Keystore failures may still surface.
Validation
./gradlew :app:assembleGoogleDebug./gradlew :app:lintGoogleDebugTinkEncryptedKeyValueStoreInstrumentedTesttests on API 35git diff --check