Search in sources :

Example 1 with SSLServerSocketFactory

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

the class LoadKeyStoreTest method loadKeyStoreFromResources.

@Test
public void loadKeyStoreFromResources() throws Exception {
    String keyStorePath = "/keystore.jks";
    InputStream resourceAsStream = this.getClass().getResourceAsStream(keyStorePath);
    assertNotNull(resourceAsStream);
    SSLServerSocketFactory sslServerSocketFactory = NanoHTTPD.makeSSLSocketFactory(keyStorePath, "password".toCharArray());
    assertNotNull(sslServerSocketFactory);
}
Also used : InputStream(java.io.InputStream) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) Test(org.junit.Test)

Example 2 with SSLServerSocketFactory

use of javax.net.ssl.SSLServerSocketFactory in project apjp by jvansteirteghem.

the class HTTPS method createSSLServerSocket.

public static synchronized SSLServerSocket createSSLServerSocket() throws HTTPSException {
    try {
        KeyStore defaultKeyStore = getDefaultKeyStore();
        SSLContext sslContext = SSLContext.getInstance("TLS");
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(defaultKeyStore, "APJP".toCharArray());
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(defaultKeyStore);
        sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
        SSLServerSocketFactory sslServerSocketFactory = (SSLServerSocketFactory) sslContext.getServerSocketFactory();
        return (SSLServerSocket) sslServerSocketFactory.createServerSocket();
    } catch (Exception e) {
        logger.log(2, "HTTPS/CREATE_SSL_SERVER_SOCKET: EXCEPTION", e);
        throw new HTTPSException("HTTPS/CREATE_SSL_SERVER_SOCKET", e);
    }
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLContext(javax.net.ssl.SSLContext) SSLServerSocket(javax.net.ssl.SSLServerSocket) KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 3 with SSLServerSocketFactory

use of javax.net.ssl.SSLServerSocketFactory in project robovm by robovm.

the class SSLContextSpiTest method test_commonTest_01.

/**
     * SSLContextSpi#engineGetClientSessionContext()
     * SSLContextSpi#engineGetServerSessionContext()
     * SSLContextSpi#engineGetServerSocketFactory()
     * SSLContextSpi#engineGetSocketFactory()
     * Verify exception when SSLContextSpi object wasn't initialiazed.
     */
public void test_commonTest_01() {
    SSLContextSpiImpl ssl = new SSLContextSpiImpl();
    try {
        SSLSessionContext slsc = ssl.engineGetClientSessionContext();
        fail("RuntimeException wasn't thrown");
    } catch (RuntimeException re) {
        String str = re.getMessage();
        if (!str.equals("Not initialiazed"))
            fail("Incorrect exception message: " + str);
    } catch (Exception e) {
        fail("Incorrect exception " + e + " was thrown");
    }
    try {
        SSLSessionContext slsc = ssl.engineGetServerSessionContext();
        fail("RuntimeException wasn't thrown");
    } catch (RuntimeException re) {
        String str = re.getMessage();
        if (!str.equals("Not initialiazed"))
            fail("Incorrect exception message: " + str);
    } catch (Exception e) {
        fail("Incorrect exception " + e + " was thrown");
    }
    try {
        SSLServerSocketFactory sssf = ssl.engineGetServerSocketFactory();
        fail("RuntimeException wasn't thrown");
    } catch (RuntimeException re) {
        String str = re.getMessage();
        if (!str.equals("Not initialiazed"))
            fail("Incorrect exception message: " + str);
    } catch (Exception e) {
        fail("Incorrect exception " + e + " was thrown");
    }
    try {
        SSLSocketFactory ssf = ssl.engineGetSocketFactory();
        fail("RuntimeException wasn't thrown");
    } catch (RuntimeException re) {
        String str = re.getMessage();
        if (!str.equals("Not initialiazed"))
            fail("Incorrect exception message: " + str);
    } catch (Exception e) {
        fail("Incorrect exception " + e + " was thrown");
    }
}
Also used : SSLSessionContext(javax.net.ssl.SSLSessionContext) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SSLContextSpiImpl(org.apache.harmony.xnet.tests.support.SSLContextSpiImpl) KeyManagementException(java.security.KeyManagementException)

Example 4 with SSLServerSocketFactory

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

the class CookieHttpsClientTest method doServerSide.

/*
     * Define the server side of the test.
     *
     * If the server prematurely exits, serverReady will be set to true
     * to avoid infinite hangs.
     */
void doServerSide() throws Exception {
    SSLServerSocketFactory sslssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    SSLServerSocket sslServerSocket = (SSLServerSocket) sslssf.createServerSocket(serverPort);
    serverPort = sslServerSocket.getLocalPort();
    /*
         * Signal Client, we're ready for his connect.
         */
    serverReady = true;
    SSLSocket sslSocket = null;
    try {
        sslSocket = (SSLSocket) sslServerSocket.accept();
        sslSocket.setSoTimeout(TIMEOUT);
        readOneRequest(sslSocket.getInputStream());
        sslSocket.getOutputStream().write(replyString.getBytes());
        readOneRequest(sslSocket.getInputStream());
        sslSocket.getOutputStream().write(replyString.getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (sslSocket != null) {
                sslSocket.close();
            }
            sslServerSocket.close();
        } catch (IOException unused) {
        /* gulp!burp! */
        }
    }
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) IOException(java.io.IOException) SSLServerSocket(javax.net.ssl.SSLServerSocket) IOException(java.io.IOException)

Example 5 with SSLServerSocketFactory

use of javax.net.ssl.SSLServerSocketFactory in project zm-mailbox by Zimbra.

the class NetUtil method main.

public static void main(String[] args) {
    SSLServerSocketFactory sf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    String[] supportedCipherSuites = sf.getSupportedCipherSuites();
    System.out.println("\nsupported cipher suites:\n");
    for (String c : supportedCipherSuites) System.out.println(c);
}
Also used : SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory)

Aggregations

SSLServerSocketFactory (javax.net.ssl.SSLServerSocketFactory)19 SSLServerSocket (javax.net.ssl.SSLServerSocket)11 SSLContext (javax.net.ssl.SSLContext)9 IOException (java.io.IOException)4 KeyStore (java.security.KeyStore)4 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)4 ServerSocket (java.net.ServerSocket)3 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)3 SSLSessionContext (javax.net.ssl.SSLSessionContext)2 SSLSocket (javax.net.ssl.SSLSocket)2 ObjectID (iaik.asn1.ObjectID)1 AlgorithmID (iaik.asn1.structures.AlgorithmID)1 Name (iaik.asn1.structures.Name)1 X509Certificate (iaik.x509.X509Certificate)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1