Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] setGenericPassword not working on Samsung devices: "Attempt to invoke virtual method 'getPublicKey()' on a null object reference" #403

Open
SocialBrothersDEV opened this issue Oct 6, 2020 · 20 comments

Comments

@SocialBrothersDEV
Copy link

First of all, thanks for this library. It has helped me a lot already.

However, i am running into an issue on Samsung devices when calling setGenericPassword().

I am currently invoking the method like this:

Keychain.setGenericPassword('general', value, {
    accessible: Keychain.ACCESSIBLE.WHEN_UNLOCKED,
    accessControl:
      hasBiometrics && isBiometricsProtected
        ? Keychain.ACCESS_CONTROL.BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE
        : undefined,
    service: username ? `${service}_${username}` : service,
  });

However when i do this i am getting this error on Android:

Error: Unknown error: Attempt to invoke virtual method 'java.security.PublicKey java.security.cert.Certificate.getPublicKey()' on a null object reference
    at Object.promiseMethodWrapper [as setGenericPasswordForOptions] (NativeModules.js:103)
    at Object.setGenericPassword (index.js:179)
    at setKeychain$ (Storage.ts:37)
    at tryCatch (runtime.js:63)
    at Generator.invoke [as _invoke] (runtime.js:293)
    at Generator.next (runtime.js:118)
    at tryCatch (runtime.js:63)
    at invoke (runtime.js:154)
    at runtime.js:164
    at tryCallOne (core.js:37)

Please let me know how i can fix this, my app is going to production soon.

@AlexD10S
Copy link

AlexD10S commented Oct 26, 2020

Hi,
I am getting this error too, in my case in a Xiaomi.
How did you fix it?

@oferRounds
Copy link

Seeing it also

@oferRounds
Copy link

Hi @AlexD10S, did you find any solution to this?

@SocialBrothersDEV
Copy link
Author

I have eventually removed this library from my project and moved to Expo's SecureStore and LocalAuthentication libraries. I would love to come back to this library once this is fixed tho.

@oferRounds
Copy link

Thanks @SocialBrothersDEV!
(I’m not using expo, so that won’t work for me)

@Perolini
Copy link

I have the same problem on Huawei

@nadishan
Copy link

nadishan commented Dec 6, 2020

I have the same problem with Nokia (API Level 29)

@fr33z3
Copy link

fr33z3 commented Jan 25, 2021

Any updates for this problem? Did anyone solved it?

@ObidosDev
Copy link

Same here. Samsung... Android 10, One UI 2.0

@weraaaaz
Copy link

Same for Samsung Galaxy S20 (Android 11), Samsung Galaxy S10 (Android 11), Samsung Galaxy A71 (Android 11), Samsung Galaxy S7 edge (Android 8), Nokia 7.2 (Android 10)

@Juan-Castelli
Copy link

I'm following this issue as it appears to be critical.

It is NOT happening on real device Samsung A50 with Android 10 OneUI2.5.

At least when using setGenericPassword/getGenericPassword.

Does it happen when you call it normally with no options at all? Just the service option, username and password?

@aleksterm
Copy link

Hey guys!

Got similar problem. In my app's flow, I was initially using setGenericPassword() without any accessControl option. Then I prompt user to enable biometric auth and in case he agreed I invoked setGenericPassword() again with the same credentials plus accessControl option BIOMETRY_ANY. And it failed with the error Attempt to invoke virtual method...

Through trial and errors I found out, that in that case I had to previously use resetGenericPassword() before storing the same credentials with setGenericPassword().

If this is your case, you may give this workaround a try.

@elshan-eth
Copy link

Hi

I had the problem with setInternetCredentials. But I changed setInternetCredentials to setGenericPassword and the problem disappeared.

@0xGaryWu
Copy link

Any updates?????

it works for several days, but fail now on my xiaomi device(android11).

@LouisWT
Copy link

LouisWT commented Apr 19, 2022

Any update? I followed @aleksterm advice, but still, get this error log sometimes.

@MAKARD
Copy link

MAKARD commented Jun 23, 2023

well, 2023
This issue is still with us
Version 8.1.1
image
image

@ErickMaeda
Copy link

Hello, this issue started happening with me when using the Keychain.setGenericPassword with Biometrics

I have this set of devices that had this issue:

Screenshot 2023-07-05 at 13 38 28

Screenshot 2023-07-05 at 13 39 10

Does anyone has an update on this issue?

@Elf2707
Copy link

Elf2707 commented Aug 28, 2023

Same issue Android. Nothing helped

@lchenfox
Copy link

lchenfox commented Jan 18, 2024

The same issue on Andorid.

Error: Unknown error: Attempt to invoke virtual method 'java.security.PublicKey 
java.security.cert.Certificate.getPublicKey()' on a null object reference
Error: Unknown error: Attempt to invoke virtual method 'java.security.PublicKey 
java.security.cert.Certificate.getPublicKey()' on a null object reference

@Dr0pG
Copy link

Dr0pG commented Jun 28, 2024

Any updates on this, guys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests