Giter Club home page Giter Club logo

secured-preference-store's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

secured-preference-store's Issues

Use Github Release Structure or CHANGELOG

It would be useful to have a CHANGELOG.md in the project's root or to use Github's release tagging feature to keep track of the different changes between versions.

For example the recent addition of the init method is a breaking change and would be useful if it was more obvious that it was added.

KeyStoreException Signature/MAC verification failed

Error occurred on the version 0.6.1 due to EcryptionManager getMacKey throws exception.

W/System.err: javax.crypto.AEADBadTagException
W/System.err:  at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:517)
        at javax.crypto.Cipher.doFinal(Cipher.java:2056)
        at devliving.online.securedpreferencestore.EncryptionManager.decryptAES(EncryptionManager.java:428)
        at devliving.online.securedpreferencestore.EncryptionManager.decrypt(EncryptionManager.java:272)
        at devliving.online.securedpreferencestore.EncryptionManager.tryDecrypt(EncryptionManager.java:217)
        at devliving.online.securedpreferencestore.EncryptionManager.decrypt(EncryptionManager.java:316)
        at devliving.online.securedpreferencestore.SecuredPreferenceStore.getString(SecuredPreferenceStore.java:143)


 W/System.err: Caused by: android.security.KeyStoreException: Signature/MAC verification failed
        at android.security.KeyStore.getKeyStoreException(KeyStore.java:1112)
        at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
        at android.security.keystore.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal(AndroidKeyStoreAuthenticatedAESCipherSpi.java:373)
        at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
    	... 22 more

[Question] - Sharing among multiple apps

Attempting to use this in a library that is shared between two apps. I have set the sharedUserId to the same ID in both apps (and the library). For the context I create a packageContext using the package name of one of my apps. However, I am not able to store the value in one app and fetch it in the other. Just curios to see if this is something that this AWESOME package is preventing me from doing. Should I be looking to move to a Content Provider instead that can use this package to secure the data at rest? Thanks in advance.

My code

  `val sharedContext = context.createPackageContext("com.one.of.my.apps", Context.MODE_PRIVATE)
    SecuredPreferenceStore.init(
        sharedContext,
        storeName,
        keyPrefix,
        seedKey,
        DefaultRecoveryHandler()
    )
    sharedPreferences = SecuredPreferenceStore.getSharedInstance()`

minSdk

这个版本必须18以上才能用吗?

anr when generateAESKey and call mStore.containsAlias(AES_KEY_ALIAS)

1.device and version: Samsung Galaxy J7 Prime (on7xelte), Android 8.1
2.anr log
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x732abec0 self=0xee07b000
| sysTid=19949 nice=0 cgrp=default sched=0/0 handle=0xf23304b8
| state=S schedstat=( 0 0 0 ) utm=9 stm=8 core=2 HZ=100
| stack=0xff334000-0xff336000 stackSize=8MB
| held mutexes=
#00 pc 0000000000049ff8 /system/lib/libc.so (__ioctl+8)
#1 pc 000000000001e215 /system/lib/libc.so (ioctl+40)
#2 pc 0000000000042839 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+204)
#3 pc 000000000004324f /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+246)
#4 pc 000000000003d45d /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+36)
#5 pc 00000000000c608d /system/lib/libandroid_runtime.so (???)
#6 pc 0000000000791c65 /system/framework/arm/boot-framework.oat (Java_android_os_BinderProxy_transactNative__ILandroid_os_Parcel_2Landroid_os_Parcel_2I+132)
at android.os.BinderProxy.transactNative (Native method)
at android.os.BinderProxy.transact (Binder.java:784)
at android.security.IKeystoreService$Stub$Proxy.exist (IKeystoreService.java:846)
at android.security.KeyStore.contains (KeyStore.java:527)
at android.security.keystore.AndroidKeyStoreSpi.engineContainsAlias (AndroidKeyStoreSpi.java:951)
at java.security.KeyStore.containsAlias (KeyStore.java:1293)
at ai.totok.chat.fqz.e (EncryptionManager.java:730)
at ai.totok.chat.fqz.a (EncryptionManager.java:717)
at ai.totok.chat.fqz.a (EncryptionManager.java:228)
at ai.totok.chat.fqz. (EncryptionManager.java:200)
at ai.totok.chat.frd. (SecuredPreferenceStoreExt.java:85)
at ai.totok.chat.frd.a (SecuredPreferenceStoreExt.java:161)
at ai.totok.chat.etm.a (SecureStoreUtil.java:86)
at ai.totok.chat.etm.b (SecureStoreUtil.java:146)
at ai.totok.chat.etm.b (SecureStoreUtil.java:292)
at ai.totok.chat.ehi.a (ZayhuPref.java:29)
at com.zayhu.app.ZayhuApplication.b (ZayhuApplication.java:403)
at com.zayhu.app.ZayhuApplication.onCreate (ZayhuApplication.java:190)

3.this is the code:
@TargetApi(Build.VERSION_CODES.M)
boolean generateAESKey(@nullable byte[] seed) throws KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
if (!mStore.containsAlias(AES_KEY_ALIAS)) {
KeyGenerator keyGen = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, KEYSTORE_PROVIDER);

        KeyGenParameterSpec spec = new KeyGenParameterSpec.Builder(AES_KEY_ALIAS, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                .setCertificateSubject(new X500Principal("CN = Secured Preference Store, O = Devliving Online"))
                .setCertificateSerialNumber(BigInteger.ONE)
                .setKeySize(AES_BIT_LENGTH)
                .setBlockModes(KeyProperties.BLOCK_MODE_GCM)
                .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
                .setRandomizedEncryptionRequired(false) //TODO: set to true and let the Cipher generate a secured IV
                .build();
        if(seed != null && seed.length > 0){
            SecureRandom random = new SecureRandom(seed);
            keyGen.init(spec, random);
        } else {
            keyGen.init(spec);
        }

        keyGen.generateKey();

        return true;
    }

    return false;
}

