From 878066ca99c1170479fb217d68ecdb9cf5498975 Mon Sep 17 00:00:00 2001 From: BrianBlade Date: Thu, 2 Apr 2015 13:35:42 +0200 Subject: [PATCH] Add option to use MTM without default TrustManager Add a new "Don't trust system CAs" preference under advanced options that will change the behaviour of the MemorizingTrustManager. All formerly unknown certificates will raise a warning if checked. --- .../services/XmppConnectionService.java | 19 ++++++++++++++++--- .../conversations/ui/SettingsActivity.java | 3 ++- src/main/res/values-de/strings.xml | 2 ++ src/main/res/values/strings.xml | 2 ++ src/main/res/xml/preferences.xml | 5 +++++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index ca182867a..f94e715eb 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -532,9 +532,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa ExceptionHelper.init(getApplicationContext()); PRNGFixes.apply(); this.mRandom = new SecureRandom(); - this.mMemorizingTrustManager = new MemorizingTrustManager( - getApplicationContext()); - + updateMemorizingTrustmanager(); final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; this.mBitmapCache = new LruCache(cacheSize) { @@ -2185,6 +2183,21 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return this.mMemorizingTrustManager; } + public void setMemorizingTrustManager(MemorizingTrustManager trustManager) { + this.mMemorizingTrustManager = trustManager; + } + + public void updateMemorizingTrustmanager() { + final MemorizingTrustManager tm; + final boolean dontTrustSystemCAs = getPreferences().getBoolean("dont_trust_system_cas", false); + if (dontTrustSystemCAs) { + tm = new MemorizingTrustManager(getApplicationContext(), null); + } else { + tm = new MemorizingTrustManager(getApplicationContext()); + } + setMemorizingTrustManager(tm); + } + public PowerManager getPowerManager() { return this.pm; } diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index 39e215f2b..1bc59b138 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -79,7 +79,8 @@ public class SettingsActivity extends XmppActivity implements } } } + } else if (name.equals("dont_trust_system_cas")) { + xmppConnectionService.updateMemorizingTrustmanager(); } } - } diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index 0dd9f4011..d5533061b 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -427,6 +427,8 @@ Keine App für die Standort-Anzeige gefunden Standort Standort empfangen + Misstraue Zertifizierungsstellen + Alle Zertifikate müssen manuell bestätigt werden %d Kontakt ausgewählt %d Kontakte ausgewählt diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index af56c0146..28bb71e95 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -454,6 +454,8 @@ No application found to display location Location Received location + Don\'t trust system CAs + All certificates must be manually approved Select %d contact Select %d contacts diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 8bf6eb877..d48124a60 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -147,6 +147,11 @@ android:key="keep_foreground_service" android:title="@string/pref_keep_foreground_service" android:summary="@string/pref_keep_foreground_service_summary" /> +