mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-28 08:00:19 +01:00
Split different exception scopes
Before this change the initinalization of the trusted key store was combined in one try-catch-block. If anything went wrong an new in memory trusted key store was created. Programming against an exception is an bad pattern. So the initialization is now splitted into multiple try-catch-blocks with it's own scopes and the decision if the trusted key store is newly created in memory or loaded from a exisitng file is done by an if condition check. Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
1bbbe20834
commit
eabd0b2d2c
@ -54,13 +54,22 @@ public class MagicTrustManager implements X509TrustManager {
|
|||||||
private KeyStore trustedKeyStore = null;
|
private KeyStore trustedKeyStore = null;
|
||||||
|
|
||||||
public MagicTrustManager() {
|
public MagicTrustManager() {
|
||||||
keystoreFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("CertsKeystore",
|
keystoreFile = new File(NextcloudTalkApplication.Companion.getSharedApplication()
|
||||||
Context.MODE_PRIVATE), "keystore.bks");
|
.getDir("CertsKeystore", Context.MODE_PRIVATE),
|
||||||
|
"keystore.bks");
|
||||||
try (FileInputStream fileInputStream = new FileInputStream(keystoreFile)) {
|
try {
|
||||||
trustedKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
trustedKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
Log.e(TAG, "Trusted key store can't be created.", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keystoreFile.exists()) {
|
||||||
|
try (FileInputStream fileInputStream = new FileInputStream(keystoreFile)) {
|
||||||
trustedKeyStore.load(fileInputStream, null);
|
trustedKeyStore.load(fileInputStream, null);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
|
Log.e(TAG, "Error during opening the trusted key store.", exception);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
trustedKeyStore.load(null, null);
|
trustedKeyStore.load(null, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user