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

Keystore operation failed on Huawei P9Lite #18

Closed
estebanlamas opened this issue Sep 22, 2017 · 6 comments
Closed

Keystore operation failed on Huawei P9Lite #18

estebanlamas opened this issue Sep 22, 2017 · 6 comments
Assignees

Comments

@estebanlamas
Copy link

Hi,

The library works fine on almost all devices I tried, but in a Huawei P9Lite with Android 6 I receive and exception when I try to save a string:

SecuredPreferenceStore.init(this, new DefaultRecoveryHandler());
sharedPreferences = SecuredPreferenceStore.getSharedInstance();
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(name,value);

The exception is:

java.security.InvalidKeyException: Keystore operation failed
android.security.KeyStore.getInvalidKeyException(KeyStore.java:700)
android.security.KeyStore.getInvalidKeyException(KeyStore.java:720)
android.security.keystore.KeyStoreCryptoOperationUtils.getInvalidKeyExceptionForInit(KeyStoreCryptoOperationUtils.java:53)
android.security.keystore.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(KeyStoreCryptoOperationUtils.java:89)
android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(AndroidKeyStoreCipherSpiBase.java:263)
android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:147)
javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:611)
javax.crypto.Cipher.tryCombinations(Cipher.java:535)
javax.crypto.Cipher.getSpi(Cipher.java:440)
javax.crypto.Cipher.init(Cipher.java:912)
javax.crypto.Cipher.init(Cipher.java:862)
devliving.online.securedpreferencestore.EncryptionManager.encryptAES(EncryptionManager.java:398)
devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:242)
devliving.online.securedpreferencestore.EncryptionManager.tryEncrypt(EncryptionManager.java:175)
devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:287)
devliving.online.securedpreferencestore.SecuredPreferenceStore$Editor.putString(SecuredPreferenceStore.java:232)

Caused by: android.security.KeyStoreException: -65535
at android.security.KeyStore.getKeyStoreException(KeyStore.java:640)
... 26 more
@iamMehedi iamMehedi self-assigned this Sep 22, 2017
@iamMehedi
Copy link
Owner

Thanks for reporting. Did this happen randomly or after you changed PIN/Password/Fingerprint? or does this happen every time you try to use the lib? @estebanlamas

@estebanlamas
Copy link
Author

It happens every time I try to use the lib.
Thanks for the quick answer.

@jepoy16
Copy link

jepoy16 commented Oct 19, 2017

we also encounter the same. Do we have updates on this? Please advise.

Many Thanks

@abhi-gadewar
Copy link

We are also facing same problem. Can somebody help here?

@abhi-gadewar
Copy link

@iamMehedi Can you help here?

@IDan14
Copy link

IDan14 commented May 8, 2018

I can also confirm this issue on a Huawei P10 Lite running Android 7.0. Solution provided by @StuStirling on #15 (or just commenting EncryptionManager line 494 .setKeyValidityStart(start.getTime())) solved this problem.

Log extract (running version 0.5.1) :

java.security.InvalidKeyException: Keystore operation failed
        at android.security.KeyStore.getInvalidKeyException(KeyStore.java:733)
        at android.security.KeyStore.getInvalidKeyException(KeyStore.java:754)
        at android.security.keystore.KeyStoreCryptoOperationUtils.getInvalidKeyExceptionForInit(KeyStoreCryptoOperationUtils.java:54)
        at android.security.keystore.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(KeyStoreCryptoOperationUtils.java:89)
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(AndroidKeyStoreCipherSpiBase.java:265)
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:148)
        at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2973)
        at javax.crypto.Cipher.tryCombinations(Cipher.java:2884)
        at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2789)
        at javax.crypto.Cipher.chooseProvider(Cipher.java:956)
        at javax.crypto.Cipher.init(Cipher.java:1329)
        at javax.crypto.Cipher.init(Cipher.java:1267)
at devliving.online.securedpreferencestore.EncryptionManager.encryptAES(EncryptionManager.java:398)
        at devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:242)
        at devliving.online.securedpreferencestore.EncryptionManager.tryEncrypt(EncryptionManager.java:175)
        at devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:287)
        at devliving.online.securedpreferencestore.SecuredPreferenceStore$Editor.putString(SecuredPreferenceStore.java:232)
        at devliving.online.securedpreferencestoresample.MainActivity.saveData(MainActivity.java:110)
        at devliving.online.securedpreferencestoresample.MainActivity$2.onClick(MainActivity.java:65)
        at android.view.View.performClick(View.java:5647)
        at android.view.View$PerformClick.run(View.java:22479)
        at android.os.Handler.handleCallback(Handler.java:761)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6595)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
    Caused by: android.security.KeyStoreException: -65535
        at android.security.KeyStore.getKeyStoreException(KeyStore.java:672)
    	... 27 more

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

5 participants