Skip to content

Commit dcbf80f

Browse files
author
XYG6
committed
FIX - MySSLSocketFactory wrong class structure
1 parent 86e5a62 commit dcbf80f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

library/src/main/java/com/loopj/android/http/MySSLSocketFactory.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@
5959
public class MySSLSocketFactory extends SSLSocketFactory {
6060
SSLContext sslContext;
6161

62-
try {
63-
sslContext = SSLContext.getInstance("TLSv1.2");
64-
Log.w("SSLSocketFactory", "TLSv1.2 is supported");
65-
} catch (NoSuchAlgorithmException e) {
66-
// TODO fallback v1.1 if needed
67-
Log.w("SSLSocketFactory", "TLSv1.2 is not supported in this device; falling through TLSv1.0");
68-
sslContext = SSLContext.getInstance("TLSv1");
69-
// should be available in any device; see reference of supported protocols in
70-
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
71-
}
72-
7362
/**
7463
* Creates a new SSL Socket Factory with the given KeyStore.
7564
*
@@ -81,6 +70,18 @@ public class MySSLSocketFactory extends SSLSocketFactory {
8170
*/
8271
public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
8372
super(truststore);
73+
74+
// Define sslContext
75+
try {
76+
sslContext = SSLContext.getInstance("TLSv1.2");
77+
Log.w("SSLSocketFactory", "TLSv1.2 is supported");
78+
} catch (NoSuchAlgorithmException e) {
79+
// TODO fallback v1.1 if needed
80+
Log.w("SSLSocketFactory", "TLSv1.2 is not supported in this device; falling through TLSv1.0");
81+
sslContext = SSLContext.getInstance("TLSv1");
82+
// should be available in any device; see reference of supported protocols in
83+
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
84+
}
8485

8586
X509TrustManager tm = new X509TrustManager() {
8687
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {

0 commit comments

Comments
 (0)