Search in sources :

Example 6 with SSLServerSocketFactory

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

the class LegacySSLSocketFactory method createSSLServerSocket.

public ServerSocket createSSLServerSocket(int port, int backlog, InetAddress inetAddress) throws IOException {
    this.initSSLContext();
    SSLServerSocketFactory serverSocketFactory = this.sslContext.getServerSocketFactory();
    SSLServerSocket serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(port, backlog, inetAddress);
    if (this.jsseSecurityDomain.getProtocols() != null) {
        serverSocket.setEnabledProtocols(this.jsseSecurityDomain.getProtocols());
    }
    if (this.jsseSecurityDomain.getCipherSuites() != null) {
        serverSocket.setEnabledCipherSuites(this.jsseSecurityDomain.getCipherSuites());
    }
    if (this.jsseSecurityDomain.isClientAuth() || this.require_mutual_auth) {
        serverSocket.setNeedClientAuth(true);
    } else {
        serverSocket.setWantClientAuth(this.request_mutual_auth);
    }
    return serverSocket;
}
Also used : SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 7 with SSLServerSocketFactory

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

the class ConnectorServerFactory method setupSsl.

private void setupSsl() throws GeneralSecurityException {
    SSLServerSocketFactory sssf = keystoreManager.createSSLServerFactory(null, secureProtocol, algorithm, keyStore, keyAlias, trustStore, keyStoreAvailabilityTimeout);
    RMIServerSocketFactory rssf = new KarafSslRMIServerSocketFactory(sssf, this.isClientAuth(), getRmiServerHost());
    RMIClientSocketFactory rcsf = new SslRMIClientSocketFactory();
    environment.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, rssf);
    environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, rcsf);
//@TODO secure RMI connector as well?
//env.put("com.sun.jndi.rmi.factory.socket", rcsf);
}
Also used : SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) RMIClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

Example 8 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 9 with SSLServerSocketFactory

use of javax.net.ssl.SSLServerSocketFactory in project Payara by payara.

the class IIOPSSLSocketFactory method createSSLServerSocket.

// ----- END implements com.sun.corba.ee.spi.transport.ORBSocketFactory -----
/**
 * Create an SSL server socket at the specified InetSocketAddress. If the type
 * is SSL_MUTUALAUTH then SSL client authentication is requested.
 */
private ServerSocket createSSLServerSocket(String type, InetSocketAddress inetSocketAddress) throws IOException {
    if (inetSocketAddress == null) {
        throw new IOException(getFormatMessage("iiop.invalid_sslserverport", new Object[] { null }));
    }
    int port = inetSocketAddress.getPort();
    Integer iport = Integer.valueOf(port);
    SSLInfo sslInfo = (SSLInfo) portToSSLInfo.get(iport);
    if (sslInfo == null) {
        throw new IOException(getFormatMessage("iiop.invalid_sslserverport", new Object[] { iport }));
    }
    SSLServerSocketFactory ssf = sslInfo.getContext().getServerSocketFactory();
    String[] ssl3TlsCiphers = sslInfo.getSsl3TlsCiphers();
    String[] ssl2Ciphers = sslInfo.getSsl2Ciphers();
    String[] ciphers = null;
    if (ssl3TlsCiphers != null || ssl2Ciphers != null) {
        String[] socketCiphers = ssf.getDefaultCipherSuites();
        ciphers = mergeCiphers(socketCiphers, ssl3TlsCiphers, ssl2Ciphers);
    }
    String[] cs = null;
    if (_logger.isLoggable(Level.FINE)) {
        cs = ssf.getSupportedCipherSuites();
        for (int i = 0; i < cs.length; ++i) {
            _logger.log(Level.FINE, "Cipher Suite: " + cs[i]);
        }
    }
    ServerSocket ss = null;
    try {
        // bugfix for 6349541
        // specify the ip address to bind to, 50 is the default used
        // by the ssf implementation when only the port is specified
        ss = ssf.createServerSocket(port, BACKLOG, inetSocketAddress.getAddress());
        if (ciphers != null) {
            ((SSLServerSocket) ss).setEnabledCipherSuites(ciphers);
        }
    } catch (IOException e) {
        _logger.log(Level.SEVERE, "iiop.createsocket_exception", new Object[] { type, String.valueOf(port) });
        _logger.log(Level.SEVERE, "", e);
        throw e;
    }
    try {
        if (type.equals(SSL_MUTUALAUTH)) {
            _logger.log(Level.FINE, "Setting Mutual auth");
            ((SSLServerSocket) ss).setNeedClientAuth(true);
        }
    } catch (Exception e) {
        _logger.log(Level.SEVERE, "iiop.cipher_exception", e);
        throw new IOException(e.getMessage());
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Created server socket:" + ss);
    }
    return ss;
}
Also used : SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) ServerSocket(java.net.ServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket) IOException(java.io.IOException) SSLServerSocket(javax.net.ssl.SSLServerSocket) SocketException(java.net.SocketException) IOException(java.io.IOException)

Example 10 with SSLServerSocketFactory

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

the class TCPServerActivity method createPrintWriter.

@Override
protected synchronized Writer createPrintWriter() {
    String host = getActivityDef().getParams().getOptionalString("host").orElse("localhost");
    int port = getActivityDef().getParams().getOptionalInteger("port").orElse(12345);
    if (listenerSocket == null || listenerSocket.isClosed()) {
        try {
            InetAddress hostAddr = InetAddress.getByName(host);
            listenerSocket = socketFactory.createServerSocket(port, 10, hostAddr);
            if (socketFactory instanceof SSLServerSocketFactory) {
                logger.info("SSL enabled on server socket " + listenerSocket);
            }
            SocketAcceptor socketAcceptor = new SocketAcceptor(queue, listenerSocket);
            managedShutdown.add(socketAcceptor);
            Thread acceptorThread = new Thread(socketAcceptor);
            acceptorThread.setDaemon(true);
            acceptorThread.setName("Listener/" + listenerSocket);
            acceptorThread.start();
        } catch (IOException e) {
            throw new RuntimeException("Error listening on listenerSocket:" + e, e);
        }
    }
    QueueWriterAdapter queueWriterAdapter = new QueueWriterAdapter(this.queue);
    logger.info("initialized queue writer:" + queueWriterAdapter);
    return queueWriterAdapter;
}
Also used : SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

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