Make parameter names more descriptive

When autocomplete comes up in Android Studio, the parameter names are named things like s and s1. This isn't enough information as to what these parameters are for.

Renaming them to things like key and value where appropriate would be useful.

KeyNotValidYetException OnePlus3T Timezones

Hi,

I'm not sure if it's specific to the OnePlus3T or its more of a timezone issue but when trying to create a new AES key on this device I get the following exception:

 android.security.keystore.KeyNotYetValidException: Key not yet valid
W:     at android.security.KeyStore.getInvalidKeyException(KeyStore.java:684)
W:     at android.security.KeyStore.getInvalidKeyException(KeyStore.java:748)
W:     at android.security.keystore.KeyStoreCryptoOperationUtils.getInvalidKeyExceptionForInit(KeyStoreCryptoOperationUtils.java:54)
W:     at android.security.keystore.KeyStoreCryptoOperationUtils.getExceptionForCipherInit(KeyStoreCryptoOperationUtils.java:89)
W:     at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized(AndroidKeyStoreCipherSpiBase.java:265)
W:     at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit(AndroidKeyStoreCipherSpiBase.java:148)
W:     at javax.crypto.Cipher.tryTransformWithProvider(Cipher.java:2973)
W:     at javax.crypto.Cipher.tryCombinations(Cipher.java:2884)
W:     at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider(Cipher.java:2789)
W:     at javax.crypto.Cipher.chooseProvider(Cipher.java:956)
W:     at javax.crypto.Cipher.init(Cipher.java:1329)
W:     at javax.crypto.Cipher.init(Cipher.java:1267)
W:     at devliving.online.securedpreferencestore.EncryptionManager.encryptAES(EncryptionManager.java:324)
W:     at devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:168)
W:     at devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:213)
W:     at devliving.online.securedpreferencestore.SecuredPreferenceStore$Editor.putString(SecuredPreferenceStore.java:205)

Now when i change the timezone on my device to be an offset of 0, I do not get this exception. Where I am currently is +1 timezone.

I believe the problem originates in the generateAESKey() method at line 483 where the start date is retrieved. Rather than setting the start validity to this local date, I think its meant to be set in UTC format.

java.security.ProviderException - HTC M8

I don't believe this to be an issue with your library, but having turned up empty with web research, I'm just here as a last resort to see if you might have any insight or suggestions.

Device: HTC M8
Android OS: 6.0.1
Reinstall resolves issue: No
Users affected: 1
Reproducible: Only by one remote user (unable to physically debug device)

The only thing I can think of asking this user is if they have recently removed their screen lock. However, I am skeptical of this as the source, since this case has historically produced exceptions under a different name (usually java.lang.IllegalStateException).

Package: com.xxxxxxxxx
Version Code: YY
Version Name: Z.Z.Z
Android: 6.0.1
Android Build: MMB29M release-keys
Manufacturer: HTC
Model: HTC M8
Thread: main-1
CrashReporter Key: 0D2E8E80-8D22-39DB-3740-F7C66634F01214BA4CB1
Start Date: Thu Nov 16 20:16:33 GMT+01:00 2017
Date: Thu Nov 16 20:16:34 GMT+01:00 2017

java.lang.RuntimeException: Unable to create application com.xxxxxxxxx.ZZZApplication: java.security.ProviderException: Keystore operation failed
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java)
	at android.app.ActivityThread.access$1600(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
	at android.os.Handler.dispatchMessage(Handler.java)
	at android.os.Looper.loop(Looper.java)
	at android.app.ActivityThread.main(ActivityThread.java)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
Caused by: java.security.ProviderException: Keystore operation failed
	at android.security.keystore.AndroidKeyStoreKeyGeneratorSpi.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java)
	at javax.crypto.KeyGenerator.generateKey(KeyGenerator.java)
	at devliving.online.securedpreferencestore.EncryptionManager.generateAESKey(EncryptionManager.java:502)
	at devliving.online.securedpreferencestore.EncryptionManager.generateKey(EncryptionManager.java:472)
	at devliving.online.securedpreferencestore.EncryptionManager.setup(EncryptionManager.java:145)
	at devliving.online.securedpreferencestore.EncryptionManager.<init>(EncryptionManager.java:124)
	at devliving.online.securedpreferencestore.SecuredPreferenceStore.<init>(SecuredPreferenceStore.java:42)
	at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:87)
	at com.xxxxxxxxx.preferences.LoginPreferences.initKeyStore(LoginPreferences.java:213)
	at com.xxxxxxxxx.ZZZApplication.setupKeyStore(ZZZApplication.java:107)
	at com.xxxxxxxxx.ZZZApplication.onCreate(ZZZApplication.java:60)
	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java)
	... 9 more
Caused by: android.security.KeyStoreException: System error
	at android.security.KeyStore.getKeyStoreException(KeyStore.java)
	... 21 more

Exception source: android.security.keystore.AndroidKeyStoreKeyGeneratorSpi [Line 303]

RSA Key Generation failed with "IllegalArgumentException: startDate == null"

I run into that issue on API 21 when init the SecurePreferenceStore with
SecuredPreferenceStore.init(context.getApplicationContext(), new DefaultRecoveryHandler());

