adorsys / secure-storage-android

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

NullPointerException on Certificate.getPublicKey #76

Closed Lovrenc closed 4 years ago

Lovrenc commented 4 years ago

Version 1.2.4

2020-01-28 14:12:50.871 8346-8496/ W/KeyStore: KeyStore exception android.os.ServiceSpecificException: (code 7) at android.os.Parcel.createException(Parcel.java:2085) at android.os.Parcel.readException(Parcel.java:2039) at android.os.Parcel.readException(Parcel.java:1987) at android.security.keystore.IKeystoreService$Stub$Proxy.get(IKeystoreService.java:978) at android.security.KeyStore.get(KeyStore.java:236) at android.security.KeyStore.get(KeyStore.java:225) at android.security.keystore.AndroidKeyStoreSpi.engineGetCertificate(AndroidKeyStoreSpi.java:165) at java.security.KeyStore.getCertificate(KeyStore.java:1120) 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 de.adorsys.android.securestoragelibrary.SecurePreferences.setValue(SecurePreferences.java:116)

Lovrenc commented 4 years ago

I noticed the lib failed to create a key upon the first setValue because my thread was interrupted so this was my mistake.

I am interested, however, why the lib never tried to recreate the key (on subsequent runs).

drilonrecica commented 4 years ago

I notices the lib failed to create a key upon the first setValue because my thread was interrupted so this was my mistake.

I am interested, however, why the lib never tried to recreate the key (on subsequent runs).

Hi @Lovrenc , The info you gave may be helpful for us finding this "bug" in the future. Could you please give some more info about the device model, OS version etc. so that we could try to reproduce the bug to make the research easier. Thanks for using SecureStorage and contributing.

Lovrenc commented 4 years ago

OpnePlus 6T Android v. 10 OxygenOS 10.3.0

In my case, I had a race condition.

The first interaction with SecurePreferences was called on a separate thread which was wrongly tied to the UI lifecycle and was sometimes disposed of before the key generation code hascompleted.