diff --git a/libs/MemorizingTrustManager b/libs/MemorizingTrustManager deleted file mode 160000 index fad83503..00000000 --- a/libs/MemorizingTrustManager +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fad835037adc1bd313bb56b694426fca4eb67346 diff --git a/libs/MemorizingTrustManager/.gitignore b/libs/MemorizingTrustManager/.gitignore new file mode 100644 index 00000000..c642de10 --- /dev/null +++ b/libs/MemorizingTrustManager/.gitignore @@ -0,0 +1,11 @@ +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 new file mode 100644 index 00000000..c125afe4 --- /dev/null +++ b/libs/MemorizingTrustManager/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/libs/MemorizingTrustManager/LICENSE.txt b/libs/MemorizingTrustManager/LICENSE.txt new file mode 100644 index 00000000..25012507 --- /dev/null +++ b/libs/MemorizingTrustManager/LICENSE.txt @@ -0,0 +1,21 @@ +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 new file mode 100644 index 00000000..c48f38de --- /dev/null +++ b/libs/MemorizingTrustManager/README.mdwn @@ -0,0 +1,125 @@ +# 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 new file mode 100644 index 00000000..ee52d86d --- /dev/null +++ b/libs/MemorizingTrustManager/ant.properties @@ -0,0 +1,17 @@ +# 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 new file mode 100644 index 00000000..aa022a93 --- /dev/null +++ b/libs/MemorizingTrustManager/build.gradle @@ -0,0 +1,32 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:0.7.+' + } +} + +apply plugin: 'android-library' + +android { + compileSdkVersion 19 + buildToolsVersion "19.1" + defaultConfig { + minSdkVersion 7 + targetSdkVersion 19 + } + + 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 new file mode 100644 index 00000000..06cf485c --- /dev/null +++ b/libs/MemorizingTrustManager/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/MemorizingTrustManager/example/AndroidManifest.xml b/libs/MemorizingTrustManager/example/AndroidManifest.xml new file mode 100644 index 00000000..cdc0450b --- /dev/null +++ b/libs/MemorizingTrustManager/example/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/libs/MemorizingTrustManager/example/ant.properties b/libs/MemorizingTrustManager/example/ant.properties new file mode 100644 index 00000000..27fcaadd --- /dev/null +++ b/libs/MemorizingTrustManager/example/ant.properties @@ -0,0 +1,18 @@ +# 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 new file mode 100644 index 00000000..00bfe99e --- /dev/null +++ b/libs/MemorizingTrustManager/example/build.gradle @@ -0,0 +1,23 @@ +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 new file mode 100644 index 00000000..cdc74917 --- /dev/null +++ b/libs/MemorizingTrustManager/example/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/MemorizingTrustManager/example/proguard-project.txt b/libs/MemorizingTrustManager/example/proguard-project.txt new file mode 100644 index 00000000..f2fe1559 --- /dev/null +++ b/libs/MemorizingTrustManager/example/proguard-project.txt @@ -0,0 +1,20 @@ +# 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 new file mode 100644 index 00000000..3692949f --- /dev/null +++ b/libs/MemorizingTrustManager/example/project.properties @@ -0,0 +1,12 @@ +# 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 new file mode 100644 index 00000000..dfef58b6 --- /dev/null +++ b/libs/MemorizingTrustManager/example/res/layout/mtmexample.xml @@ -0,0 +1,36 @@ + + + +