The following Exception was thrown:
Caused by: java.lang.IllegalArgumentException: startDate == null at android.security.KeyPairGeneratorSpec.<init>(KeyPairGeneratorSpec.java:141) at android.security.KeyPairGeneratorSpec$Builder.build(KeyPairGeneratorSpec.java:482) at devliving.online.securedpreferencestore.EncryptionManager.generateRSAKeys(EncryptionManager.java:614) at devliving.online.securedpreferencestore.EncryptionManager.generateKey(EncryptionManager.java:480) at devliving.online.securedpreferencestore.EncryptionManager.setup(EncryptionManager.java:151) at devliving.online.securedpreferencestore.EncryptionManager.<init>(EncryptionManager.java:130) at devliving.online.securedpreferencestore.SecuredPreferenceStore.<init>(SecuredPreferenceStore.java:44) at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:93) at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:114)

The Problem is that both startDate is null when generating the RSA Key. Looking deeper in the code I realized that both startDate and endDate are not set (both are null) in the EncryptionManager:

@SuppressWarnings("WrongConstant")
    void generateRSAKeys(Context context, @Nullable byte[] seed) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, KeyStoreException {
        if (!mStore.containsAlias(RSA_KEY_ALIAS)) {
                        KeyPairGenerator keyGen = KeyPairGenerator.getInstance(KEY_ALGORITHM_RSA, KEYSTORE_PROVIDER);

            KeyPairGeneratorSpec spec;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                spec = new KeyPairGeneratorSpec.Builder(context)
                        .setAlias(RSA_KEY_ALIAS)
                        .setKeySize(RSA_BIT_LENGTH)
                        .setKeyType(KEY_ALGORITHM_RSA)
                        .setSerialNumber(BigInteger.ONE)
                        .setSubject(new X500Principal("CN = Secured Preference Store, O = Devliving Online"))
                        .build();
            } else {
                spec = new KeyPairGeneratorSpec.Builder(context)
                        .setAlias(RSA_KEY_ALIAS)
                        .setSerialNumber(BigInteger.ONE)
                        .setSubject(new X500Principal("CN = Secured Preference Store, O = Devliving Online"))
                        .build();
            }

            if(seed != null && seed.length > 0) {
                SecureRandom random = new SecureRandom(seed);
                keyGen.initialize(spec, random);
            } else {
                keyGen.initialize(spec);
            }
            keyGen.generateKeyPair();
        }
    }

getBytes throws AEADBadTagException

While encryption / decryption works on 5.x and 6.x series, on a S7 with 7.x I get this exception while decoding with getBytes. Data amount less than 32K works without issues, but whenever I try with larger data I get this (see below). Then I tried to write chunked byte buffers (split a large byte buffer into multiple 32K buffers) but the problem remains the same.

02-12 18:35:49.786 9791-10394/xx.myapplication W/System.err: javax.crypto.AEADBadTagException
02-12 18:35:49.787 9791-10394/xx.myapplication W/System.err: at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:517)
02-12 18:35:49.787 9791-10394/xx.myapplication W/System.err: at javax.crypto.Cipher.doFinal(Cipher.java:2056)
02-12 18:35:49.787 9791-10394/xx.myapplication W/System.err: at devliving.online.securedpreferencestore.EncryptionManager.decryptAES(EncryptionManager.java:422)
02-12 18:35:49.787 9791-10394/xx.myapplication W/System.err: at devliving.online.securedpreferencestore.EncryptionManager.decrypt(EncryptionManager.java:266)
02-12 18:35:49.787 9791-10394/xx.myapplication W/System.err: at devliving.online.securedpreferencestore.EncryptionManager.tryDecrypt(EncryptionManager.java:211)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at devliving.online.securedpreferencestore.EncryptionManager.decrypt(EncryptionManager.java:310)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at devliving.online.securedpreferencestore.SecuredPreferenceStore.getString(SecuredPreferenceStore.java:116)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at devliving.online.securedpreferencestore.SecuredPreferenceStore.getBytes(SecuredPreferenceStore.java:184)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at xx.myapplication.utils.WebService$4.then(WebService.java:206)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at xx.myapplication.utils.WebService$4.then(WebService.java:197)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.Task$15.run(Task.java:917)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.Task.continueWithTask(Task.java:715)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.Task.continueWithTask(Task.java:726)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.Task$13.then(Task.java:818)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.Task$13.then(Task.java:806)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at bolts.Task$15.run(Task.java:917)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
02-12 18:35:49.788 9791-10394/xx.myapplication W/System.err: at java.lang.Thread.run(Thread.java:762)
02-12 18:35:49.789 9791-10394/xx.myapplication W/System.err: Caused by: android.security.KeyStoreException: Signature/MAC verification failed
02-12 18:35:49.789 9791-10394/xx.myapplication W/System.err: at android.security.KeyStore.getKeyStoreException(KeyStore.java:1097)
02-12 18:35:49.789 9791-10394/xx.myapplication W/System.err: at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
02-12 18:35:49.789 9791-10394/xx.myapplication W/System.err: at android.security.keystore.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal(AndroidKeyStoreAuthenticatedAESCipherSpi.java:373)
02-12 18:35:49.789 9791-10394/xx.myapplication W/System.err: at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
02-12 18:35:49.789 9791-10394/xx.myapplication W/System.err: ... 20 more

App Crashed in lollipop OS version with error "java.lang.IllegalStateException: Must call init() before using the store"

First of all thank you for sharing this awesome library.
My app perfectly working in other OS versions. Tested on Marshmallow Nougat working fine.
Here's the full stack trace for crash.

06-13 12:20:51.745 7726-7726/my.com.abc.app E/AndroidRuntime: FATAL EXCEPTION: main Process: my.com.abc.app, PID: 7726 java.lang.RuntimeException: Unable to start activity ComponentInfo{my.com.abc.app/my.com.abc.app.activities.LoginActivity}: java.lang.IllegalStateException: Must call init() before using the store at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.IllegalStateException: Must call init() before using the store at devliving.online.securedpreferencestore.SecuredPreferenceStore.getSharedInstance(SecuredPreferenceStore.java:58) at my.com.abc.app.activities.LoginActivity.initialization(LoginActivity.java:93) at my.com.abc.app.activities.LoginActivity.onCreate(LoginActivity.java:84) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  at android.app.ActivityThread.access$800(ActivityThread.java:151)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5254)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

I have use init method in Application like bellow.

`public class Global extends Application {

@Override
public void onCreate() {

    Stetho.initializeWithDefaults(this);

    try {
        SecuredPreferenceStore.init(getApplicationContext(), new DefaultRecoveryHandler());
    } catch (Exception e) {
        //TODO: handel get
        e.printStackTrace();
    }

    super.onCreate();
}

}`

"Key not yet valid" on device

I'm using SecuredPreferenceStore to store access tokens etc. Works fine in the emulator, but when I run the app on my device I'm not able to save anything.

The error I'm getting when calling putString is android.security.keystore.KeyNotYetValidException: Key not yet valid

Any idea why this is happening?

Keys are not encrypted at rest

Currently the keys stored in the KeyStore aren't encrypted at rest. We need to look out for a fix from Google for the issue 61989.

In case of no fix from Google, some options might be:

  • Let the library forget about the unrecoverable data and start over again.
  • Come up with a way to recover and migrate the data when the lock screen protection changes.

Some help would be appreciated

I'm kind of new at android development and would love some guidance if possible. I was wondering why when I add

compile 'online.devliving:securedpreferencestore:latest_version'

and build, I get this error:

Failed to resolve: online

Thanks in advance

IllegalBlocksizeException Huawei p8 lite ALE-L21

Hi. I have an issue similar to 18. When I try store an string in Huawei p8 lite ALE-L21 I get this error:

10-24 14:49:24.216 10624-10721/com.twogetherbank.app W/System.err: javax.crypto.IllegalBlockSizeException
10-24 14:49:24.221 10624-10721/com.twogetherbank.app W/System.err:     at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:486)
10-24 14:49:24.221 10624-10721/com.twogetherbank.app W/System.err:     at javax.crypto.Cipher.doFinal(Cipher.java:1505)
10-24 14:49:24.221 10624-10721/com.twogetherbank.app W/System.err:     at devliving.online.securedpreferencestore.EncryptionManager.encryptAES(EncryptionManager.java:401)
10-24 14:49:24.221 10624-10721/com.twogetherbank.app W/System.err:     at devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:242)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at devliving.online.securedpreferencestore.EncryptionManager.tryEncrypt(EncryptionManager.java:175)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at devliving.online.securedpreferencestore.EncryptionManager.encrypt(EncryptionManager.java:287)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at devliving.online.securedpreferencestore.SecuredPreferenceStore$Editor.putString(SecuredPreferenceStore.java:232)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at com.twogetherbank.app.utils.managers.CategoryManager$loadCategoriesFromServer$1.invoke(CategoryManager.kt:64)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at com.twogetherbank.app.utils.managers.CategoryManager$loadCategoriesFromServer$1.invoke(CategoryManager.kt:18)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Async.kt:140)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at org.jetbrains.anko.AsyncKt$doAsync$1.invoke(Async.kt)
10-24 14:49:24.222 10624-10721/com.twogetherbank.app W/System.err:     at org.jetbrains.anko.AsyncKt$sam$Callable$761a5578.call(Async.kt)
10-24 14:49:24.224 10624-10721/com.twogetherbank.app W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-24 14:49:24.224 10624-10721/com.twogetherbank.app W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
10-24 14:49:24.224 10624-10721/com.twogetherbank.app W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
10-24 14:49:24.224 10624-10721/com.twogetherbank.app W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
10-24 14:49:24.224 10624-10721/com.twogetherbank.app W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
10-24 14:49:24.224 10624-10721/com.twogetherbank.app W/System.err:     at java.lang.Thread.run(Thread.java:833)
10-24 14:49:24.224 10624-10721/com.twogetherbank.app W/System.err: Caused by: android.security.KeyStoreException: -65536
10-24 14:49:24.225 10624-10721/com.twogetherbank.app W/System.err:     at android.security.KeyStore.getKeyStoreException(KeyStore.java:632)
10-24 14:49:24.225 10624-10721/com.twogetherbank.app W/System.err:     at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.update(KeyStoreCryptoOperationChunkedStreamer.java:132)
10-24 14:49:24.225 10624-10721/com.twogetherbank.app W/System.err:     at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:217)
10-24 14:49:24.225 10624-10721/com.twogetherbank.app W/System.err:     at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:473)
10-24 14:49:24.225 10624-10721/com.twogetherbank.app W/System.err: 	... 17 more

In others devices the library works fine.

Can you help me?

Cannot connect to keystore

Cannot connect to keystore
android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:617)
at android.security.IKeystoreService$Stub$Proxy.begin(IKeystoreService.java:1255)

This mistake happens occasionally. The wrong place is the 496th line of EncryptionManager.

AndroidManifest contains application label

