ukhsa-collaboration / covid-19-app-android-ag-public

COVID19 Android app
Other
142 stars 31 forks source link

Application crashes on launch #22

Closed Daniel-sims closed 3 years ago

Daniel-sims commented 4 years ago

Describe the bug The application is crashing on launch.

To Reproduce Steps to reproduce the behavior:

  1. Try and open the app.

Expected behavior App to open correctly.

Screenshots None

Desktop (please complete the following information): Android

Smartphone (please complete the following information):

Additional context When launching the app it's crashing with a KeyStoreException (Downloaded from the store).

2020-09-29 12:24:36.788 19044-19044/? E/AndroidRuntime: FATAL EXCEPTION: main Process: uk.nhs.covid19.production, PID: 19044 java.lang.RuntimeException: Unable to create application uk.nhs.nhsx.covid19.android.app.ExposureApplication: java.security.KeyStoreException: the master key android-keystore://_master_key_strongbox_ exists but is unusable at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6717) at android.app.ActivityThread.access$1300(ActivityThread.java:237) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.security.KeyStoreException: the master key android-keystore://_master_key_strongbox_ exists but is unusable at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:268) at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:228) at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:121) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createEncryptedSharedPreferences$app_productionRelease(EncryptionUtils.kt:186) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createStrongBoxBackedEncryptedSharedPreferences(EncryptionUtils.kt:145) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createEncryptedSharedPreferences(EncryptionUtils.kt:136) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.tryCreateEncryptedSharedPreferences(EncryptionUtils.kt:130) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.tryCreateEncryptedSharedPreferences$default(EncryptionUtils.kt:118) at uk.nhs.nhsx.covid19.android.app.ExposureApplication.buildAndUseAppComponent(ExposureApplication.kt:109) at uk.nhs.nhsx.covid19.android.app.ExposureApplication.buildAndUseAppComponent$default(ExposureApplication.kt:107) at uk.nhs.nhsx.covid19.android.app.ExposureApplication.onCreate(ExposureApplication.kt:48) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712) at android.app.ActivityThread.access$1300(ActivityThread.java:237)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:223)  at android.app.ActivityThread.main(ActivityThread.java:7656)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)  Caused by: java.security.InvalidKeyException: Keystore operation failed at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1378) at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1388) at android.security.keystore.KeyStoreCryptoOperationUtils.getInvalidKeyExceptionForInit(KeyStoreCryptoOperationUtils.java:54) at android.security.keystore.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(KeyStoreCryptoOperationUtils.java:89) at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(AndroidKeyStoreCipherSpiBase.java:265) at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:109) at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2984) at javax.crypto.Cipher.tryCombinations(Cipher.java:2891) at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2796) at javax.crypto.Cipher.chooseProvider(Cipher.java:773) at javax.crypto.Cipher.init(Cipher.java:1143) at javax.crypto.Cipher.init(Cipher.java:1084) at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encrypt(AndroidKeystoreAesGcm.java:69) at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.validateAead(AndroidKeystoreKmsClient.java:226) at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.getAead(AndroidKeystoreKmsClient.java:160) at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:259) 2020-09-29 12:24:36.788 19044-19044/? E/AndroidRuntime: ... 20 more Caused by: android.security.KeyStoreException: Too many operations at android.security.KeyStore.getKeyStoreException(KeyStore.java:1301) ... 35 more

Daniel-sims commented 4 years ago

Looks to be associated with Tink, exception is thrown here on line 268. https://github.com/google/tink/blob/master/java_src/src/main/java/com/google/crypto/tink/integration/android/AndroidKeysetManager.java

cmenon12 commented 4 years ago

I'm encountering this error too on a Pixel 4a on Android 11, this is with version 3.7.1 (83) of the app.

Daniel-sims commented 4 years ago

My app started to work about 3 days after I posted this bug.

tom-pryor commented 4 years ago

Also encountering this problem with a Pixel 4 XL on Android 11 with version 3.7.1 (83)

Can we get some confirmation is the app is still tracking or not? Seems rather serious if it's just suddenly broken and users may not be aware.

Daniel-sims commented 4 years ago

