Skip to content

Commit

Permalink
Merge pull request #1014 from marci4/Issue1011
Browse files Browse the repository at this point in the history
  • Loading branch information
marci4 authored May 10, 2020
2 parents c207fb8 + 877ad76 commit 7c07eb7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/java_websocket/client/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 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");
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/java_websocket/issues/Issue997Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 7c07eb7

Please sign in to comment.