Secured-Preference-Store/securedpreferencestore/src/main/AndroidManifest.xml
<application android:label="@string/app_name">

The AndroidManifest in the SecuredPreferenceStore package contains an application label which causes a Manifest merger failure for any project which also contains its own label. What is the purpose of this labels presence?

Adding tools:replace to the Android Manifest is not a solution for me since this library is being integrated into an SDK and I do not want to force everyone using it to have to add this as well.

Error: Manifest merger failed : Attribute application@label value=(My Application) from AndroidManifest.xml:14:9-39
is also present at [online.devliving:securedpreferencestore:0.7.4] AndroidManifest.xml:11:18-50 value=(@string/app_name).
Suggestion: add 'tools:replace="android:label"' to element at AndroidManifest.xml:10:5-40:19 to override.

App crashes when the users changes the lock screen pattern

I'm testing on a 4.4.4 device where the screen lock was set to None. I changed it to PIN and after that I'm getting a crash. Are you experiencing the same? It's one of the problematic cases pointed on The Forgetful Keystore where the keys are lost.
java.lang.RuntimeException: java.io.IOException: Error while finalizing cipher
at devliving.online.securedpreferencestore.SecuredPreferenceStore.a(SourceFile:46)

I debugged the code and the keys are not generated again, the key store contains the alias but it crashes when it's trying to load the key on the RSADecrypt method
while ((nextByte = cipherInputStream.read()) != -1) {

Caused by: javax.crypto.BadPaddingException: error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block type is not 02
at com.android.org.conscrypt.NativeCrypto.RSA_private_decrypt(Native Method)
at com.android.org.conscrypt.OpenSSLCipherRSA.engineDoFinal(OpenSSLCipherRSA.java:273)
at com.android.org.conscrypt.OpenSSLCipherRSA.engineDoFinal(OpenSSLCipherRSA.java:297)

java.lang.NoClassDefFoundError: devliving.online.securedpreferencestore.Logger on Android APi 19

Couln't launch app on Android emulator, Android 4.4 Api 19. Other api works correct.

I/dalvikvm: Could not find method devliving.online.securedpreferencestore.EncryptionManager.getHashed, referenced from method devliving.online.securedpreferencestore.SecuredPreferenceStore.getStringSet W/dalvikvm: VFY: unable to resolve static method 1011: Ldevliving/online/securedpreferencestore/EncryptionManager;.getHashed (Ljava/lang/String;)Ljava/lang/String; D/dalvikvm: VFY: replacing opcode 0x71 at 0x0006 I/dalvikvm: Could not find method devliving.online.securedpreferencestore.Logger.e, referenced from method devliving.online.securedpreferencestore.SecuredPreferenceStore.getStringSet W/dalvikvm: VFY: unable to resolve static method 1013: Ldevliving/online/securedpreferencestore/Logger;.e (Ljava/lang/Exception;)V D/dalvikvm: VFY: replacing opcode 0x71 at 0x0039 DexOpt: unable to opt direct call 0x03fe at 0x2b in Ldevliving/online/securedpreferencestore/SecuredPreferenceStore;.<init> DexOpt: unable to opt direct call 0x03fc at 0x37 in Ldevliving/online/securedpreferencestore/SecuredPreferenceStore;.<init> DexOpt: unable to opt direct call 0x03f0 at 0x3e in Ldevliving/online/securedpreferencestore/SecuredPreferenceStore;.<init> DexOpt: unable to opt direct call 0x03fd at 0x02 in Ldevliving/online/securedpreferencestore/SecuredPreferenceStore;.edit D/AndroidRuntime: Shutting down VM W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x9cca8b20) E/AndroidRuntime: FATAL EXCEPTION: main Process: zam.wallet, PID: 3297 java.lang.NoClassDefFoundError: devliving.online.securedpreferencestore.Logger at devliving.online.securedpreferencestore.SecuredPreferenceStore.<init>(SecuredPreferenceStore.java:67) at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:134)

could not generate key in keystore error

When beta testing my app, one user out of around 1,000 users experienced "could not generate key in keystore" error and could not log in to my service with the following exception.

Caused by java.lang.IllegalStateException: could not generate key in keystore android.security.AndroidKeyPairGenerator.generateKeyPair (AndroidKeyPairGenerator.java:99) java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair (KeyPairGenerator.java:276) devliving.online.securedpreferencestore.EncryptionManager.generateRSAKeys (EncryptionManager.java:488) devliving.online.securedpreferencestore.EncryptionManager.generateKey (EncryptionManager.java:348) devliving.online.securedpreferencestore.EncryptionManager.<init> (EncryptionManager.java:95) devliving.online.securedpreferencestore.SecuredPreferenceStore.<init> (SecuredPreferenceStore.java:36) devliving.online.securedpreferencestore.SecuredPreferenceStore.getSharedInstance (SecuredPreferenceStore.java:42)

Is there any solutions to this problem?

I'm using minSdk 21 and target 25.
The device info is:-

Manufacturer: Samsung
Model: SHV-E470S
Board: Msm8974
Android API: 21
Android OS: 5.0.1

"Attempt to invoke interface method 'int android.security.IKeystoreService.exist(java.lang.String, int)' on a null object reference" error

When beta testing my app, one user out of around 1,000 users experienced "Attempt to invoke interface method 'int android.security.IKeystoreService.exist(java.lang.String, int)' on a null object reference" error and could not log in to my service with the following exception.

