android / security-samples

Multiple samples showing the best practices in security APIs on Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BiometricLoginKotlin: crash at Emulator API33

KKChong opened this issue · comments

I've tried to run the app on Emulator API 33, it crash as below (but it is working on API 32 and below):

2022-09-01 17:46:41.132 21363-21363/com.example.biometricloginsample E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.biometricloginsample, PID: 21363
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
 Caused by: javax.crypto.IllegalBlockSizeException
    at android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:613)
    at javax.crypto.Cipher.doFinal(Cipher.java:2056)
    at com.example.biometricloginsample.CryptographyManagerImpl.encryptData(CryptographyManager.kt:98)
    at com.example.biometricloginsample.EnableBiometricLoginActivity.encryptAndStoreServerToken(EnableBiometricLoginActivity.kt:101)
    at com.example.biometricloginsample.EnableBiometricLoginActivity.access$encryptAndStoreServerToken(EnableBiometricLoginActivity.kt:30)
    at com.example.biometricloginsample.EnableBiometricLoginActivity$showBiometricPromptForEncryption$biometricPrompt$1.invoke(EnableBiometricLoginActivity.kt:91)
    at com.example.biometricloginsample.EnableBiometricLoginActivity$showBiometricPromptForEncryption$biometricPrompt$1.invoke(EnableBiometricLoginActivity.kt:30)
    at com.example.biometricloginsample.BiometricPromptUtils$createBiometricPrompt$callback$1.onAuthenticationSucceeded(BiometricPromptUtils.kt:48)
    at androidx.biometric.BiometricFragment$2$2.run(BiometricFragment.java:140)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7898)
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
 Caused by: android.security.KeyStoreException: Key user not authenticated (internal Keystore code: -26 message: In KeystoreOperation::update

Caused by:
    0: In update: KeyMint::update failed.
    1: Error::Km(ErrorCode(-26))) (public error code: 2 internal Keystore code: -26)
    at android.security.KeyStore2.getKeyStoreException(KeyStore2.java:369)
    at android.security.KeyStoreOperation.handleExceptions(KeyStoreOperation.java:78)
    at android.security.KeyStoreOperation.update(KeyStoreOperation.java:115)
    at android.security.keystore2.KeyStoreCryptoOperationChunkedStreamer$MainDataStream.update(KeyStoreCryptoOperationChunkedStreamer.java:222)
    at android.security.keystore2.KeyStoreCryptoOperationChunkedStreamer.update(KeyStoreCryptoOperationChunkedStreamer.java:156)
    at android.security.keystore2.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:179)
    at android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:603)
    	... 16 more
commented

Facing the exact same issue, also got this working on API 32, but fails on API 33. This seems to be a major issue, anyone knows a workaround or solution?
Can anyone confirm if this is a emulator-only issue or also happens on real devices?

I'm not sure why google still ignore our issue. This is very huge impact to our existing user.