Skip to content
Florian Schmaus edited this page Nov 23, 2013 · 3 revisions

How can I integrate MTM into my project?

It consists of three easy steps:

1. Add the directory path of MTM to your default.properties:

...
android.library.reference.1=../MemorizingTrustManager

2. Add the MTM activity into the application part of your AndroidManifest.xml:

                ...
                <activity android:name="de.duenndns.ssl.MemorizingActivity" />
        </application>
</manifest>

3. Hook MemorizingTrustManager as the default TrustManager for your connection type:

Hooking MemorizingTrustmanager in HTTPS connections:

// register MemorizingTrustManager for HTTPS
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, MemorizingTrustManager.getInstanceList(this), new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

Or, for aSmack you can use setCustomSSLContext()

org.jivesoftware.smack.ConnectionConfiguration connectionConfiguration = …
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, MemorizingTrustManager.getInstanceList(application), new java.security.SecureRandom());
connectionConfiguration.setCustomSSLContext(sc);