Caused by java.lang.NullPointerException: Attempt to invoke interface method 'int android.security.IKeystoreService.exist(java.lang.String, int)' on a null object reference android.security.KeyStore.contains (KeyStore.java:137) android.security.KeyStore.contains (KeyStore.java:145) android.security.AndroidKeyStore.engineContainsAlias (AndroidKeyStore.java:415) java.security.KeyStore.containsAlias (KeyStore.java:442) devliving.online.securedpreferencestore.EncryptionManager.generateRSAKeys (EncryptionManager.java:458) devliving.online.securedpreferencestore.EncryptionManager.generateKey (EncryptionManager.java:348) devliving.online.securedpreferencestore.EncryptionManager.<init> (EncryptionManager.java:95) devliving.online.securedpreferencestore.SecuredPreferenceStore.<init> (SecuredPreferenceStore.java:36) devliving.online.securedpreferencestore.SecuredPreferenceStore.getSharedInstance (SecuredPreferenceStore.java:42)

Is there any solutions to this problem?

I'm using minSdk 21 and target 25.
The device info is:-

Manufacturer: LGE
Model: LG-F460K
Board: Apq8084
Android API: 21
Android OS: 5.0.1

KeyPermanentelyInvalidatedException was added in API 23

After upgrading to version 0.4.0, the app doesn't work on Android 4.4

java.lang.NoClassDefFoundError: android.security.keystore.KeyPermanentlyInvalidatedException
                                                                                at devliving.online.securedpreferencestore.EncryptionManager.isRecoverableError(EncryptionManager.java:137)
                                                                                at devliving.online.securedpreferencestore.EncryptionManager.(EncryptionManager.java:127)
                                                                                at devliving.online.securedpreferencestore.SecuredPreferenceStore.(SecuredPreferenceStore.java:42)
                                                                                at devliving.online.securedpreferencestore.SecuredPreferenceStore.getSharedInstance(SecuredPreferenceStore.java:57)

Keystore operation failed on Huawei P9Lite

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

Very long strings are not stored

I used this library quite often with a lot of success.
However right now I have a problem with storing a long JSON string (>7000 chars).
The edit().putString().apply() goes through smoothly, but the key is not even present in the SharedPreferences afterwards.

Failed to init Secured Preference Store. Exception: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Hello,

I am using the latest version of the library (0.7.2).
I noticed that the init function was marked as deprecated so I tried to use the new init function (by the way, the description of the new function is missing the @param annotations for the newly added input fields).

The extra arguments of the new init function:
private static final String SECURE_PREFS_NAME = "secPrefs";
private static final String SECURE_KEY_PREFIX = "testvss";
private static final byte[] SECURE_PREFS_SEED = "seed".getBytes();

The stack trace of the error:
W/System.err: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at devliving.online.securedpreferencestore.SecuredPreferenceStore$MigrationHelper.migrateToV10(SecuredPreferenceStore.java:491)
at devliving.online.securedpreferencestore.SecuredPreferenceStore$MigrationHelper.migrate(SecuredPreferenceStore.java:548)
at devliving.online.securedpreferencestore.SecuredPreferenceStore$MigrationHelper.migrate(SecuredPreferenceStore.java:537)
at devliving.online.securedpreferencestore.SecuredPreferenceStore.(SecuredPreferenceStore.java:60)
at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:116)
at initializeSecurePreferences(Application.java:136).

Can you please check?
Also, how can I enable the library specific logs?

KeyStore exception in log on Android 9 device

Thx for a great library.
When running on a Android 9 device (Pixel) I see an error in the log. This happens both when target api is set to Android 9 (28) and earlier (tested with 26). This exception is not propagated to the calling app.
This error does not occur when running older Android devices (tested on Android 8 and 6).
I can't tell the severity of this error (the call to "KeyStore.entryInstanceOf" probably fails, which is part of an if statement) but hope you can :)
BR, Kristian

Stacktrace:
W/KeyStore: KeyStore exception
android.os.ServiceSpecificException: (code 7)
at android.os.Parcel.createException(Parcel.java:1956)
at android.os.Parcel.readException(Parcel.java:1910)
at android.os.Parcel.readException(Parcel.java:1860)
at android.security.IKeystoreService$Stub$Proxy.get(IKeystoreService.java:786)
at android.security.KeyStore.get(KeyStore.java:195)
at android.security.keystore.AndroidKeyStoreSpi.engineGetCertificate(AndroidKeyStoreSpi.java:144)
at java.security.KeyStoreSpi.engineEntryInstanceOf(KeyStoreSpi.java:583)
at java.security.KeyStore.entryInstanceOf(KeyStore.java:1631)
at devliving.online.securedpreferencestore.EncryptionManager.loadKey(EncryptionManager.java:690)
at devliving.online.securedpreferencestore.EncryptionManager.setup(EncryptionManager.java:228)
at devliving.online.securedpreferencestore.EncryptionManager.(EncryptionManager.java:201)
at devliving.online.securedpreferencestore.SecuredPreferenceStore.(SecuredPreferenceStore.java:79)
at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:134)
at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:142)
at ...

Suggestion: it would be nice to know if key is inside secure hardware

I think it would be nice to offer an easy way to someone using your library to know if the key used for encryption is currently stored in secure hardware. In my case I'd like to have this information to show it to the user and let him know that his data base is encrypted but it may (or may not) be 100% secure as his hardware supports (or not) TrustZone or whatever secure system.

I don't know if this is out of the scope of this library but its just a suggestion.

In my case I created a class copying your EncryptionManager class and adding a couple of functions. Please note that this was a fast guess and I haven't checked if there is a better way to determine or another way to determine it in API lower than 23, for example.

