Search in sources :

Example 36 with SSLServerSocket

use of javax.net.ssl.SSLServerSocket in project android by cSploit.

the class HTTPSRedirector method getSSLSocket.

private SSLServerSocket getSSLSocket() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException {
    KeyStore keyStore = KeyStore.getInstance("PKCS12");
    keyStore.load(mContext.getAssets().open(KEYSTORE_FILE), KEYSTORE_PASS.toCharArray());
    KeyManagerFactory keyMan = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyMan.init(keyStore, KEYSTORE_PASS.toCharArray());
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyMan.getKeyManagers(), null, null);
    SSLServerSocketFactory sslFactory = sslContext.getServerSocketFactory();
    return (SSLServerSocket) sslFactory.createServerSocket(mPort, BACKLOG, mAddress);
}
Also used : 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 37 with SSLServerSocket

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

the class SSLServerSocketFactoryTest method testCreatePassesTheProtocolsToServerSocket.

@Test
public void testCreatePassesTheProtocolsToServerSocket() throws IOException {
    // first find the supported protocols
    SecureServerSocketFactory secureServerSocketFactory = new SecureServerSocketFactory(NanoHTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()), null);
    SSLServerSocket socket = (SSLServerSocket) secureServerSocketFactory.create();
    String[] protocols = socket.getSupportedProtocols();
    // remove one element from supported protocols
    if (protocols.length > 0) {
        protocols = Arrays.copyOfRange(protocols, 0, protocols.length - 1);
    }
    // test
    secureServerSocketFactory = new SecureServerSocketFactory(NanoHTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()), protocols);
    socket = (SSLServerSocket) secureServerSocketFactory.create();
    Assert.assertArrayEquals("Enabled protocols specified in the factory were not set to the socket.", protocols, socket.getEnabledProtocols());
}
Also used : SecureServerSocketFactory(org.nanohttpd.protocols.http.sockets.SecureServerSocketFactory) SSLServerSocket(javax.net.ssl.SSLServerSocket) Test(org.junit.Test)

Example 38 with SSLServerSocket

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

the class SecureServerSocketFactory method create.

@Override
public ServerSocket create() throws IOException {
    SSLServerSocket ss = null;
    ss = (SSLServerSocket) this.sslServerSocketFactory.createServerSocket();
    if (this.sslProtocols != null) {
        ss.setEnabledProtocols(this.sslProtocols);
    } else {
        ss.setEnabledProtocols(ss.getSupportedProtocols());
    }
    ss.setUseClientMode(false);
    ss.setWantClientAuth(false);
    ss.setNeedClientAuth(false);
    return ss;
}
Also used : SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 39 with SSLServerSocket

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

the class TestSSLContext method create.

/**
     * TestSSLContext creation method that allows separate creation of client and server key store
     */
