Skip to content

Commit

Permalink
use TLSv1.2 as SSL context on supported plattforms
Browse files Browse the repository at this point in the history
  • Loading branch information
iNPUTmice committed Feb 3, 2016
1 parent 1d572c6 commit 7dd9545
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Expand Up @@ -23,6 +23,7 @@
import eu.siacs.conversations.services.AbstractConnectionManager;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.SSLSocketHelper;

public class HttpConnectionManager extends AbstractConnectionManager {

Expand Down Expand Up @@ -76,7 +77,7 @@ public void setupTrustManager(final HttpsURLConnection connection, final boolean
new StrictHostnameVerifier());
}
try {
final SSLContext sc = SSLContext.getInstance("TLS");
final SSLContext sc = SSLSocketHelper.getSSLContext();
sc.init(null, new X509TrustManager[]{trustManager},
mXmppConnectionService.getRNG());

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/eu/siacs/conversations/utils/SSLSocketHelper.java
@@ -1,11 +1,14 @@
package eu.siacs.conversations.utils;

import android.os.Build;

import java.lang.reflect.Method;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

Expand Down Expand Up @@ -59,4 +62,12 @@ public static void setAlpnProtocol(final SSLSocketFactory factory, final SSLSock
// ignore any error, we just can't set the alpn protocol...
}
}

public static SSLContext getSSLContext() throws NoSuchAlgorithmException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return SSLContext.getInstance("TLSv1.2");
} else {
return SSLContext.getInstance("TLS");
}
}
}
Expand Up @@ -408,7 +408,7 @@ public TlsFactoryVerifier(final SSLSocketFactory factory, final HostnameVerifier
}

private TlsFactoryVerifier getTlsFactoryVerifier() throws NoSuchAlgorithmException, KeyManagementException, IOException {
final SSLContext sc = SSLContext.getInstance("TLS");
final SSLContext sc = SSLSocketHelper.getSSLContext();
MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager();
KeyManager[] keyManager;
if (account.getPrivateKeyAlias() != null && account.getPassword().isEmpty()) {
Expand Down

0 comments on commit 7dd9545

Please sign in to comment.