52
52
import javax .net .ssl .SSLContext ;
53
53
import javax .net .ssl .SSLEngine ;
54
54
import javax .net .ssl .SSLException ;
55
+ import javax .net .ssl .SSLParameters ;
55
56
import javax .net .ssl .TrustManagerFactory ;
56
57
import javax .websocket .ClientEndpoint ;
57
58
import javax .websocket .ClientEndpointConfig ;
@@ -328,7 +329,7 @@ private Session connectToServerRecursive(Endpoint endpoint,
328
329
// Regardless of whether a non-secure wrapper was created for a
329
330
// proxy CONNECT, need to use TLS from this point on so wrap the
330
331
// original AsynchronousSocketChannel
331
- SSLEngine sslEngine = createSSLEngine (userProperties );
332
+ SSLEngine sslEngine = createSSLEngine (userProperties , host , port );
332
333
channel = new AsyncChannelWrapperSecure (socketChannel , sslEngine );
333
334
} else if (channel == null ) {
334
335
// Only need to wrap as this point if it wasn't wrapped to process a
@@ -866,7 +867,7 @@ private String readLine(ByteBuffer response) {
866
867
}
867
868
868
869
869
- private SSLEngine createSSLEngine (Map <String ,Object > userProperties )
870
+ private SSLEngine createSSLEngine (Map <String ,Object > userProperties , String host , int port )
870
871
throws DeploymentException {
871
872
872
873
try {
@@ -904,7 +905,7 @@ private SSLEngine createSSLEngine(Map<String,Object> userProperties)
904
905
}
905
906
}
906
907
907
- SSLEngine engine = sslContext .createSSLEngine ();
908
+ SSLEngine engine = sslContext .createSSLEngine (host , port );
908
909
909
910
String sslProtocolsValue =
910
911
(String ) userProperties .get (Constants .SSL_PROTOCOLS_PROPERTY );
@@ -914,6 +915,14 @@ private SSLEngine createSSLEngine(Map<String,Object> userProperties)
914
915
915
916
engine .setUseClientMode (true );
916
917
918
+ // Enable host verification
919
+ // Start with current settings (returns a copy)
920
+ SSLParameters sslParams = engine .getSSLParameters ();
921
+ // Use HTTPS since WebSocket starts over HTTP(S)
922
+ sslParams .setEndpointIdentificationAlgorithm ("HTTPS" );
923
+ // Write the parameters back
924
+ engine .setSSLParameters (sslParams );
925
+
917
926
return engine ;
918
927
} catch (Exception e ) {
919
928
throw new DeploymentException (sm .getString (
0 commit comments