Search in sources :

Example 1 with SNIServerName

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;
}
Also used : SNIServerName(javax.net.ssl.SNIServerName) SNIHostName(javax.net.ssl.SNIHostName) ArrayList(java.util.ArrayList)

Example 2 with SNIServerName

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);
}
Also used : SNIServerName(javax.net.ssl.SNIServerName) SNIHostName(javax.net.ssl.SNIHostName) ArrayList(java.util.ArrayList)

Example 3 with SNIServerName

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));
}
Also used : SNIServerName(javax.net.ssl.SNIServerName) SNIMatcher(javax.net.ssl.SNIMatcher)

Example 4 with SNIServerName

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();
    }
}
Also used : SNIServerName(javax.net.ssl.SNIServerName) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SSLParameters(javax.net.ssl.SSLParameters) SNIHostName(javax.net.ssl.SNIHostName) SSLSocket(javax.net.ssl.SSLSocket) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) X509Certificate(java.security.cert.X509Certificate)

Example 5 with SNIServerName

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());
        }
    }
}
Also used : SNIServerName(javax.net.ssl.SNIServerName)

Aggregations

SNIServerName (javax.net.ssl.SNIServerName)8 SNIHostName (javax.net.ssl.SNIHostName)6 ArrayList (java.util.ArrayList)5 SSLParameters (javax.net.ssl.SSLParameters)3 SSLSocket (javax.net.ssl.SSLSocket)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 X509Certificate (java.security.cert.X509Certificate)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 SNIMatcher (javax.net.ssl.SNIMatcher)1 SSLContext (javax.net.ssl.SSLContext)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1