public static boolean isHardwareBacked(Context appContext) throws Exception {
        SharedPreferences prefs = appContext.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
        EncryptionManager mEncryptionManager = new EncryptionManager(appContext, prefs);
        return mEncryptionManager.isHardwareBacked();
    }
    
	@SuppressLint("NewApi")
	public boolean isHardwareBacked() {
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
			return false;
		}
		
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
			return false; // Can't determine as KeyInfo is API 23
		}
		
		if (aesKey != null) {
			SecretKey key = aesKey;
			try {
				SecretKeyFactory factory = SecretKeyFactory.getInstance(
						key.getAlgorithm(), "AndroidKeyStore");
				KeyInfo keyInfo = (KeyInfo) factory.getKeySpec(key, KeyInfo.class);
				return keyInfo.isInsideSecureHardware();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return false;
    }

java.lang.IllegalArgumentException: key.length == 0

When initializing the library I got this situation: it will fail to init due to IllegalArgumentException.
I was doing some tests regarding recovery after a keystore deletion due to unlock pattern/pin/password changes. Usually the recovery was as expected, but one of the times it got stuck in this situation, and only reinstalling the app would fix it.

11-10 09:30:32.331: E/OpenSSLKeyMaster(195): OpenSSL error in openssl_sign_rsa 67526788: error:04066084:rsa routines:RSA_EAY_PRIVATE_ENCRYPT:data too large for modulus
11-10 09:30:32.331: W/keystore(195): device couldn't sign data
11-10 09:30:32.331: W/OpenSSL-keystore-rsa(6391): No valid signature returned
11-10 09:30:32.335: E/OpenSSLKeyMaster(195): OpenSSL error in openssl_sign_rsa 67547258: error:0406B07A:rsa routines:RSA_padding_add_none:data too small for key size
11-10 09:30:32.335: W/keystore(195): device couldn't sign data
11-10 09:30:32.335: W/OpenSSL-keystore-rsa(6391): No valid signature returned
11-10 09:30:32.335: W/System.err(6391): java.lang.IllegalArgumentException: key.length == 0
11-10 09:30:32.335: W/System.err(6391): 	at javax.crypto.spec.SecretKeySpec.<init>(SecretKeySpec.java:62)
11-10 09:30:32.335: W/System.err(6391): 	at devliving.online.securedpreferencestore.EncryptionManager.getFallbackAESKey(EncryptionManager.java:555)
11-10 09:30:32.335: W/System.err(6391): 	at devliving.online.securedpreferencestore.EncryptionManager.loadKey(EncryptionManager.java:465)
11-10 09:30:32.335: W/System.err(6391): 	at devliving.online.securedpreferencestore.EncryptionManager.setup(EncryptionManager.java:146)
11-10 09:30:32.335: W/System.err(6391): 	at devliving.online.securedpreferencestore.EncryptionManager.<init>(EncryptionManager.java:124)
11-10 09:30:32.335: W/System.err(6391): 	at devliving.online.securedpreferencestore.SecuredPreferenceStore.<init>(SecuredPreferenceStore.java:42)
11-10 09:30:32.335: W/System.err(6391): 	at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:87)
11-10 09:30:32.335: W/System.err(6391): 	at com.spotbros.database.MultiprocessPreferencesProvider.init(MultiprocessPreferencesProvider.java:69)
11-10 09:30:32.335: W/System.err(6391): 	at com.spotbros.database.MultiprocessPreferencesProvider.getContentUri(MultiprocessPreferencesProvider.java:522)
11-10 09:30:32.335: W/System.err(6391): 	at com.spotbros.database.MultiprocessPreferencesProvider.access$0(MultiprocessPreferencesProvider.java:520)
11-10 09:30:32.335: W/System.err(6391): 	at com.spotbros.database.MultiprocessPreferencesProvider$MultiprocessSharedPreferences.getString(MultiprocessPreferencesProvider.java:488)
11-10 09:30:32.335: W/System.err(6391): 	at com.spotbros.database.SpotBrosProvider$SpotbrosDatabaseHelper.getDBEncryptionPassword(SpotBrosProvider.java:2414)
11-10 09:30:32.335: W/System.err(6391): 	at com.spotbros.database.SpotBrosProvider$SpotbrosDatabaseHelper.access$0(SpotBrosProvider.java:2407)
11-10 09:30:32.335: W/System.err(6391): 	at com.spotbros.database.SpotBrosProvider.onCreate(SpotBrosProvider.java:2667)
11-10 09:30:32.335: W/System.err(6391): 	at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
11-10 09:30:32.339: W/System.err(6391): 	at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
11-10 09:30:32.339: W/System.err(6391): 	at android.app.ActivityThread.installProvider(ActivityThread.java:4774)
11-10 09:30:32.339: W/System.err(6391): 	at android.app.ActivityThread.installContentProviders(ActivityThread.java:4369)
11-10 09:30:32.339: W/System.err(6391): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4309)
11-10 09:30:32.339: W/System.err(6391): 	at android.app.ActivityThread.access$1500(ActivityThread.java:135)
11-10 09:30:32.339: W/System.err(6391): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-10 09:30:32.339: W/System.err(6391): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-10 09:30:32.339: W/System.err(6391): 	at android.os.Looper.loop(Looper.java:136)
11-10 09:30:32.339: W/System.err(6391): 	at android.app.ActivityThread.main(ActivityThread.java:5001)
11-10 09:30:32.339: W/System.err(6391): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-10 09:30:32.339: W/System.err(6391): 	at java.lang.reflect.Method.invoke(Method.java:515)
11-10 09:30:32.339: W/System.err(6391): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-10 09:30:32.339: W/System.err(6391): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-10 09:30:32.339: W/System.err(6391): 	at dalvik.system.NativeStart.main(Native Method)
11-10 09:30:32.343: W/dalvikvm(6391): threadid=1: thread exiting with uncaught exception (group=0xa4d87b20)
11-10 09:30:32.347: E/AndroidRuntime(6391): FATAL EXCEPTION: main
11-10 09:30:32.347: E/AndroidRuntime(6391): Process: com.spotbros.enterprise, PID: 6391
11-10 09:30:32.347: E/AndroidRuntime(6391): java.lang.RuntimeException: Unable to get provider com.imbox.database.ImboxProvider: java.lang.IllegalStateException: Must call init() before using the store
11-10 09:30:32.347: E/AndroidRuntime(6391): 	at android.app.ActivityThread.installProvider(ActivityThread.java:4777)
11-10 09:30:32.347: E/AndroidRuntime(6391): 	at android.app.ActivityThread.installContentProviders(ActivityThread.java:4369)
11-10 09:30:32.347: E/AndroidRuntime(6391): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4309)

