Commit 10bac8fd authored by Grigory Fedorov's avatar Grigory Fedorov

Slack: not final solution for certificate problems. @ge0rg...

Slack: not final solution for certificate problems. @ge0rg /MemorizingTrustManager library added as submodule. #502
parent e28e5d01
[submodule "app/otr4j"] [submodule "app/otr4j"]
path = app/otr4j path = app/otr4j
url = https://github.com/otr4j/otr4j.git url = https://github.com/otr4j/otr4j.git
[submodule "app/MemorizingTrustManager"]
path = app/MemorizingTrustManager
url = https://github.com/ge0rg/MemorizingTrustManager.git
Subproject commit 8b80fb176542fa96c1028c379be8de7e32c730df
...@@ -56,4 +56,5 @@ dependencies { ...@@ -56,4 +56,5 @@ dependencies {
compile "org.igniterealtime.smack:smack-experimental:4.1.2" compile "org.igniterealtime.smack:smack-experimental:4.1.2"
compile "org.igniterealtime.smack:smack-tcp:4.1.2" compile "org.igniterealtime.smack:smack-tcp:4.1.2"
compile project('otr4j') compile project('otr4j')
compile project('MemorizingTrustManager')
} }
...@@ -415,5 +415,9 @@ ...@@ -415,5 +415,9 @@
<receiver android:name="com.xabber.android.receiver.GoAwayReceiver" /> <receiver android:name="com.xabber.android.receiver.GoAwayReceiver" />
<receiver android:name="com.xabber.android.receiver.GoXaReceiver" /> <receiver android:name="com.xabber.android.receiver.GoXaReceiver" />
<receiver android:name="com.xabber.android.receiver.ComposingPausedReceiver" /> <receiver android:name="com.xabber.android.receiver.ComposingPausedReceiver" />
<activity
android:name="de.duenndns.ssl.MemorizingActivity"
/>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -41,6 +41,8 @@ import org.xbill.DNS.Record; ...@@ -41,6 +41,8 @@ import org.xbill.DNS.Record;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -48,7 +50,11 @@ import java.util.concurrent.ThreadFactory; ...@@ -48,7 +50,11 @@ import java.util.concurrent.ThreadFactory;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import javax.net.ssl.X509TrustManager;
import de.duenndns.ssl.MemorizingTrustManager;
/** /**
* Provides connection workflow. * Provides connection workflow.
...@@ -348,6 +354,19 @@ public class ConnectionThread implements ...@@ -348,6 +354,19 @@ public class ConnectionThread implements
builder.setSecurityMode(tlsMode.getSecurityMode()); builder.setSecurityMode(tlsMode.getSecurityMode());
builder.setCompressionEnabled(compression); builder.setCompressionEnabled(compression);
{
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
MemorizingTrustManager mtm = new MemorizingTrustManager(Application.getInstance());
sslContext.init(null, new X509TrustManager[]{mtm}, new java.security.SecureRandom());
builder.setCustomSSLContext(sslContext);
builder.setHostnameVerifier(
mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier()));
} catch (NoSuchAlgorithmException | KeyManagementException e) {
e.printStackTrace();
}
}
xmppConnection = new XMPPTCPConnection(builder.build()); xmppConnection = new XMPPTCPConnection(builder.build());
xmppConnection.addAsyncStanzaListener(this, ACCEPT_ALL); xmppConnection.addAsyncStanzaListener(this, ACCEPT_ALL);
xmppConnection.addConnectionListener(this); xmppConnection.addConnectionListener(this);
......
include ':app' include ':app'
include ':app:otr4j' include ':app:otr4j'
include ':app:MemorizingTrustManager'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment