From 7c147befcbf54bc153f795da1dd90a83917932dc Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Tue, 23 Jun 2020 21:37:11 +0200 Subject: [PATCH] Fix catching ProviderException with KeyStoreException as the cause We're looking for android.security.KeyStoreException as the cause of ProviderException, not java.security.KeyStoreException. Unfortunately this is a hidden class, so all we can do is check the class name. --- .../java/com/beemdevelopment/aegis/crypto/KeyStoreHandle.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/beemdevelopment/aegis/crypto/KeyStoreHandle.java b/app/src/main/java/com/beemdevelopment/aegis/crypto/KeyStoreHandle.java index a94edf88..5cb1c89b 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/crypto/KeyStoreHandle.java +++ b/app/src/main/java/com/beemdevelopment/aegis/crypto/KeyStoreHandle.java @@ -63,9 +63,9 @@ public class KeyStoreHandle { return generator.generateKey(); } catch (ProviderException e) { // a ProviderException can occur at runtime with buggy Keymaster HAL implementations - // so if this was caused by a KeyStoreException, throw a KeyStoreHandleException instead + // so if this was caused by an android.security.KeyStoreException, throw a KeyStoreHandleException instead Throwable cause = e.getCause(); - if (cause instanceof KeyStoreException) { + if (cause != null && cause.getClass().getName().equals("android.security.KeyStoreException")) { throw new KeyStoreHandleException(cause); } throw e;