llegalStateException: Must call init() before using the store

Hello,

I am using the library and works fine in all the devices that I tested so far. The problem is that I receive crashes in production for some older devices (i.e. Samsung Note 3 with Android 5):

llegalStateException: Must call init() before using the store in SecuredPreferenceStore.setRecoveryHandler

, but I call init as it is stated in the documentation (cannot replicate it on devices that I have available).

Please provide a fix and let me know!

KeyStoreService.del null object reference on HUAWEI device 7.0

java.lang.RuntimeException: Unable to create application com.bananasrl.banana.Utils.App: java.lang.NullPointerException: Attempt to invoke interface method 'int android.security.IKeystoreService.del(java.lang.String, int)' on a null object reference
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5678)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int android.security.IKeystoreService.del(java.lang.String, int)' on a null object reference
at android.security.KeyStore.delete(KeyStore.java:186)
at android.security.Credentials.deletePrivateKeyTypeForAlias(Credentials.java:292)
at android.security.Credentials.deleteAllTypesForAlias(Credentials.java:251)
at android.security.keystore.AndroidKeyStoreKeyGeneratorSpi.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java:329)
at javax.crypto.KeyGenerator.generateKey(KeyGenerator.java:580)
at devliving.online.securedpreferencestore.EncryptionManager.generateAESKey(EncryptionManager.java:502)
at devliving.online.securedpreferencestore.EncryptionManager.generateKey(EncryptionManager.java:472)
at devliving.online.securedpreferencestore.EncryptionManager.setup(EncryptionManager.java:145)
at devliving.online.securedpreferencestore.EncryptionManager.(EncryptionManager.java:124)
at devliving.online.securedpreferencestore.SecuredPreferenceStore.(SecuredPreferenceStore.java:42)
at devliving.online.securedpreferencestore.SecuredPreferenceStore.init(SecuredPreferenceStore.java:87)
at com.bananasrl.banana.Utils.App.onCreate(App.java:111)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1028)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5659)
... 8 more

so long time for store

In a project, it takes 3 seconds or so long to save a field for the first time. I wonder if you have this problem. Thanks

IllegalBlockSizeException on Samsung Galaxy S7 7.0

Hi,

When running my app on a Samsung Galaxy S7 running android version 7.0 I get the following exception:

javax.crypto.IllegalBlockSizeException
W:     at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:519)
W:     at javax.crypto.Cipher.doFinal(Cipher.java:2056)
W:     at devliving.online.securedpreferencestore.EncryptionManager.decryptAES(EncryptionManager.java:348)
W:     at devliving.online.securedpreferencestore.EncryptionManager.decrypt(EncryptionManager.java:192)
W:     at devliving.online.securedpreferencestore.EncryptionManager.decrypt(EncryptionManager.java:236)
W:     at devliving.online.securedpreferencestore.SecuredPreferenceStore.getString(SecuredPreferenceStore.java:89)
W:     at com.flipsidegroup.beegeeandroid.api.AuthInterceptor.intercept(AuthInterceptor.java:88)
W:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W:     at com.flipsidegroup.beegeeandroid.dagger.ApiModule$1.intercept(ApiModule.java:103)
W:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W:     at com.flipsidegroup.beegeeandroid.api.BaseUrlInterceptor.intercept(BaseUrlInterceptor.java:41)
W:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
W:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
W:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
W:     at okhttp3.RealCall.execute(RealCall.java:63)
W:     at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
W:     at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:40)
W:     at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24)
W:     at retrofit2.adapter.rxjava.BodyOnSubscribe.call(BodyOnSubscribe.java:33)
W:     at retrofit2.adapter.rxjava.BodyOnSubscribe.call(BodyOnSubscribe.java:25)
W:     at rx.Observable.unsafeSubscribe(Observable.java:10142)
W:     at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
W:     at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:230)
W:     at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
W:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
W:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
W:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W:     at java.lang.Thread.run(Thread.java:762)
W: Caused by: android.security.KeyStoreException: Invalid operation handle
W:     at android.security.KeyStore.getKeyStoreException(KeyStore.java:1097)
W:     at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.update(KeyStoreCryptoOperationChunkedStreamer.java:132)
W:     at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:217)
W:     at android.security.keystore.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal(AndroidKeyStoreAuthenticatedAESCipherSpi.java:373)
W:     at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
W: 	... 31 more

This happened multiple times but then all of a sudden it just started working successfully. I came across this question in StackOverflow that details the same scenario and a potential solution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.