Secured-Preference-Store
Secured-Preference-Store copied to clipboard
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)
#01 pc 000000000001e215 /system/lib/libc.so (ioctl+40)
#02 pc 0000000000042839 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+204)
#03 pc 000000000004324f /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+246)
#04 pc 000000000003d45d /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+36)
#05 pc 00000000000c608d /system/lib/libandroid_runtime.so (???)
#06 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.
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;
}