use of javax.net.ssl.SNIServerName in project netty by netty.
the class Java8SslParametersUtils method getSniHostNames.
static List<String> getSniHostNames(SSLParameters sslParameters) {
List<SNIServerName> names = sslParameters.getServerNames();
if (names == null || names.isEmpty()) {
return Collections.emptyList();
}
List<String> strings = new ArrayList<String>(names.size());
for (SNIServerName serverName : names) {
if (serverName instanceof SNIHostName) {
strings.add(((SNIHostName) serverName).getAsciiName());
} else {
throw new IllegalArgumentException("Only " + SNIHostName.class.getName() + " instances are supported, but found: " + serverName);
}
}
return strings;
}
use of javax.net.ssl.SNIServerName in project netty by netty.
the class Java8SslParametersUtils method setSniHostNames.
static void setSniHostNames(SSLParameters sslParameters, List<String> names) {
List<SNIServerName> sniServerNames = new ArrayList<SNIServerName>(names.size());
for (String name : names) {
sniServerNames.add(new SNIHostName(name));
}
sslParameters.setServerNames(sniServerNames);
}
use of javax.net.ssl.SNIServerName in project netty by netty.
the class Java8SslUtils method setSNIMatcher.
static void setSNIMatcher(SSLParameters parameters) {
SNIMatcher matcher = new SNIMatcher(0) {
@Override
public boolean matches(SNIServerName sniServerName) {
return false;
}
};
parameters.setSNIMatchers(Collections.singleton(matcher));
}
use of javax.net.ssl.SNIServerName in project jetty.project by eclipse.
the class SniSslConnectionFactoryTest 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();
try (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));
}
String response = "GET /ctx/path HTTP/1.0\r\nHost: " + reqHost + ":" + _port + "\r\n\r\n";
sslSocket.getOutputStream().write(response.getBytes(StandardCharsets.ISO_8859_1));
return IO.toString(sslSocket.getInputStream());
} finally {
clientContextFactory.stop();
}
}
use of javax.net.ssl.SNIServerName in project jdk8u_jdk by JetBrains.
the class ServerNameExtension method send.
@Override
void send(HandshakeOutStream s) throws IOException {
s.putInt16(type.id);
if (listLength == 0) {
// in ServerHello, empty extension_data
s.putInt16(listLength);
} else {
// length of extension_data
s.putInt16(listLength + 2);
// length of ServerNameList
s.putInt16(listLength);
for (SNIServerName sniName : sniMap.values()) {
// server name type
s.putInt8(sniName.getType());
// server name value
s.putBytes16(sniName.getEncoded());
}
}
}
Aggregations