59
59
public class MySSLSocketFactory extends SSLSocketFactory {
60
60
SSLContext sslContext ;
61
61
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
-
73
62
/**
74
63
* Creates a new SSL Socket Factory with the given KeyStore.
75
64
*
@@ -81,6 +70,18 @@ public class MySSLSocketFactory extends SSLSocketFactory {
81
70
*/
82
71
public MySSLSocketFactory (KeyStore truststore ) throws NoSuchAlgorithmException , KeyManagementException , KeyStoreException , UnrecoverableKeyException {
83
72
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
+ }
84
85
85
86
X509TrustManager tm = new X509TrustManager () {
86
87
public void checkClientTrusted (X509Certificate [] chain , String authType ) throws CertificateException {
0 commit comments