public static TestSSLContext create(KeyStore clientKeyStore, char[] clientStorePassword, KeyStore serverKeyStore, char[] serverStorePassword, KeyManager clientKeyManagers, KeyManager serverKeyManagers, TrustManager clientTrustManagers, TrustManager serverTrustManagers, SSLContext clientContext, SSLContext serverContext) {
    try {
        SSLServerSocket serverSocket = (SSLServerSocket) serverContext.getServerSocketFactory().createServerSocket(0);
        InetAddress host = InetAddress.getLocalHost();
        int port = serverSocket.getLocalPort();
        return new TestSSLContext(clientKeyStore, clientStorePassword, serverKeyStore, serverStorePassword, (X509ExtendedKeyManager) clientKeyManagers, (X509ExtendedKeyManager) serverKeyManagers, (X509TrustManager) clientTrustManagers, (X509TrustManager) serverTrustManagers, clientContext, serverContext, serverSocket, host, port);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SSLServerSocket(javax.net.ssl.SSLServerSocket) InetAddress(java.net.InetAddress) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException)

Example 40 with SSLServerSocket

use of javax.net.ssl.SSLServerSocket in project camel by apache.

the class SSLContextParametersTest method testCipherSuites.

public void testCipherSuites() throws Exception {
    SSLContext controlContext = SSLContext.getInstance("TLS");
    controlContext.init(null, null, null);
    SSLEngine controlEngine = controlContext.createSSLEngine();
    SSLSocket controlSocket = (SSLSocket) controlContext.getSocketFactory().createSocket();
    SSLServerSocket controlServerSocket = (SSLServerSocket) controlContext.getServerSocketFactory().createServerSocket();
    // default
    SSLContextParameters scp = new SSLContextParameters();
    SSLContext context = scp.createSSLContext();
    SSLEngine engine = context.createSSLEngine();
    SSLSocket socket = (SSLSocket) context.getSocketFactory().createSocket();
    SSLServerSocket serverSocket = (SSLServerSocket) context.getServerSocketFactory().createServerSocket();
    assertTrue(Arrays.equals(controlEngine.getEnabledCipherSuites(), engine.getEnabledCipherSuites()));
    assertTrue(Arrays.equals(controlSocket.getEnabledCipherSuites(), socket.getEnabledCipherSuites()));
    assertTrue(Arrays.equals(this.getDefaultCipherSuiteIncludes(controlServerSocket.getSupportedCipherSuites()), serverSocket.getEnabledCipherSuites()));
    // empty csp
    CipherSuitesParameters csp = new CipherSuitesParameters();
    scp.setCipherSuites(csp);
    context = scp.createSSLContext();
    engine = context.createSSLEngine();
    socket = (SSLSocket) context.getSocketFactory().createSocket();
    serverSocket = (SSLServerSocket) context.getServerSocketFactory().createServerSocket();
    assertEquals(0, engine.getEnabledCipherSuites().length);
    assertEquals(0, socket.getEnabledCipherSuites().length);
    assertEquals(0, serverSocket.getEnabledCipherSuites().length);
    // explicit csp
    csp.setCipherSuite(Collections.singletonList(controlEngine.getEnabledCipherSuites()[0]));
    context = scp.createSSLContext();
    engine = context.createSSLEngine();
    socket = (SSLSocket) context.getSocketFactory().createSocket();
    serverSocket = (SSLServerSocket) context.getServerSocketFactory().createServerSocket();
    assertEquals(1, engine.getEnabledCipherSuites().length);
    assertEquals(controlEngine.getEnabledCipherSuites()[0], engine.getEnabledCipherSuites()[0]);
    assertEquals(1, socket.getEnabledCipherSuites().length);
    assertEquals(controlEngine.getEnabledCipherSuites()[0], socket.getEnabledCipherSuites()[0]);
    assertEquals(1, serverSocket.getEnabledCipherSuites().length);
    assertEquals(controlEngine.getEnabledCipherSuites()[0], serverSocket.getEnabledCipherSuites()[0]);
    // explicit csp overrides filter
    FilterParameters filter = new FilterParameters();
    filter.getInclude().add(".*");
    scp.setCipherSuitesFilter(filter);
    context = scp.createSSLContext();
    engine = context.createSSLEngine();
    socket = (SSLSocket) context.getSocketFactory().createSocket();
    serverSocket = (SSLServerSocket) context.getServerSocketFactory().createServerSocket();
    assertEquals(1, engine.getEnabledCipherSuites().length);
    assertEquals(controlEngine.getEnabledCipherSuites()[0], engine.getEnabledCipherSuites()[0]);
    assertEquals(1, socket.getEnabledCipherSuites().length);
    assertEquals(controlEngine.getEnabledCipherSuites()[0], socket.getEnabledCipherSuites()[0]);
    assertEquals(1, socket.getEnabledCipherSuites().length);
    assertEquals(controlEngine.getEnabledCipherSuites()[0], serverSocket.getEnabledCipherSuites()[0]);
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) SSLSocket(javax.net.ssl.SSLSocket) SSLContext(javax.net.ssl.SSLContext) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Aggregations

SSLServerSocket (javax.net.ssl.SSLServerSocket)67 SSLContext (javax.net.ssl.SSLContext)24 SSLSocket (javax.net.ssl.SSLSocket)19 InetSocketAddress (java.net.InetSocketAddress)15 SSLServerSocketFactory (javax.net.ssl.SSLServerSocketFactory)14 IOException (java.io.IOException)13 ServerSocket (java.net.ServerSocket)12 URL (java.net.URL)10 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)10 SSLEngine (javax.net.ssl.SSLEngine)9 UnknownHostException (java.net.UnknownHostException)7 Proxy (java.net.Proxy)6 Test (org.junit.Test)6 InetAddress (java.net.InetAddress)5 Method (java.lang.reflect.Method)3 KeyManagementException (java.security.KeyManagementException)3 KeyStore (java.security.KeyStore)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ArrayList (java.util.ArrayList)3 ServerSocketFactory (javax.net.ServerSocketFactory)3