Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SNI TLS Extension when trying to connect to the test object #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -33,16 +33,14 @@
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import java.util.List;
import javax.net.ssl.*;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
import org.bouncycastle.tls.TlsFatalAlertReceived;
import org.apache.commons.lang3.StringUtils;

@Builder
@Slf4j
Expand Down Expand Up @@ -140,6 +138,15 @@ private void tlsConnect(
clientSSLSocket.setSSLParameters(sslParameters);
clientSSLSocket.setEnabledProtocols(tlsSettings.getEnabledProtocols());

// Keep in mind java.net.InetAddress.getHostName() will try a DNS lookup if an IP was configured! //
// Could this be an issue? / Do we need some on/off switch maybe?
String hostName = serverAddress.getHostName();
if (StringUtils.isNotBlank(hostName) && !serverAddress.isLoopbackAddress()){
log.info("Try to connect with S(erver)N(ame)I(ndication): \"{}\"", hostName);
SNIHostName sniHostName = new SNIHostName(hostName);
sslParameters.setServerNames(List.of(sniHostName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be placed before line 138, shouldn't it?

}

clientSSLSocket.setUseClientMode(true);
clientSSLSocket.addHandshakeCompletedListener(new TlsHandshakeCompletedListener());
log.info(
Expand Down