I've had a few exposure notifications, and have been using the application as I'd expect it to work since. It seems to be an issue with Pixel devices too.

tom-pryor commented 4 years ago

I wonder if it is something specific to Pixel devices or maybe Android 11 as Pixel devices tend to be among the first devices to get the update.

Just as an update I found rebooting the device allowed the app to open again. I'll keep an eye out to see if it starts crashing again.

jthawme commented 4 years ago

I also experienced the app crashing on startup with a pixel 4A (so it does seem the pixel connection is real). A restart did fix it and allowed it to open, but i had to go through all of the onboarding again

liamheneghan commented 3 years ago

I'm also experiencing the same crash just adding a stack trace and app info as well.

Version name: 4.0.1 Version code: 118

Pixel 3 Android 11, build number RP1A.201105.002

FATAL EXCEPTION: main
                         E  Process: uk.nhs.covid19.production, PID: 5171
                         E  java.lang.RuntimeException: Unable to create application uk.nhs.nhsx.covid19.android.app.ExposureApplication: java.security.KeyStoreException: the master key android-keystore://_master_key_strongbox_ exists but is unusable
                         E      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6717)
                         E      at android.app.ActivityThread.access$1300(ActivityThread.java:237)
                         E      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
                         E      at android.os.Handler.dispatchMessage(Handler.java:106)
                         E      at android.os.Looper.loop(Looper.java:223)
                         E      at android.app.ActivityThread.main(ActivityThread.java:7656)
                         E      at java.lang.reflect.Method.invoke(Native Method)
                         E      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
                         E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
                         E  Caused by: java.security.KeyStoreException: the master key android-keystore://_master_key_strongbox_ exists but is unusable
                         E      at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:268)
                         E      at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:228)
                         E      at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:121)
                         E      at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createEncryptedSharedPreferences$app_productionRelease(EncryptionUtils.kt:150)
                         E      at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createStrongBoxBackedEncryptedSharedPreferences(EncryptionUtils.kt:109)
                         E      at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createEncryptedSharedPreferences(EncryptionUtils.kt:100)
                         E      at uk.nhs.nhsx.covid19.android.app.ExposureApplication$buildAndUseAppComponent$sharedPreferences$1.invoke(ExposureApplication.kt:106)
                         E      at uk.nhs.nhsx.covid19.android.app.ExposureApplication$buildAndUseAppComponent$sharedPreferences$1.invoke(ExposureApplication.kt:37)
                         E      at uk.nhs.nhsx.covid19.android.app.util.RetryMechanism.retryWithBackOff(RetryMechanism.kt:25)
                         E      at uk.nhs.nhsx.covid19.android.app.util.RetryMechanism.retryWithBackOff$default(RetryMechanism.kt:18)
                         E      at uk.nhs.nhsx.covid19.android.app.ExposureApplication.buildAndUseAppComponent(ExposureApplication.kt:105)
                         E      at uk.nhs.nhsx.covid19.android.app.ExposureApplication.buildAndUseAppComponent$default(ExposureApplication.kt:103)
                         E      at uk.nhs.nhsx.covid19.android.app.ExposureApplication.onCreate(ExposureApplication.kt:50)
                         E      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
                         E      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
                         E      ... 8 more
                         E  Caused by: java.security.InvalidKeyException: Keystore operation failed
                         E      at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1378)
                         E      at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1388)
                         E      at android.security.keystore.KeyStoreCryptoOperationUtils.getInvalidKeyExceptionForInit(KeyStoreCryptoOperationUtils.java:54)
                         E      at android.security.keystore.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(KeyStoreCryptoOperationUtils.java:89)
                         E      at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(AndroidKeyStoreCipherSpiBase.java:265)
                         E      at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:109)
                         E      at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2984)
                         E      at javax.crypto.Cipher.tryCombinations(Cipher.java:2891)
                         E      at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2796)
                         E      at javax.crypto.Cipher.chooseProvider(Cipher.java:773)
                         E      at javax.crypto.Cipher.init(Cipher.java:1143)
                         E      at javax.crypto.Cipher.init(Cipher.java:1084)
                         E      at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encrypt(AndroidKeystoreAesGcm.java:69)
                         E      at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.validateAead(AndroidKeystoreKmsClient.java:226)
                         E      at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.getAead(AndroidKeystoreKmsClient.java:160)
                         E      at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:259)
                         E      ... 22 more
                         E  Caused by: android.security.KeyStoreException: Too many operations
                         E      at android.security.KeyStore.getKeyStoreException(KeyStore.java:1301)
                         E      ... 37 more
