adorsys / secure-storage-android

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

NullPointerException: SecurePreferences.getStringValue #38

Closed NathanSass closed 5 years ago

NathanSass commented 5 years ago
if (SecurePreferences.contains(DOWNLOAD_KEY)) {
    SecurePreferences.getStringValue(DOWNLOAD_KEY, null)!!.toSecretByteArray
}

SecurePreferences.getStringValue is throwing a NPE on one of my coworkers devices. Any idea why a user may be able to know that they have a DOWNLOAD_KEY but not be able to access it.

This crash is on startup and they are unable to use the app - even after deleting it and re-downloading it.

"%1$s is having trouble with Google Play services. Please try again." is the core exception. Its then wrapped in an SecureStorageException (ExceptionType.INTERNAL_LIBRARY_EXCEPTION) with the message "KeyPair does not exist in Keystore"

kabliz commented 5 years ago

Hello, affected coworker here, I tried to trace the extent of the error through the debugger, though with everything obfuscated and sometimes in binary I had somewhat of a hard time tracking. What I do know:

method a.e():PrivateKey appears to be the affected area. My device is API 28. I think a.h():Keystore throws the exception.

AndroidKeyStoreSpi.engineGetKey may be the internal method. at line if (!mKeyStore.contains(userKeyAlias, mUid)) return null; userKeyAlias= "USRPKEY_adorsysKeyPair" mUid = -1

which calls KeyStore.contains

The exception makes the stack and my debugger start jumping around and I can't tell what's happening again until i see "%1$s is having trouble with Google Play services. Please try again." being pulled out of resources, followed by "KeyPair does not exist in Keystore".

if the KeyPair can't be obtained in the keystore, it would be nice if SecurePreferences.contains also returns false.

drilonrecica commented 5 years ago

Hi, thank you for reporting this. We will look into this issue ASAP and inform you about the solution.

luckyhandler commented 5 years ago

Hey, on first sight, it seems to be related with https://github.com/adorsys/secure-storage-android/issues/37. Could you post a stacktrace?

kabliz commented 5 years ago

Our stacktrace wouldn't be helpful to you. It crashes with a NPE on our client side - by then SecurePreferences has already internally caught its own exception and returned null to us.

I've used the debugger to get the information i could and i posted it above.

luckyhandler commented 5 years ago

Hey @KATHYxx and @NathanSass, I just pushed a commit which realizes your wish that contains also returns false if the key pair does not exist - see more at commit https://github.com/adorsys/secure-storage-android/commit/14d11a6fe4f73a847dbb650e697230301178dbc4 This will be released with Version 1.1.0