Skip to content

Commit 304a1f5

Browse files
committed
Normalize SSL domain name from hostname when it's a FQDM, close AsyncHttpClient#1505
Motivation: When hostname is a FQDN, AHC crashes when performing TLS handshake. Modification: Remove the trailing dot when configuring the SNI/hostname verification hostname. Result: Handshake successful with FQDN
1 parent f8b28f5 commit 304a1f5

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

client/src/main/java/org/asynchttpclient/netty/ssl/DefaultSslEngineFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private SslContext buildSslContext(AsyncHttpClientConfig config) throws SSLExcep
5858
@Override
5959
public SSLEngine newSslEngine(AsyncHttpClientConfig config, String peerHost, int peerPort) {
6060
// FIXME should be using ctx allocator
61-
SSLEngine sslEngine = sslContext.newEngine(ByteBufAllocator.DEFAULT, peerHost, peerPort);
61+
SSLEngine sslEngine = sslContext.newEngine(ByteBufAllocator.DEFAULT, domain(peerHost), peerPort);
6262
configureSslEngine(sslEngine, config);
6363
return sslEngine;
6464
}

client/src/main/java/org/asynchttpclient/netty/ssl/JsseSslEngineFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public JsseSslEngineFactory(SSLContext sslContext) {
2828

2929
@Override
3030
public SSLEngine newSslEngine(AsyncHttpClientConfig config, String peerHost, int peerPort) {
31-
SSLEngine sslEngine = sslContext.createSSLEngine(peerHost, peerPort);
31+
SSLEngine sslEngine = sslContext.createSSLEngine(domain(peerHost), peerPort);
3232
configureSslEngine(sslEngine, config);
3333
return sslEngine;
3434
}

client/src/main/java/org/asynchttpclient/netty/ssl/SslEngineFactoryBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121

2222
public abstract class SslEngineFactoryBase implements SslEngineFactory {
2323

24+
protected String domain(String hostname) {
25+
int fqdnLength = hostname.length() - 1;
26+
return hostname.charAt(fqdnLength) == '.' ?
27+
hostname.substring(0, fqdnLength) :
28+
hostname;
29+
}
30+
2431
protected void configureSslEngine(SSLEngine sslEngine, AsyncHttpClientConfig config) {
2532
sslEngine.setUseClientMode(true);
2633
if (!config.isDisableHttpsEndpointIdentificationAlgorithm()) {

0 commit comments

Comments
 (0)