1919
2020package org .apache .cloudstack .network .opendaylight .api ;
2121
22+ import org .apache .cloudstack .utils .security .SSLUtils ;
2223import java .io .IOException ;
2324import java .lang .reflect .Constructor ;
2425import java .lang .reflect .InvocationTargetException ;
3334import java .security .cert .X509Certificate ;
3435
3536import javax .net .ssl .SSLContext ;
37+ import javax .net .ssl .SSLSocket ;
3638import javax .net .ssl .SSLSocketFactory ;
3739import javax .net .ssl .TrustManager ;
3840import javax .net .ssl .X509TrustManager ;
@@ -175,7 +177,7 @@ public void checkServerTrusted(final X509Certificate[] certs, final String authT
175177
176178 try {
177179 // Install the all-trusting trust manager
178- SSLContext sc = SSLContext . getInstance ( "SSL" );
180+ SSLContext sc = SSLUtils . getSSLContext ( );
179181 sc .init (null , trustAllCerts , new java .security .SecureRandom ());
180182 ssf = sc .getSocketFactory ();
181183 } catch (KeyManagementException e ) {
@@ -187,17 +189,23 @@ public void checkServerTrusted(final X509Certificate[] certs, final String authT
187189
188190 @ Override
189191 public Socket createSocket (final String host , final int port ) throws IOException {
190- return ssf .createSocket (host , port );
192+ SSLSocket s = (SSLSocket ) ssf .createSocket (host , port );
193+ s .setEnabledProtocols (SSLUtils .getSupportedProtocols (s .getEnabledProtocols ()));
194+ return s ;
191195 }
192196
193197 @ Override
194198 public Socket createSocket (final String address , final int port , final InetAddress localAddress , final int localPort ) throws IOException , UnknownHostException {
195- return ssf .createSocket (address , port , localAddress , localPort );
199+ SSLSocket s = (SSLSocket ) ssf .createSocket (address , port , localAddress , localPort );
200+ s .setEnabledProtocols (SSLUtils .getSupportedProtocols (s .getEnabledProtocols ()));
201+ return s ;
196202 }
197203
198204 @ Override
199205 public Socket createSocket (final Socket socket , final String host , final int port , final boolean autoClose ) throws IOException , UnknownHostException {
200- return ssf .createSocket (socket , host , port , autoClose );
206+ SSLSocket s = (SSLSocket ) ssf .createSocket (socket , host , port , autoClose );
207+ s .setEnabledProtocols (SSLUtils .getSupportedProtocols (s .getEnabledProtocols ()));
208+ return s ;
201209 }
202210
203211 @ Override
@@ -207,7 +215,8 @@ public Socket createSocket(final String host, final int port, final InetAddress
207215 if (timeout == 0 ) {
208216 return createSocket (host , port , localAddress , localPort );
209217 } else {
210- Socket s = ssf .createSocket ();
218+ SSLSocket s = (SSLSocket ) ssf .createSocket ();
219+ s .setEnabledProtocols (SSLUtils .getSupportedProtocols (s .getEnabledProtocols ()));
211220 s .bind (new InetSocketAddress (localAddress , localPort ));
212221 s .connect (new InetSocketAddress (host , port ), timeout );
213222 return s ;
0 commit comments