Skip to content

Commit a7477cd

Browse files
authored
Merge pull request #784 from criege/UNDERTOW-1564
[UNDERTOW-1564] Use proper peer address for proxied connections
2 parents afeca74 + 9578461 commit a7477cd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/src/main/java/io/undertow/protocols/ssl/UndertowXnioSsl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public SslConnection wrapExistingConnection(StreamConnection connection, OptionM
222222
}
223223

224224
public SslConnection wrapExistingConnection(StreamConnection connection, OptionMap optionMap, URI destinationURI) {
225-
SSLEngine sslEngine = createSSLEngine(sslContext, optionMap, (InetSocketAddress) connection.getPeerAddress(), true);
225+
SSLEngine sslEngine = createSSLEngine(sslContext, optionMap, getPeerAddress(destinationURI), true);
226226
SSLParameters sslParameters = sslEngine.getSSLParameters();
227227
if (sslParameters.getServerNames() == null || sslParameters.getServerNames().isEmpty()) {
228228
sslParameters.setServerNames(Collections.singletonList(new SNIHostName(destinationURI.getHost())));
@@ -231,6 +231,15 @@ public SslConnection wrapExistingConnection(StreamConnection connection, OptionM
231231
return new UndertowSslConnection(connection, sslEngine, bufferPool);
232232
}
233233

234+
private InetSocketAddress getPeerAddress(URI destinationURI) {
235+
String hostname = destinationURI.getHost();
236+
int port = destinationURI.getPort();
237+
if (port == -1) {
238+
port = destinationURI.getScheme().equals("wss") ? 443 : 80;
239+
}
240+
return new InetSocketAddress(hostname, port);
241+
}
242+
234243
/**
235244
* Create a new SSL engine, configured from an option map.
236245
*

0 commit comments

Comments
 (0)