ElliotSknr commented 3 years ago

Same issue as reported above, adding my stack trace and info to assist. However in my case the application crashed when the app was fully in the background (Not open or in recent apps), after that point attempting to open the application would result in the below error. I was not able to grab the original stack trace when the application first crashed Device: Pixel 4xl OS Version: 11 App Version: 4.1.1

Restarting the phone resolved the issue, deleting data and cache alone was not sufficient.

2021-01-10 02:43:17.969 12020-12020/? E/AndroidRuntime: FATAL EXCEPTION: main Process: uk.nhs.covid19.production, PID: 12020 java.lang.RuntimeException: Unable to create application uk.nhs.nhsx.covid19.android.app.ExposureApplication: java.security.KeyStoreException: the master key android-keystore://_master_keystrongbox exists but is unusable at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6720) at android.app.ActivityThread.access$1300(ActivityThread.java:237) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7660) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.security.KeyStoreException: the master key android-keystore://_master_keystrongbox exists but is unusable at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey(AndroidKeysetManager.java:268) at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:228) at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:121) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createEncryptedSharedPreferences$app_productionRelease(EncryptionUtils.kt:150) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createStrongBoxBackedEncryptedSharedPreferences(EncryptionUtils.kt:109) at uk.nhs.nhsx.covid19.android.app.util.EncryptionUtils.createEncryptedSharedPreferences(EncryptionUtils.kt:100) at uk.nhs.nhsx.covid19.android.app.ExposureApplication$buildAndUseAppComponent$sharedPreferences$1.invoke(ExposureApplication.kt:107) at uk.nhs.nhsx.covid19.android.app.ExposureApplication$buildAndUseAppComponent$sharedPreferences$1.invoke(ExposureApplication.kt:38) at uk.nhs.nhsx.covid19.android.app.util.RetryMechanism.retryWithBackOff(RetryMechanism.kt:25) at uk.nhs.nhsx.covid19.android.app.util.RetryMechanism.retryWithBackOff$default(RetryMechanism.kt:18) at uk.nhs.nhsx.covid19.android.app.ExposureApplication.buildAndUseAppComponent(ExposureApplication.kt:106) at uk.nhs.nhsx.covid19.android.app.ExposureApplication.buildAndUseAppComponent$default(ExposureApplication.kt:104) at uk.nhs.nhsx.covid19.android.app.ExposureApplication.onCreate(ExposureApplication.kt:51) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6715) at android.app.ActivityThread.access$1300(ActivityThread.java:237)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:223)  at android.app.ActivityThread.main(ActivityThread.java:7660)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)  Caused by: java.security.InvalidKeyException: Keystore operation failed at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1378) at android.security.KeyStore.getInvalidKeyException(KeyStore.java:1388) at android.security.keystore.KeyStoreCryptoOperationUtils.getInvalidKeyExceptionForInit(KeyStoreCryptoOperationUtils.java:54) at android.security.keystore.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(KeyStoreCryptoOperationUtils.java:89) at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(AndroidKeyStoreCipherSpiBase.java:265) at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:109) at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2984) at javax.crypto.Cipher.tryCombinations(Cipher.java:2891) at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2796) at javax.crypto.Cipher.chooseProvider(Cipher.java:773) at javax.crypto.Cipher.init(Cipher.java:1143) at javax.crypto.Cipher.init(Cipher.java:1084) at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encrypt(AndroidKeystoreAesGcm.java:69) at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.validateAead(AndroidKeystoreKmsClient.java:226)

nhs-covid19 commented 3 years ago

We have now fixed a number of defects relating to StrongBox, so closing this issue.