mjwheatley / cordova-plugin-android-fingerprint-auth

A cordova plugin for fingerprint authentication using the hardware fingerprint scanner on devices running Android 6+
Apache License 2.0
168 stars 131 forks source link

InvalidAlgorithmParmeterException in createKey() causes crash #4

Closed scottmcnab closed 8 years ago

scottmcnab commented 8 years ago

While testing this plugin on Android 6 emulator, I get unexpected app termination attempting to call FingerprintAuth.show() (after a successful call to FingerprintAuth.isAvailable() that indicates fingerprints are available and enrolled):

V/FingerprintAuth: Init FingerprintAuth V/FingerprintAuth: FingerprintAuth action: availability W/CordovaPlugin: Attempted to send a second callback for ID: FingerprintAuth1796866245 Result was: "OK" V/FingerprintAuth: FingerprintAuth action: authenticate W/CordovaPlugin: Attempted to send a second callback for ID: FingerprintAuth1796866267 Result was: "Error" W/CordovaPlugin: Attempted to send a second callback for ID: FingerprintAuth1796866267 Result was: "InvalidKeyException" D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.myapp, PID: 1019 java.lang.NullPointerException: Attempt to invoke virtual method 'void com.cordova.plugin.android.fingerprintauth.FingerprintAuthenticationDialogFragment.setCryptoObject(android.hardware.fingerprint.FingerprintManager$CryptoObject)' on a null object reference at com.cordova.plugin.android.fingerprintauth.FingerprintAuth$1.run(FingerprintAuth.java:196) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Details:

Investigating with debugger shows InvalidAlgorithmParameterException raised (and caught) in createKey() method with this message (when executing the "authenticate" action):

"java.lang.IllegalStateException: At least one fingerprint must be enrolled to create keys requiring user authentication for every use"

Since this error case is never acted on to abort the call, this in turn causes initCipher() to fail with InvalidKeyException (message "Unsupported key: null"), falling through to the "else" statement, whereby mFragment is null as it is never initialised (hence crash).

Any idea what is causing this or how to fix it? Thanks!

scottmcnab commented 8 years ago

FYI to reproduce this bug:

NOTE: if you then simulate locking and unlocking the emulator with the fingerprint (instead of PIN) then the plugin works fine!

rakeshpalivela commented 8 years ago

Hi @scottmcnab did you get any solutions? I am also facing same issue.

mjwheatley commented 8 years ago

Is this an emulator only error, or is it showing up on hardware devices as well?

Shall I then abort the call upon catching that exception to prevent the crash, or would that just be masking the problem? It would not change the fact that you would be unable to use fingerprint authentication.

rakeshpalivela commented 8 years ago

Hi @mjwheatley I am facing this in Hardware device (Samsung S6 Edge Device).

mjwheatley commented 8 years ago

I have published v0.0.8 to improve the error handling in order to prevent the plugin from causing the application to crash. Now if the cipher fails to initialize the backup activity will be launched and ask for the backup pin, password, or pattern. If you validate using a fingerprint on this screen it seems to resolve the issue with the key being permanently revoked which seemed to be causing the cipher from being initialized.

Please test it out and let me know if it helps resolve this issue.