android / android/security-samples

BiometricLoginKotlin: crash at Emulator API33

Open
#86 2 comments 5 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
1k
Forks
450
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash on Emulator API 33 and start with CryptographyManager.kt at line 98, then trace the call from EnableBiometricLoginActivity.kt at line 101. Compare the biometric encryption flow with API 32 and below; done means the sample no longer crashes on API 33 while preserving the working behavior on older APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
authentication, mobile-dev, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.