adorsys / secure-storage-android

Store strings & credentials securely encrypted on your device
Apache License 2.0
367 stars 58 forks source link

java.security.PublicKey java.security.cert.Certificate.getPublicKey() on a null object reference de.adorsys.android.securestoragelibrary.KeystoreTool.getPublicKey #86

Closed halilozdemr closed 1 year ago

halilozdemr commented 4 years ago

Hello adorsys,

I use 1.2.4 version.

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.security.PublicKey java.security.cert.Certificate.getPublicKey()' on a null object reference at de.adorsys.android.securestoragelibrary.KeystoreTool.getPublicKey(KeystoreTool.java:174) at de.adorsys.android.securestoragelibrary.KeystoreTool.encryptMessage(KeystoreTool.java:82) at de.adorsys.android.securestoragelibrary.SecurePreferences.setValue(SecurePreferences.java:59) at tr.gov.eicisleri.App.onCreate(App.kt:33) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1158) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6250) at android.app.ActivityThread.access$1200(ActivityThread.java:237) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1792) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7078) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)

Caused by de.adorsys.android.securestoragelibrary.SecureStorageException: Attempt to invoke virtual method 'java.security.PublicKey java.security.cert.Certificate.getPublicKey()' on a null object reference at de.adorsys.android.securestoragelibrary.KeystoreTool.getPublicKey(KeystoreTool.java:182) at de.adorsys.android.securestoragelibrary.KeystoreTool.encryptMessage(KeystoreTool.java:82) at de.adorsys.android.securestoragelibrary.SecurePreferences.setValue(SecurePreferences.java:59) at this is my application class.onCreate(App.kt:33) I create a UUID.randomUUID() and save it, SecurePreferences.setValue(this, "uuid_key", UUID.randomUUID().toString()) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1158) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6250) at android.app.ActivityThread.access$1200(ActivityThread.java:237) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1792) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7078) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)

Devices 100% samsung Operating systems 52% Android 9 36% Android 8 12% Android 10

HelenaSewell commented 4 years ago

I am also seeing this issue on 1.2.4 - also seems to be only Samsung devices.

drilonrecica commented 4 years ago

Hello @halilozdemr & @HelenaSewell , Sorry for the late reply! This seems to be a recurring problem with android devices and their implementation of the KeyStore. Other libraries and apps that use the KeyStore also seem to encounter this without much success of circumventing it.

I will look at possibilities in the next days/weeks and keep you posted.

Thank you for contributing to secure-storage-android

Shinineko commented 4 years ago

Hello @drilonrecica are there any updates on this topic yet? I'm also facing this issue on 1.2.4.

drilonrecica commented 4 years ago

I'm sorry but I have not found a solution to the problem yet. This seems too be a Android Keystore failure which happens on some devices (mostly Samsung but also some others). Since we are migrating to SecureStorage2 I will se if it appears there as well and hope to find a workaround. I will keep you informed if I find something.

kukabi commented 3 years ago

Not 100% sure yet, but running the code that accesses the secure preferences on the main thread seems to have fixed the issue for me. It was a write that caused the crash in my case.

pulpet112 commented 2 years ago

Hello, any updates on this? The issue still exists.

ruijun commented 2 years ago

@halilozdemr hello,any updates on this problem??

halilozdemr commented 2 years ago

hello @ruijun, no updates. But I've started use EncryptedSharedPreferences https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences

ruijun commented 2 years ago

@halilozdemr this problem is occasionally??