Search in sources :

Example 16 with SSLServerSocketFactory

use of javax.net.ssl.SSLServerSocketFactory in project nanohttpd by NanoHttpd.

the class NanoHTTPD method makeSSLSocketFactory.

/**
     * Creates an SSLSocketFactory for HTTPS. Pass a loaded KeyStore and an
     * array of loaded KeyManagers. These objects must properly
     * loaded/initialized by the caller.
     */
public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManager[] keyManagers) throws IOException {
    SSLServerSocketFactory res = null;
    try {
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(loadedKeyStore);
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
        res = ctx.getServerSocketFactory();
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }
    return res;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 17 with SSLServerSocketFactory

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

the class ConsoleProxySecureServerFactoryImpl method createSSLServerSocket.

@Override
public SSLServerSocket createSSLServerSocket(int port) throws IOException {
    try {
        SSLServerSocket srvSock = null;
        SSLServerSocketFactory ssf = sslContext.getServerSocketFactory();
        srvSock = (SSLServerSocket) ssf.createServerSocket(port);
        srvSock.setEnabledProtocols(SSLUtils.getSupportedProtocols(srvSock.getEnabledProtocols()));
        s_logger.info("create SSL server socket on port: " + port);
        return srvSock;
    } catch (Exception ioe) {
        s_logger.error(ioe.toString(), ioe);
    }
    return null;
}
Also used : SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLServerSocket(javax.net.ssl.SSLServerSocket) IOException(java.io.IOException)

Example 18 with SSLServerSocketFactory

use of javax.net.ssl.SSLServerSocketFactory 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 19 with SSLServerSocketFactory

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

the class Timeout method main.

public static void main(String[] args) throws Exception {
    //        try {
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket();
    String[] protocols = ss.getSupportedProtocols();
    for (int i = 0; i < protocols.length; i++) {
        //                try {
        if (protocols[i].equals("SSLv2Hello")) {
            continue;
        }
        SSLContext sslc = SSLContext.getInstance(protocols[i]);
        SSLSessionContext sslsc = sslc.getServerSessionContext();
        System.out.println("Protocol: " + protocols[i]);
        sslsc.setSessionTimeout(Integer.MAX_VALUE);
        int newtime = sslsc.getSessionTimeout();
        if (newtime != Integer.MAX_VALUE) {
            throw new Exception("Expected timeout: " + Integer.MAX_VALUE + ", got instead: " + newtime);
        }
    //                } catch (Exception e) {
    //                }
    }
    //        } catch (Exception e) {
    //            System.out.println(e);
    //        }
    System.out.println("Finished");
}
Also used : SSLSessionContext(javax.net.ssl.SSLSessionContext) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLContext(javax.net.ssl.SSLContext) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 20 with SSLServerSocketFactory

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

the class PrintSSL method main.

public static void main(String[] args) throws Exception {
    System.setProperty("javax.net.ssl.keyStorePassword", "passphrase");
    System.setProperty("javax.net.ssl.keyStore", System.getProperty("test.src", "./") + "/../../ssl/etc/keystore");
    SSLServerSocketFactory sslssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    final ServerSocket server = sslssf.createServerSocket(0);
    System.out.println(server.getLocalPort());
    System.out.flush();
    Thread t = new Thread() {

        public void run() {
            try {
                Thread.sleep(30000);
                server.close();
            } catch (Exception e) {
                ;
            }
            throw new RuntimeException("Timeout");
        }
    };
    t.setDaemon(true);
    t.start();
    ((SSLSocket) server.accept()).startHandshake();
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) ServerSocket(java.net.ServerSocket)

Aggregations

SSLServerSocketFactory (javax.net.ssl.SSLServerSocketFactory)22 SSLServerSocket (javax.net.ssl.SSLServerSocket)13 SSLContext (javax.net.ssl.SSLContext)10 IOException (java.io.IOException)7 ServerSocket (java.net.ServerSocket)4 KeyStore (java.security.KeyStore)4 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)4 SSLSocket (javax.net.ssl.SSLSocket)3 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)3 InetAddress (java.net.InetAddress)2 SSLSessionContext (javax.net.ssl.SSLSessionContext)2 ObjectID (iaik.asn1.ObjectID)1 AlgorithmID (iaik.asn1.structures.AlgorithmID)1 Name (iaik.asn1.structures.Name)1 X509Certificate (iaik.x509.X509Certificate)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1