From de0272fd1ac231a532bcc9fedcd5e81fb15cb209 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 16 Feb 2018 18:58:57 +0100 Subject: [PATCH] integrate trust manager into conversations --- build.gradle | 1 - libs/MemorizingTrustManager/.gitignore | 11 -- .../AndroidManifest.xml | 11 -- libs/MemorizingTrustManager/LICENSE.txt | 21 --- libs/MemorizingTrustManager/README.mdwn | 125 ------------- libs/MemorizingTrustManager/ant.properties | 17 -- libs/MemorizingTrustManager/build.gradle | 33 ---- libs/MemorizingTrustManager/build.xml | 92 ---------- .../example/AndroidManifest.xml | 29 --- .../example/ant.properties | 18 -- .../example/build.gradle | 23 --- libs/MemorizingTrustManager/example/build.xml | 92 ---------- .../example/proguard-project.txt | 20 --- .../example/project.properties | 12 -- .../example/res/layout/mtmexample.xml | 36 ---- .../example/res/values/strings.xml | 4 - .../de/duenndns/mtmexample/JULHandler.java | 169 ------------------ .../de/duenndns/mtmexample/MTMExample.java | 143 --------------- .../libs/.android_sucks | 0 .../mtm-notification.png | Bin 59399 -> 0 bytes .../MemorizingTrustManager/mtm-screenshot.png | Bin 85104 -> 0 bytes .../MemorizingTrustManager/mtm-servername.png | Bin 83611 -> 0 bytes .../proguard-project.txt | 20 --- .../MemorizingTrustManager/project.properties | 12 -- .../res/values-de/strings.xml | 17 -- .../res/values-es/strings.xml | 17 -- .../res/values-eu/strings.xml | 17 -- .../res/values-fi/strings.xml | 16 -- .../res/values-fr/strings.xml | 16 -- .../res/values-no/strings.xml | 16 -- .../res/values-v21/themes.xml | 7 - .../res/values/defaults.xml | 4 - .../res/values/strings.xml | 17 -- .../res/values/themes.xml | 7 - libs/MemorizingTrustManager/settings.gradle | 1 - settings.gradle | 2 +- src/main/AndroidManifest.xml | 5 +- .../crypto}/DomainHostnameVerifier.java | 2 +- .../crypto/XmppDomainVerifier.java | 2 - .../conversations/entities}/MTMDecision.java | 6 +- .../services}/MemorizingTrustManager.java | 15 +- .../services/XmppConnectionService.java | 1 - .../conversations/ui}/MemorizingActivity.java | 22 +-- .../conversations/ui/SettingsActivity.java | 2 +- .../conversations/xmpp/XmppConnection.java | 4 +- src/main/res/values/strings.xml | 9 + 46 files changed, 40 insertions(+), 1054 deletions(-) delete mode 100644 libs/MemorizingTrustManager/.gitignore delete mode 100644 libs/MemorizingTrustManager/AndroidManifest.xml delete mode 100644 libs/MemorizingTrustManager/LICENSE.txt delete mode 100644 libs/MemorizingTrustManager/README.mdwn delete mode 100644 libs/MemorizingTrustManager/ant.properties delete mode 100644 libs/MemorizingTrustManager/build.gradle delete mode 100644 libs/MemorizingTrustManager/build.xml delete mode 100644 libs/MemorizingTrustManager/example/AndroidManifest.xml delete mode 100644 libs/MemorizingTrustManager/example/ant.properties delete mode 100644 libs/MemorizingTrustManager/example/build.gradle delete mode 100644 libs/MemorizingTrustManager/example/build.xml delete mode 100644 libs/MemorizingTrustManager/example/proguard-project.txt delete mode 100644 libs/MemorizingTrustManager/example/project.properties delete mode 100644 libs/MemorizingTrustManager/example/res/layout/mtmexample.xml delete mode 100644 libs/MemorizingTrustManager/example/res/values/strings.xml delete mode 100644 libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/JULHandler.java delete mode 100644 libs/MemorizingTrustManager/example/src/de/duenndns/mtmexample/MTMExample.java delete mode 100644 libs/MemorizingTrustManager/libs/.android_sucks delete mode 100644 libs/MemorizingTrustManager/mtm-notification.png delete mode 100644 libs/MemorizingTrustManager/mtm-screenshot.png delete mode 100644 libs/MemorizingTrustManager/mtm-servername.png delete mode 100644 libs/MemorizingTrustManager/proguard-project.txt delete mode 100644 libs/MemorizingTrustManager/project.properties delete mode 100644 libs/MemorizingTrustManager/res/values-de/strings.xml delete mode 100644 libs/MemorizingTrustManager/res/values-es/strings.xml delete mode 100644 libs/MemorizingTrustManager/res/values-eu/strings.xml delete mode 100644 libs/MemorizingTrustManager/res/values-fi/strings.xml delete mode 100644 libs/MemorizingTrustManager/res/values-fr/strings.xml delete mode 100644 libs/MemorizingTrustManager/res/values-no/strings.xml delete mode 100644 libs/MemorizingTrustManager/res/values-v21/themes.xml delete mode 100644 libs/MemorizingTrustManager/res/values/defaults.xml delete mode 100644 libs/MemorizingTrustManager/res/values/strings.xml delete mode 100644 libs/MemorizingTrustManager/res/values/themes.xml delete mode 100644 libs/MemorizingTrustManager/settings.gradle rename {libs/MemorizingTrustManager/src/de/duenndns/ssl => src/main/java/eu/siacs/conversations/crypto}/DomainHostnameVerifier.java (84%) rename {libs/MemorizingTrustManager/src/de/duenndns/ssl => src/main/java/eu/siacs/conversations/entities}/MTMDecision.java (93%) rename {libs/MemorizingTrustManager/src/de/duenndns/ssl => src/main/java/eu/siacs/conversations/services}/MemorizingTrustManager.java (98%) rename {libs/MemorizingTrustManager/src/de/duenndns/ssl => src/main/java/eu/siacs/conversations/ui}/MemorizingActivity.java (83%) diff --git a/build.gradle b/build.gradle index a1e8d2c27..7833fc76d 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,6 @@ ext { } dependencies { - implementation project(':libs:MemorizingTrustManager') implementation project(':libs:EnhancedListView') playstoreImplementation 'com.google.android.gms:play-services-gcm:11.8.0' implementation 'org.sufficientlysecure:openpgp-api:10.0' diff --git a/libs/MemorizingTrustManager/.gitignore b/libs/MemorizingTrustManager/.gitignore deleted file mode 100644 index c642de10f..000000000 --- a/libs/MemorizingTrustManager/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -bin -build -gen -local.properties -example/bin -example/gen -tags -.project -.classpath -.gradle -.*.swp diff --git a/libs/MemorizingTrustManager/AndroidManifest.xml b/libs/MemorizingTrustManager/AndroidManifest.xml deleted file mode 100644 index c125afe42..000000000 --- a/libs/MemorizingTrustManager/AndroidManifest.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/libs/MemorizingTrustManager/LICENSE.txt b/libs/MemorizingTrustManager/LICENSE.txt deleted file mode 100644 index 25012507a..000000000 --- a/libs/MemorizingTrustManager/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT license. - -Copyright (c) 2010 Georg Lukas - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/libs/MemorizingTrustManager/README.mdwn b/libs/MemorizingTrustManager/README.mdwn deleted file mode 100644 index c48f38de3..000000000 --- a/libs/MemorizingTrustManager/README.mdwn +++ /dev/null @@ -1,125 +0,0 @@ -# MemorizingTrustManager - Private Cloud Support for Your App - -MemorizingTrustManager (MTM) is a project to enable smarter and more secure use -of SSL on Android. If it encounters an unknown SSL certificate, it asks the -user whether to accept the certificate once, permanently or to abort the -connection. This is a step in preventing man-in-the-middle attacks by blindly -accepting any invalid, self-signed and/or expired certificates. - -MTM is aimed at providing seamless integration into your Android application, -and the source code is available under the MIT license. - -## Screenshots - -![MemorizingTrustManager dialog](mtm-screenshot.png) -![MemorizingTrustManager notification](mtm-notification.png) -![MemorizingTrustManager server name dialog](mtm-servername.png) - -## Status - -MemorizingTrustManager is in production use in the -[yaxim XMPP client](https://yaxim.org/). It is usable and easy to integrate, -though it does not yet support hostname validation (the Java API makes it -**hard** to integrate). - -## Integration - -MTM is easy to integrate into your own application. Follow these steps or have -a look into the demo application in the `example` directory. - -### 1. Add MTM to your project - -Download the MTM source from GitHub, or add it as a -[git submodule](http://git-scm.com/docs/git-submodule): - - # plain download: - git clone https://github.com/ge0rg/MemorizingTrustManager - # submodule: - git submodule add https://github.com/ge0rg/MemorizingTrustManager - -Then add a library project dependency to `default.properties`: - - android.library.reference.1=MemorizingTrustManager - -### 2. Add the MTM (popup) Activity to your manifest - -Edit your `AndroidManifest.xml` and add the MTM activity element right before the -end of your closing `` tag. - - ... - - - - -### 3. Hook MTM as the default TrustManager for your connection type - -Hooking MemorizingTrustmanager in HTTPS connections: - - // register MemorizingTrustManager for HTTPS - SSLContext sc = SSLContext.getInstance("TLS"); - MemorizingTrustManager mtm = new MemorizingTrustManager(this); - sc.init(null, new X509TrustManager[] { mtm }, new java.security.SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - HttpsURLConnection.setDefaultHostnameVerifier( - mtm.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())); - - -Or, for aSmack you can use `setCustomSSLContext()`: - - org.jivesoftware.smack.ConnectionConfiguration connectionConfiguration = … - SSLContext sc = SSLContext.getInstance("TLS"); - MemorizingTrustManager mtm = new MemorizingTrustManager(this); - sc.init(null, new X509TrustManager[] { mtm }, new java.security.SecureRandom()); - connectionConfiguration.setCustomSSLContext(sc); - connectionConfiguration.setHostnameVerifier( - mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier())); - -By default, MTM falls back to the system `TrustManager` before asking the user. -If you do not trust the establishment, you can enforce a dialog on *every new -connection* by supplying a `defaultTrustManager = null` parameter to the -constructor: - - MemorizingTrustManager mtm = new MemorizingTrustManager(this, null); - -If you want to use a different underlying `TrustManager`, like -[AndroidPinning](https://github.com/moxie0/AndroidPinning), just supply that to -MTM's constructor: - - X509TrustManager pinning = new PinningTrustManager(SystemKeyStore.getInstance(), - new String[] {"f30012bbc18c231ac1a44b788e410ce754182513"}, 0); - MemorizingTrustManager mtm = new MemorizingTrustManager(this, pinning); - -### 4. Profit! - -### Logging - -MTM uses java.util.logging (JUL) for logging purposes. If you have not -configured a Handler for JUL, then Android will by default log all -messages of Level.INFO or higher. In order to get also the debug log -messages (those with Level.FINE or lower) you need to configure a -Handler accordingly. The MTM example project contains -de.duenndns.mtmexample.JULHandler, which allows to enable and disable -debug logging at runtime. - -## Alternatives - -MemorizingTrustManager is not the only one out there. - -[**NetCipher**](https://guardianproject.info/code/netcipher/) is an Android -library made by the [Guardian Project](https://guardianproject.info/) to -improve network security for mobile apps. It comes with a StrongTrustManager -to do more thorough certificate checks, an independent Root CA store, and code -to easily route your traffic through -[the Tor network](https://www.torproject.org/) using [Orbot](https://guardianproject.info/apps/orbot/). - -[**AndroidPinning**](https://github.com/moxie0/AndroidPinning) is another Android -library, written by [Moxie Marlinspike](http://www.thoughtcrime.org/) to allow -pinning of server certificates, improving security against government-scale -MitM attacks. Use this if your app is made to communicate with a specific -server! - -## Contribute - -Please [help translating MTM into more languages](https://translations.launchpad.net/yaxim/master/+pots/mtm/)! diff --git a/libs/MemorizingTrustManager/ant.properties b/libs/MemorizingTrustManager/ant.properties deleted file mode 100644 index ee52d86d9..000000000 --- a/libs/MemorizingTrustManager/ant.properties +++ /dev/null @@ -1,17 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked in Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. - diff --git a/libs/MemorizingTrustManager/build.gradle b/libs/MemorizingTrustManager/build.gradle deleted file mode 100644 index 9c56d504b..000000000 --- a/libs/MemorizingTrustManager/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -buildscript { - repositories { - google() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' - } -} - -apply plugin: 'com.android.library' - -android { - compileSdkVersion 27 - buildToolsVersion "27.0.3" - defaultConfig { - minSdkVersion 14 - targetSdkVersion 25 - } - - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - resources.srcDirs = ['src'] - aidl.srcDirs = ['src'] - renderscript.srcDirs = ['src'] - res.srcDirs = ['res'] - assets.srcDirs = ['assets'] - } - } - -} diff --git a/libs/MemorizingTrustManager/build.xml b/libs/MemorizingTrustManager/build.xml deleted file mode 100644 index 06cf485c1..000000000 --- a/libs/MemorizingTrustManager/build.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libs/MemorizingTrustManager/example/AndroidManifest.xml b/libs/MemorizingTrustManager/example/AndroidManifest.xml deleted file mode 100644 index cdc0450b3..000000000 --- a/libs/MemorizingTrustManager/example/AndroidManifest.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/libs/MemorizingTrustManager/example/ant.properties b/libs/MemorizingTrustManager/example/ant.properties deleted file mode 100644 index 27fcaadd8..000000000 --- a/libs/MemorizingTrustManager/example/ant.properties +++ /dev/null @@ -1,18 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked in Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. - -application.package=de.duenndns.mtmexample diff --git a/libs/MemorizingTrustManager/example/build.gradle b/libs/MemorizingTrustManager/example/build.gradle deleted file mode 100644 index 00bfe99e2..000000000 --- a/libs/MemorizingTrustManager/example/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -apply plugin: 'android' - -dependencies { - compile rootProject -} - -android { - compileSdkVersion 19 - buildToolsVersion "19.1" - defaultConfig { - minSdkVersion 7 - targetSdkVersion 19 - } - - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - res.srcDirs = ['res'] - } - } - -} diff --git a/libs/MemorizingTrustManager/example/build.xml b/libs/MemorizingTrustManager/example/build.xml deleted file mode 100644 index cdc74917d..000000000 --- a/libs/MemorizingTrustManager/example/build.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/libs/MemorizingTrustManager/example/proguard-project.txt b/libs/MemorizingTrustManager/example/proguard-project.txt deleted file mode 100644 index f2fe1559a..000000000 --- a/libs/MemorizingTrustManager/example/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/libs/MemorizingTrustManager/example/project.properties b/libs/MemorizingTrustManager/example/project.properties deleted file mode 100644 index 3692949fd..000000000 --- a/libs/MemorizingTrustManager/example/project.properties +++ /dev/null @@ -1,12 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system use, -# "ant.properties", and override values to adapt the script to your -# project structure. - -android.library.reference.1=../ -# Project target. -target=android-19 diff --git a/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml b/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml deleted file mode 100644 index dfef58b6c..000000000 --- a/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - -