Search in sources :

Example 66 with SSLParameters

use of javax.net.ssl.SSLParameters in project jdk8u_jdk by JetBrains.

the class SSLEchoServer method init.

/*
     * Creates server instance.
     *
     * @param cipherSuiteFilter Filter for enabled cipher suites
     * @param sniMatcherPattern Pattern for SNI server hame
     */
static SSLEchoServer init(String cipherSuiteFilter, String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket = (SSLServerSocket) ssf.createServerSocket(0);
    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: " + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }
    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }
    return new SSLEchoServer(ssocket);
}
Also used : SNIMatcher(javax.net.ssl.SNIMatcher) SSLParameters(javax.net.ssl.SSLParameters) ArrayList(java.util.ArrayList) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLContext(javax.net.ssl.SSLContext) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 67 with SSLParameters

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

Example 68 with SSLParameters

use of javax.net.ssl.SSLParameters in project cloudstack by apache.

the class ConsoleProxySecureServerFactoryImpl method createHttpServerInstance.

@Override
public HttpServer createHttpServerInstance(int port) throws IOException {
    try {
        HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 5);
        server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {

            @Override
            public void configure(HttpsParameters params) {
                // get the remote address if needed
                InetSocketAddress remote = params.getClientAddress();
                SSLContext c = getSSLContext();
                // get the default parameters
                SSLParameters sslparams = c.getDefaultSSLParameters();
                params.setSSLParameters(sslparams);
            // statement above could throw IAE if any params invalid.
            // eg. if app has a UI and parameters supplied by a user.
            }
        });
        s_logger.info("create HTTPS server instance on port: " + port);
        return server;
    } catch (Exception ioe) {
        s_logger.error(ioe.toString(), ioe);
    }
    return null;
}
Also used : HttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator) SSLParameters(javax.net.ssl.SSLParameters) InetSocketAddress(java.net.InetSocketAddress) HttpsParameters(com.sun.net.httpserver.HttpsParameters) SSLContext(javax.net.ssl.SSLContext) HttpsServer(com.sun.net.httpserver.HttpsServer) IOException(java.io.IOException)

Aggregations

SSLParameters (javax.net.ssl.SSLParameters)68 Test (org.testng.annotations.Test)16 SSLSocket (javax.net.ssl.SSLSocket)15 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)14 SSLContext (javax.net.ssl.SSLContext)13 Test (org.junit.Test)10 ByteString (com.linkedin.data.ByteString)9 AsciiString (io.netty.util.AsciiString)9 SSLEngine (javax.net.ssl.SSLEngine)8 InetSocketAddress (java.net.InetSocketAddress)6 SNIHostName (javax.net.ssl.SNIHostName)6 ArrayList (java.util.ArrayList)5 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)5 HttpsConfigurator (com.sun.net.httpserver.HttpsConfigurator)4 HttpsParameters (com.sun.net.httpserver.HttpsParameters)4 IOException (java.io.IOException)4 URI (java.net.URI)4 X509Certificate (java.security.cert.X509Certificate)4 Jedis (redis.clients.jedis.Jedis)4 JedisShardInfo (redis.clients.jedis.JedisShardInfo)4