When uploading our app to the Google Play store, google's pre-launch report indicates that the app is crashing with a null pointer exception. The issue is regarding KeyStore implementation in Huawei devices only.
Stacktrace:
Fatal Exception: 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.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:464)
at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:699)
at com.example.utility.crypto.KeyStoreHelper.createKeys(Unknown Source)
at com.example.utility.crypto.KeyStoreHelper.createKeys(Unknown Source)
at com.example.activities.register.SplashActivity$1.run(Unknown Source)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:255)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:776)
I am using Google's Tink library for Keystore implementation. Library has nothing to do with error. Error still occurs without library.
Below is code:
@Throws(Exception::class)
private fun getOrGenerateNewKeysetHandle(): KeysetHandle {
return AndroidKeysetManager.Builder()
.withSharedPref(this, "KEYSET", "PREF")
.withKeyTemplate(AeadKeyTemplates.AES256_GCM)
.withMasterKeyUri(REIWA_MASTER_KEY_URI)
.build()
.keysetHandle
}
I think it has to do something with the device's keystore implementation.
Any help will be appreciated.