Skip to content

Commit 402a2e8

Browse files
authored
Fix SNI not being set on SSLSocket when using connect timeout (#781)
* Fix SNI not being set on SSLSocket when using connect timeout Under BCJSSE (Bouncy Castle JSSE provider), creating an unconnected SSLSocket via createSocket() and then calling connect(InetSocketAddress) does not automatically propagate the hostname for SNI. This causes TLS handshake failures against endpoints that require SNI for certificate selection (e.g. AWS OpenSearch managed domains behind load balancers). The fix explicitly sets SNI server names via SSLParameters before connecting, which works correctly with both SunJSSE and BCJSSE. Closes #765 Signed-off-by: Sotaro Hikita <bering1814@gmail.com> * Add CHANGELOG entry Signed-off-by: Sotaro Hikita <bering1814@gmail.com> --------- Signed-off-by: Sotaro Hikita <bering1814@gmail.com>
1 parent bf3f425 commit 402a2e8

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4444
- Fixed RowSerializationEventConverterTest for Spark 3.4+ StructType.toString() format change ([#702](https://github.com/opensearch-project/opensearch-hadoop/pull/702))
4545
- Fixed object fields with `enabled: false` returning empty structs or throwing exceptions when read via the connector ([#715](https://github.com/opensearch-project/opensearch-hadoop/pull/715))
4646
- Fixed SigV4 signing failure on bulk retry after partial success causing `x-amz-content-sha256 invalid` ([#759](https://github.com/opensearch-project/opensearch-hadoop/pull/759))
47+
- Fixed SNI not being set on SSLSocket when using connect timeout, causing TLS handshake failures under BCJSSE ([#781](https://github.com/opensearch-project/opensearch-hadoop/pull/781))
4748

4849
### Security
4950

mr/src/main/java/org/opensearch/hadoop/rest/commonshttp/SSLSocketFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@
4141
import java.security.cert.CertificateException;
4242
import java.security.cert.X509Certificate;
4343

44+
import java.util.Collections;
45+
4446
import javax.net.SocketFactory;
4547
import javax.net.ssl.KeyManager;
4648
import javax.net.ssl.KeyManagerFactory;
49+
import javax.net.ssl.SNIHostName;
4750
import javax.net.ssl.SSLContext;
51+
import javax.net.ssl.SSLParameters;
52+
import javax.net.ssl.SSLSocket;
4853
import javax.net.ssl.TrustManager;
4954
import javax.net.ssl.TrustManagerFactory;
5055
import javax.net.ssl.X509TrustManager;
@@ -142,6 +147,12 @@ public Socket createSocket(String host, int port, InetAddress localAddress, int
142147
}
143148
else {
144149
Socket socket = socketfactory.createSocket();
150+
if (socket instanceof SSLSocket) {
151+
SSLSocket sslSocket = (SSLSocket) socket;
152+
SSLParameters sslParams = sslSocket.getSSLParameters();
153+
sslParams.setServerNames(Collections.singletonList(new SNIHostName(host)));
154+
sslSocket.setSSLParameters(sslParams);
155+
}
145156
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
146157
SocketAddress remoteaddr = new InetSocketAddress(host, port);
147158
socket.bind(localaddr);

0 commit comments

Comments
 (0)