From e6f6bcb14964520c23af291fa7c90a430b650693 Mon Sep 17 00:00:00 2001 From: marci4 Date: Sun, 10 May 2020 17:06:48 +0200 Subject: [PATCH 1/2] Move setEndpointIdentificationAlgorithm inside onSetSSLParametersof #Fixes 1011 --- .../java/org/java_websocket/client/WebSocketClient.java | 6 ++++-- src/test/java/org/java_websocket/issues/Issue997Test.java | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java index 0bbcfe54..303b6a9a 100644 --- a/src/main/java/org/java_websocket/client/WebSocketClient.java +++ b/src/main/java/org/java_websocket/client/WebSocketClient.java @@ -472,8 +472,6 @@ public void run() { if (socket instanceof SSLSocket) { SSLSocket sslSocket = (SSLSocket)socket; SSLParameters sslParameters = sslSocket.getSSLParameters(); - // Make sure we perform hostname validation - sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); onSetSSLParameters(sslParameters); sslSocket.setSSLParameters(sslParameters); } @@ -520,10 +518,14 @@ public void run() { /** * Apply specific SSLParameters + * If you override this method make sure to always call super.onSetSSLParameters() to ensure the hostname validation is active * * @param sslParameters the SSLParameters which will be used for the SSLSocket */ protected void onSetSSLParameters(SSLParameters sslParameters) { + // If you run into problem (NoSuchMethodException), check out the wiki https://github.com/TooTallNate/Java-WebSocket/wiki/No-such-method-error-'setEndpointIdentificationAlgorithm' + // Perform hostname validation + sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); } /** diff --git a/src/test/java/org/java_websocket/issues/Issue997Test.java b/src/test/java/org/java_websocket/issues/Issue997Test.java index 0fc81bc2..493dd69b 100644 --- a/src/test/java/org/java_websocket/issues/Issue997Test.java +++ b/src/test/java/org/java_websocket/issues/Issue997Test.java @@ -143,6 +143,8 @@ public void onError(Exception ex) { @Override protected void onSetSSLParameters(SSLParameters sslParameters) { + // Always call super to ensure hostname validation is active by default + super.onSetSSLParameters(sslParameters); if (endpointIdentificationAlgorithm != null) { sslParameters.setEndpointIdentificationAlgorithm(endpointIdentificationAlgorithm); } From 877ad764e5d01166d754e611a4139e816cc04d0d Mon Sep 17 00:00:00 2001 From: marci4 Date: Sun, 10 May 2020 17:13:59 +0200 Subject: [PATCH 2/2] Update WebSocketClient.java --- src/main/java/org/java_websocket/client/WebSocketClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java index 303b6a9a..4d735dee 100644 --- a/src/main/java/org/java_websocket/client/WebSocketClient.java +++ b/src/main/java/org/java_websocket/client/WebSocketClient.java @@ -523,7 +523,7 @@ public void run() { * @param sslParameters the SSLParameters which will be used for the SSLSocket */ protected void onSetSSLParameters(SSLParameters sslParameters) { - // If you run into problem (NoSuchMethodException), check out the wiki https://github.com/TooTallNate/Java-WebSocket/wiki/No-such-method-error-'setEndpointIdentificationAlgorithm' + // If you run into problem on Android (NoSuchMethodException), check out the wiki https://github.com/TooTallNate/Java-WebSocket/wiki/No-such-method-error-setEndpointIdentificationAlgorithm // Perform hostname validation sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); }