use of javax.net.ssl.SNIServerName in project jetty.project by eclipse.
the class SslConnectionFactoryTest method getResponse.
private String getResponse(String sniHost, String reqHost, String cn) throws Exception {
SslContextFactory clientContextFactory = new SslContextFactory(true);
clientContextFactory.start();
SSLSocketFactory factory = clientContextFactory.getSslContext().getSocketFactory();
SSLSocket sslSocket = (SSLSocket) factory.createSocket("127.0.0.1", _port);
if (cn != null) {
SNIHostName serverName = new SNIHostName(sniHost);
List<SNIServerName> serverNames = new ArrayList<>();
serverNames.add(serverName);
SSLParameters params = sslSocket.getSSLParameters();
params.setServerNames(serverNames);
sslSocket.setSSLParameters(params);
}
sslSocket.startHandshake();
if (cn != null) {
X509Certificate cert = ((X509Certificate) sslSocket.getSession().getPeerCertificates()[0]);
Assert.assertThat(cert.getSubjectX500Principal().getName("CANONICAL"), Matchers.startsWith("cn=" + cn));
}
sslSocket.getOutputStream().write(("GET /ctx/path HTTP/1.0\r\nHost: " + reqHost + ":" + _port + "\r\n\r\n").getBytes(StandardCharsets.ISO_8859_1));
String response = IO.toString(sslSocket.getInputStream());
sslSocket.close();
clientContextFactory.stop();
return response;
}
use of javax.net.ssl.SNIServerName in project mongo-java-driver by mongodb.
the class Java8SniSslHelper method enableSni.
@Override
public void enableSni(final ServerAddress address, final SSLParameters sslParameters) {
try {
SNIServerName sniHostName = new SNIHostName(address.getHost());
sslParameters.setServerNames(singletonList(sniHostName));
} catch (IllegalArgumentException e) {
// ignore because SNIHostName will throw this for some legit host names for connecting to MongoDB, e.g an IPV6 literal
}
}
use of javax.net.ssl.SNIServerName in project jdk8u_jdk by JetBrains.
the class SSLEchoServer method init.
static SSLClient init(String host, int port, String cipherSuiteFilter, String sniHostName) throws NoSuchAlgorithmException, IOException {
SSLContext sslContext = SSLContext.getDefault();
SSLSocketFactory ssf = (SSLSocketFactory) sslContext.getSocketFactory();
SSLSocket socket = (SSLSocket) ssf.createSocket(host, port);
SSLParameters params = new SSLParameters();
if (cipherSuiteFilter != null) {
String[] cipherSuites = UnboundSSLUtils.filterStringArray(ssf.getSupportedCipherSuites(), cipherSuiteFilter);
System.out.println("Client: enabled cipher suites: " + Arrays.toString(cipherSuites));
params.setCipherSuites(cipherSuites);
}
if (sniHostName != null) {
System.out.println("Client: set SNI hostname: " + sniHostName);
SNIHostName serverName = new SNIHostName(sniHostName);
List<SNIServerName> serverNames = new ArrayList<>();
serverNames.add(serverName);
params.setServerNames(serverNames);
}
socket.setSSLParameters(params);
return new SSLClient(socket);
}
Aggregations