Skip to content

Commit 7c07eb7

Browse files
authored
Merge pull request #1014 from marci4/Issue1011
2 parents c207fb8 + 877ad76 commit 7c07eb7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,6 @@ public void run() {
472472
if (socket instanceof SSLSocket) {
473473
SSLSocket sslSocket = (SSLSocket)socket;
474474
SSLParameters sslParameters = sslSocket.getSSLParameters();
475-
// Make sure we perform hostname validation
476-
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
477475
onSetSSLParameters(sslParameters);
478476
sslSocket.setSSLParameters(sslParameters);
479477
}
@@ -520,10 +518,14 @@ public void run() {
520518

521519
/**
522520
* Apply specific SSLParameters
521+
* If you override this method make sure to always call super.onSetSSLParameters() to ensure the hostname validation is active
523522
*
524523
* @param sslParameters the SSLParameters which will be used for the SSLSocket
525524
*/
526525
protected void onSetSSLParameters(SSLParameters sslParameters) {
526+
// If you run into problem on Android (NoSuchMethodException), check out the wiki https://github.com/TooTallNate/Java-WebSocket/wiki/No-such-method-error-setEndpointIdentificationAlgorithm
527+
// Perform hostname validation
528+
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
527529
}
528530

529531
/**

src/test/java/org/java_websocket/issues/Issue997Test.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public void onError(Exception ex) {
143143

144144
@Override
145145
protected void onSetSSLParameters(SSLParameters sslParameters) {
146+
// Always call super to ensure hostname validation is active by default
147+
super.onSetSSLParameters(sslParameters);
146148
if (endpointIdentificationAlgorithm != null) {
147149
sslParameters.setEndpointIdentificationAlgorithm(endpointIdentificationAlgorithm);
148150
}

0 commit comments

Comments
 (0)