sergeykomlach / AdvancedBiometricPromptCompat

This is an Android project allowing you to use the advanced biometric authorization features.
Apache License 2.0
155 stars 17 forks source link

One Plus 9 fingerprint unlock calls onSucceeded when dialog is cancelled #305

Closed jamiehiggins closed 2 years ago

jamiehiggins commented 2 years ago

When testing the library on the One Plus 9 I have noticed that if I cancel the dialog while prompting for a fingerprint, instead of getting an onCanceled callback like I do on other devices I am seeing an onSucceeded callback. This is allowing users to bypass the security lock simply by cancelling the dialog.

There appears to be no difference in the onSucceeded callback on this device if I do actually authenticate with my fingerprint as the return parameter is identical.

sergeykomlach commented 2 years ago

Sounds like a critical issue. I have a OnePlus 8T device, but with the test app, all works fine, including the case with dialog cancel.

Can you provide more details about this case?

jamiehiggins commented 2 years ago

I am testing against the latest version 2.1.11, although it also happens on older versions (I first noticed on 2.0.79 and upgraded to latest to test)

The test APK exhibits the same problem when I click any of the buttons and then click to cancel I see a Succeeded popup message.

In my app I am using the following: BiometricAuthRequest(BiometricApi.AUTO, BiometricType.BIOMETRIC_ANY, BiometricConfirmation.ANY)

The toast is shown below:

image

If I cancel the popup by going back (using back button/swipe gesture) I do see the correct cancel popup as desired.

My device is running Android 12.

jamiehiggins commented 2 years ago

On my OnePlus 7 with Android 11 the issue does not happen and everything behaves as it should.

sergeykomlach commented 2 years ago

@jamiehiggins okay, I checked the code and behavior on my OnePlus 8T/Android 12. For me both API's (Fingerprint and Biometric) behave in a next way:

Also, I checked more logic that handles errors and success cases - onSucceeded() will be called if at least one API call the onAuthenticationSucceeded. From your report - it seems like touching outside leads to onAuthenticationSucceeded for both - Fingerprint and BiometricPrompt API.

Recently I faced a bug on MS Surface Duo when onAuthenticationError with 10 "The user canceled the operation." was called right after onAuthenticationFailed. It's just an idea, but I have a mind that if you touch outside the dialog, the onAuthenticationSucceeded called due to some system bug, and then onAuthenticationError is called, but this call will be ignored.

Is possible to get from your OnePlus 9 device to get logs? You can obtain logs from LogCat OR after bug reproducing - press "Send logs".

Thank you.

sergeykomlach commented 2 years ago

@jamiehiggins So, I prepare the APK with possible fix. Testing required

jamiehiggins commented 2 years ago

Thanks so much for the super quick response. I will test first thing tomorrow morning and report back ASAP.

jamiehiggins commented 2 years ago

The fix has the same result, I'm afraid. Hitting back or touching outside the dialog returns the correct Canceled result, but hitting the cancel button still shows the success popup.

Screenshot_20220816_225231

I can't seem to send logs I'm afraid as it loads up gmail and then hangs before crashing.

jamiehiggins commented 2 years ago

Here is the logcat output after this issue happens.

logcat.txt

sergeykomlach commented 2 years ago

Okay, step-by-step we moving. I pushed some changes to oneplus_9 branch, so fresh test build can be found here

jamiehiggins commented 2 years ago

Result is the same. Updated logcat output is attached:

logcat_op9.txt

sergeykomlach commented 2 years ago

@jamiehiggins

  1. prepared the update, not sure that the issue is fixed, but it may produce some additional information in logcat APK here
  2. Can you try to launch this sample https://github.com/Kieun/android-biometricprompt and reproduce the bug?
jamiehiggins commented 2 years ago

@sergeykomlach I have just emailed logs from the new APK.

The sample app does get an onAuthenticationSucceeded returned when I hit the cancel button, however it then goes on to hit the SignatureException so it doesn't succeed. (All works fine when I authenticate with the fingerprint).

sergeykomlach commented 2 years ago

@jamiehiggins thank you for the logs and feedback! It seems like in case of false onAuthenticationSucceeded, if used BiometricCryptoObject - Cipher/Signature is not initialized properly and can't be used for crypto functions. I can try to use this to detect the false onAuthenticationSucceeded calls. Here the APK with fix. Hope this will help

jamiehiggins commented 2 years ago

@sergeykomlach that APK is working great and I am now getting the cancelled popup when I tap the cancel button. Great work!

sergeykomlach commented 2 years ago

Super! I'll close the issue and prepare new version of the library