Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ private void createLdapContext() throws NamingException {
sslSocketFactory = provider.getSSLSocketFactory();
}

// Wrap factory to ensure SNI hostname is set for endpoint verification
if (sslSocketFactory != null) {
sslSocketFactory = new SNIAwareSSLSocketFactory(sslSocketFactory);
}

tlsResponse = startTLS(ldapContext, sslSocketFactory);

// Exception should be already thrown by LDAPContextManager.startTLS if "startTLS" could not be established, but rather do some additional check
Expand Down Expand Up @@ -292,6 +297,71 @@ public static Hashtable<Object, Object> getNonAuthConnectionProperties(LDAPConfi
return new Hashtable<>(env);
}

private static class SNIAwareSSLSocketFactory extends javax.net.ssl.SSLSocketFactory {
private final javax.net.ssl.SSLSocketFactory delegate;

SNIAwareSSLSocketFactory(javax.net.ssl.SSLSocketFactory delegate) {
this.delegate = delegate;
}

@Override
public String[] getDefaultCipherSuites() {
return delegate.getDefaultCipherSuites();
}

@Override
public String[] getSupportedCipherSuites() {
return delegate.getSupportedCipherSuites();
}

@Override
public java.net.Socket createSocket(java.net.Socket socket, String host, int port, boolean autoClose) throws java.io.IOException {
return setSNI(delegate.createSocket(socket, host, port, autoClose), host);
}

@Override
public java.net.Socket createSocket(String host, int port) throws java.io.IOException {
return setSNI(delegate.createSocket(host, port), host);
}

@Override
public java.net.Socket createSocket(String host, int port, java.net.InetAddress localHost, int localPort) throws java.io.IOException {
return setSNI(delegate.createSocket(host, port, localHost, localPort), host);
}

@Override
public java.net.Socket createSocket(java.net.InetAddress address, int port) throws java.io.IOException {
return delegate.createSocket(address, port);
}

@Override
public java.net.Socket createSocket(java.net.InetAddress address, int port, java.net.InetAddress localAddress, int localPort) throws java.io.IOException {
return delegate.createSocket(address, port, localAddress, localPort);
}

@Override
public java.net.Socket createSocket() throws java.io.IOException {
return delegate.createSocket();
}

private static java.net.Socket setSNI(java.net.Socket socket, String hostname) {
if (hostname != null && socket instanceof javax.net.ssl.SSLSocket) {
try {
javax.net.ssl.SSLSocket sslSocket = (javax.net.ssl.SSLSocket) socket;
javax.net.ssl.SSLParameters params = sslSocket.getSSLParameters();
if (params == null) {
params = new javax.net.ssl.SSLParameters();
}
params.setServerNames(java.util.Collections.singletonList(new javax.net.ssl.SNIHostName(hostname)));
sslSocket.setSSLParameters(params);
} catch (Exception e) {
logger.debugf("Failed to set SNI hostname '%s' for LDAP TLS: %s", hostname, e.getMessage());
}
}
return socket;
}
}

@Override
public void close() {
if (tlsResponse != null) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<jboss.dmr.version>1.5.1.Final</jboss.dmr.version>

<bouncycastle.pkixfips.version>2.1.10</bouncycastle.pkixfips.version>
<bouncycastle.bcfips.version>2.1.2</bouncycastle.bcfips.version>
<bouncycastle.bcfips.version>2.1.3</bouncycastle.bcfips.version>
<bouncycastle.bctls-fips.version>2.1.22</bouncycastle.bctls-fips.version>
<bouncycastle.bcutilfips.version>2.1.5</bouncycastle.bcutilfips.version>

Expand Down
Loading