34
34
35
35
import javax .net .ssl .HttpsURLConnection ;
36
36
import javax .net .ssl .SSLContext ;
37
+ import javax .net .ssl .SSLParameters ;
38
+ import javax .net .ssl .SSLSocket ;
37
39
import javax .net .ssl .TrustManager ;
38
40
import javax .net .ssl .X509TrustManager ;
39
41
@@ -196,12 +198,27 @@ public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
196
198
197
199
@ Override
198
200
public Socket createSocket (Socket socket , String host , int port , boolean autoClose ) throws IOException {
199
- return sslContext .getSocketFactory ().createSocket (socket , host , port , autoClose );
201
+ Socket localSocket = sslContext .getSocketFactory ().createSocket (socket , host , port , autoClose );
202
+ enableSecureProtocols (localSocket );
203
+ return localSocket ;
200
204
}
201
205
202
206
@ Override
203
207
public Socket createSocket () throws IOException {
204
- return sslContext .getSocketFactory ().createSocket ();
208
+ Socket socket = sslContext .getSocketFactory ().createSocket ();
209
+ enableSecureProtocols (socket );
210
+ return socket ;
211
+ }
212
+
213
+ /**
214
+ * Activate supported protocols on the socket.
215
+ *
216
+ * @param socket The socket on which to activate secure protocols.
217
+ */
218
+ private void enableSecureProtocols (Socket socket ) {
219
+ // set all supported protocols
220
+ SSLParameters params = sslContext .getSupportedSSLParameters ();
221
+ ((SSLSocket ) socket ).setEnabledProtocols (params .getProtocols ());
205
222
}
206
223
207
224
/**
@@ -210,5 +227,4 @@ public Socket createSocket() throws IOException {
210
227
public void fixHttpsURLConnection () {
211
228
HttpsURLConnection .setDefaultSSLSocketFactory (sslContext .getSocketFactory ());
212
229
}
213
-
214
- }
230
+ }
0 commit comments