Crash when trying to load key from keystore
I got the following crash while signing into an existing account on the API 26 emulator:
java.lang.RuntimeException: java.security.UnrecoverableKeyException: Failed to obtain information about key
at org.briarproject.briar.android.AndroidKeyStrengthener.isInitialised(AndroidKeyStrengthener.java:83)
at org.briarproject.bramble.crypto.CryptoComponentImpl.decryptWithPassword(CryptoComponentImpl.java:397)
at org.briarproject.bramble.account.AccountManagerImpl.loadAndDecryptDatabaseKey(AccountManagerImpl.java:215)
at org.briarproject.bramble.account.AccountManagerImpl.signIn(AccountManagerImpl.java:198)
at org.briarproject.briar.android.login.StartupViewModel.lambda$validatePassword$0$StartupViewModel(StartupViewModel.java:108)
at org.briarproject.briar.android.login.-$$Lambda$StartupViewModel$g7VDyWGXbuZadVRd8U1dRkICyWk.run(Unknown Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.security.UnrecoverableKeyException: Failed to obtain information about key
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreSecretKeyFromKeystore(AndroidKeyStoreProvider.java:282)
at android.security.keystore.AndroidKeyStoreSpi.engineGetKey(AndroidKeyStoreSpi.java:98)
at java.security.KeyStoreSpi.engineGetEntry(KeyStoreSpi.java:474)
at java.security.KeyStore.getEntry(KeyStore.java:1560)
at org.briarproject.briar.android.AndroidKeyStrengthener.isInitialised(AndroidKeyStrengthener.java:75)
at org.briarproject.bramble.crypto.CryptoComponentImpl.decryptWithPassword(CryptoComponentImpl.java:397)
at org.briarproject.bramble.account.AccountManagerImpl.loadAndDecryptDatabaseKey(AccountManagerImpl.java:215)
at org.briarproject.bramble.account.AccountManagerImpl.signIn(AccountManagerImpl.java:198)
at org.briarproject.briar.android.login.StartupViewModel.lambda$validatePassword$0$StartupViewModel(StartupViewModel.java:108)
at org.briarproject.briar.android.login.-$$Lambda$StartupViewModel$g7VDyWGXbuZadVRd8U1dRkICyWk.run(Unknown Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: android.security.KeyStoreException: Invalid key blob
at android.security.KeyStore.getKeyStoreException(KeyStore.java:695)
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreSecretKeyFromKeystore(AndroidKeyStoreProvider.java:283)
at android.security.keystore.AndroidKeyStoreSpi.engineGetKey(AndroidKeyStoreSpi.java:98)
at java.security.KeyStoreSpi.engineGetEntry(KeyStoreSpi.java:474)
at java.security.KeyStore.getEntry(KeyStore.java:1560)
at org.briarproject.briar.android.AndroidKeyStrengthener.isInitialised(AndroidKeyStrengthener.java:75)
at org.briarproject.bramble.crypto.CryptoComponentImpl.decryptWithPassword(CryptoComponentImpl.java:397)
at org.briarproject.bramble.account.AccountManagerImpl.loadAndDecryptDatabaseKey(AccountManagerImpl.java:215)
at org.briarproject.bramble.account.AccountManagerImpl.signIn(AccountManagerImpl.java:198)
at org.briarproject.briar.android.login.StartupViewModel.lambda$validatePassword$0$StartupViewModel(StartupViewModel.java:108)
at org.briarproject.briar.android.login.-$$Lambda$StartupViewModel$g7VDyWGXbuZadVRd8U1dRkICyWk.run(Unknown Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Looks like we can get a GeneralSecurityException instead of a clean failure when trying to load the key. We should handle this like a clean failure instead of crashing.
Edited by akwizgran