From fca9c8ad2f325001bdbcd5cd2118c15120f0ea99 Mon Sep 17 00:00:00 2001 From: maxkomarychev Date: Fri, 20 Jul 2018 11:07:07 +0300 Subject: [PATCH] Catch uncaught exceptions to prevent crash (#134) `NullPointerException` thrown on some Huawei devices is crashing entire app. Handle all exceptions and rethrow them as caught exceptions. This is an attempt to prevent issue described in https://github.com/oblador/react-native-keychain/issues/115. --- .../keychain/cipherStorage/CipherStorageKeystoreAESCBC.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/android/src/main/java/com/oblador/keychain/cipherStorage/CipherStorageKeystoreAESCBC.java b/android/src/main/java/com/oblador/keychain/cipherStorage/CipherStorageKeystoreAESCBC.java index 7cc45d2..8174ed9 100644 --- a/android/src/main/java/com/oblador/keychain/cipherStorage/CipherStorageKeystoreAESCBC.java +++ b/android/src/main/java/com/oblador/keychain/cipherStorage/CipherStorageKeystoreAESCBC.java @@ -88,6 +88,8 @@ public class CipherStorageKeystoreAESCBC implements CipherStorage { throw new CryptoFailedException("Could not encrypt data for service " + service, e); } catch (KeyStoreException | KeyStoreAccessException e) { throw new CryptoFailedException("Could not access Keystore for service " + service, e); + } catch (Exception e) { + throw new CryptoFailedException("Unknown error: " + e.getMessage(), e); } } @@ -108,6 +110,8 @@ public class CipherStorageKeystoreAESCBC implements CipherStorage { throw new CryptoFailedException("Could not get key from Keystore", e); } catch (KeyStoreAccessException e) { throw new CryptoFailedException("Could not access Keystore", e); + } catch (Exception e) { + throw new CryptoFailedException("Unknown error: " + e.getMessage(), e); } } @@ -123,6 +127,8 @@ public class CipherStorageKeystoreAESCBC implements CipherStorage { } } catch (KeyStoreException e) { throw new KeyStoreAccessException("Failed to access Keystore", e); + } catch (Exception e) { + throw new KeyStoreAccessException("Unknown error " + e.getMessage(), e); } }