NativeScript / plugins

@nativescript plugins to help with your developments.
https://docs.nativescript.org/plugins/index.html
Apache License 2.0
189 stars 107 forks source link

[@nativescript/biometrics] SecItemCopyMatching Failed #524

Closed tujlaky closed 1 year ago

tujlaky commented 1 year ago

On iOS 16.6 I have started to see the following error when I am trying to call verifyBiometric:

  {
  "code": 70,
  "message": "SecItemCopyMatching Failed"
  }

I am using the plugin in the following way:

biometricAuth.verifyBiometric({
  ios: {
    fetchSecret: true,
  },
});

I am using the latest version of the@nativescript/biometrics plugin (1.3.1)

tujlaky commented 1 year ago

After doing more debugging the error is happening here:

https://github.com/NativeScript/plugins/blob/main/packages/biometrics/index.ios.ts#L152

I have checked the real result code which is -25300 or errSecItemNotFound.

https://developer.apple.com/documentation/security/1542001-security_framework_result_codes/errsecitemnotfound

jcassidyav commented 1 year ago

Have you set a secret? if you are not using this to encrypt a secret, and have not previously called with the secret parameter, do not pass the fetchSecret flag.

i.e. To encrypt/decrypt a secret

tujlaky commented 1 year ago

Thanks, originally I migrated from the old fingerprint-auth package and I wanted to disable the Passcode option. This way it worked somehow maybe it was a leftover from before.

I still have an issue if I try without the pinfallback: true. In that case the verifyBiometric call is just returning with true without checking the Face ID or Passcode.

So this works:

                    .verifyBiometric({
                        message: "Use your fingerprint",
                        pinFallback: true
                    })

But this will resolve without any check:

                    .verifyBiometric({
                        message: "Use your fingerprint",
                        pinFallback: false
                    })

So if I understand correctly currently not possible to have a Face ID auth without the option to fallback to Passcode.

tujlaky commented 1 year ago

Sorry, I have figured out.

                    .verifyBiometric({
                        message: "Use your fingerprint",
                        pinFallback: true,
                        fallbackMessage: 'Enter password',
                        ios: {
                            customFallback: true,
                        },
                    })

I would say the pinFallback true is misleading in this case.

tujlaky commented 1 year ago

One more step is needed for the real solution:

            .verifyBiometric({
                pinFallback: isIOS,
                ios: {
                    customFallback: true, // This will only work if pinFallback is true on iOS
                },
            })

With this I can achieve what was previously possible with the old plugin: allow only to use biometric authentications.