Merge "Keystore 2.0: Fix getKey returns null on key not found."

This commit is contained in:
Treehugger Robot
2021-02-06 04:43:49 +00:00
committed by Gerrit Code Review

View File

@@ -352,11 +352,14 @@ public class AndroidKeyStoreProvider extends Provider {
try { try {
response = keyStore.getKeyEntry(descriptor); response = keyStore.getKeyEntry(descriptor);
} catch (android.security.KeyStoreException e) { } catch (android.security.KeyStoreException e) {
if (e.getErrorCode() == ResponseCode.KEY_PERMANENTLY_INVALIDATED) { switch (e.getErrorCode()) {
case ResponseCode.KEY_NOT_FOUND:
return null;
case ResponseCode.KEY_PERMANENTLY_INVALIDATED:
throw new KeyPermanentlyInvalidatedException( throw new KeyPermanentlyInvalidatedException(
"User changed or deleted their auth credentials", "User changed or deleted their auth credentials",
e); e);
} else { default:
throw (UnrecoverableKeyException) throw (UnrecoverableKeyException)
new UnrecoverableKeyException("Failed to obtain information about key") new UnrecoverableKeyException("Failed to obtain information about key")
.initCause(e); .initCause(e);