53
53
import javax .net .ssl .SSLContext ;
54
54
import javax .net .ssl .SSLEngine ;
55
55
import javax .net .ssl .SSLException ;
56
+ import javax .net .ssl .SSLParameters ;
56
57
import javax .net .ssl .TrustManagerFactory ;
57
58
import javax .websocket .ClientEndpoint ;
58
59
import javax .websocket .ClientEndpointConfig ;
@@ -369,7 +370,7 @@ private Session connectToServerRecursive(Endpoint endpoint,
369
370
// Regardless of whether a non-secure wrapper was created for a
370
371
// proxy CONNECT, need to use TLS from this point on so wrap the
371
372
// original AsynchronousSocketChannel
372
- SSLEngine sslEngine = createSSLEngine (userProperties );
373
+ SSLEngine sslEngine = createSSLEngine (userProperties , host , port );
373
374
channel = new AsyncChannelWrapperSecure (socketChannel , sslEngine );
374
375
} else if (channel == null ) {
375
376
// Only need to wrap as this point if it wasn't wrapped to process a
@@ -931,7 +932,7 @@ private String readLine(ByteBuffer response) {
931
932
}
932
933
933
934
934
- private SSLEngine createSSLEngine (Map <String ,Object > userProperties )
935
+ private SSLEngine createSSLEngine (Map <String ,Object > userProperties , String host , int port )
935
936
throws DeploymentException {
936
937
937
938
try {
@@ -979,7 +980,7 @@ private SSLEngine createSSLEngine(Map<String,Object> userProperties)
979
980
}
980
981
}
981
982
982
- SSLEngine engine = sslContext .createSSLEngine ();
983
+ SSLEngine engine = sslContext .createSSLEngine (host , port );
983
984
984
985
String sslProtocolsValue =
985
986
(String ) userProperties .get (SSL_PROTOCOLS_PROPERTY );
@@ -989,6 +990,14 @@ private SSLEngine createSSLEngine(Map<String,Object> userProperties)
989
990
990
991
engine .setUseClientMode (true );
991
992
993
+ // Enable host verification
994
+ // Start with current settings (returns a copy)
995
+ SSLParameters sslParams = engine .getSSLParameters ();
996
+ // Use HTTPS since WebSocket starts over HTTP(S)
997
+ sslParams .setEndpointIdentificationAlgorithm ("HTTPS" );
998
+ // Write the parameters back
999
+ engine .setSSLParameters (sslParams );
1000
+
992
1001
return engine ;
993
1002
} catch (Exception e ) {
994
1003
throw new DeploymentException (sm .getString (
0 commit comments