cordova-plugin-secure-storage-echo icon indicating copy to clipboard operation
cordova-plugin-secure-storage-echo copied to clipboard

Added KeyPermanentlyInvalidatedException handling

Open giordanocardillo opened this issue 5 years ago • 2 comments

Customers were complaining that device would infinitely ask device password/PIN if they changed it.

I found out that initializing secure storage was bringing to the reuse of the same key, which was permanently invalidated from android system.

I created a method to delete the key if there is a KeyPermanentlyInvalidatedException, therefore the plugin will initialize a new key.

giordanocardillo avatar Nov 26 '19 20:11 giordanocardillo

Hi,

Thanks for providing a fix for the screen-lock issue !

After adding your code to my project, the console shows a different error after deleting the key and executing the init method again: Error: KeyStore doesn't contain alias: xxxx It looks like the key has been removed but doesn't get re-instantiated...

I did some debugging and found an issue in the 'init' method. The key should be created through the generateEncryptionKeys method. Instead, it doesn't pass the following line of code: if (storage.isEmpty()) { //Solves Issue #96. The RSA key may have been deleted by changing the lock type. getStorage(INIT_SERVICE).clear(); rsa.createKeyPair(getContext(), alias, userAuthenticationValidityDuration); }

Since the 'sharedPreferences' folder doesn't get cleared, the key wont be generated.

No idea why this IF statement is required but removing it fixes the issue...

aximobile avatar Jun 19 '20 13:06 aximobile

@aximobile how did you solve it? removing only the if statement? did you keep these two lines?

getStorage(INIT_SERVICE).clear();
rsa.createKeyPair(getContext(), alias, userAuthenticationValidityDuration);

Thanks!!

mateo2181 avatar Jan 08 '21 19:01 mateo2181