Example usage for javax.net.ssl SSLServerSocketFactory createServerSocket

List of usage examples for javax.net.ssl SSLServerSocketFactory createServerSocket

Introduction

In this page you can find the example usage for javax.net.ssl SSLServerSocketFactory createServerSocket.

Prototype

@Override
    public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException 

Source Link

Usage

From source file:com.apporiented.hermesftp.cmd.PassiveModeSocketProvider.java

/**
 * Creates the server socket that accepts the data connection.
 * /*w w  w.jav a2  s  . c  o m*/
 * @param localIp The local IP address.
 * @param port The port.
 * @return The server socket.
 * @throws IOException Error on creating server socket.
 */
private ServerSocket createServerSocket(InetAddress localIp, int port) throws IOException {
    ServerSocket sock;
    Boolean dataProtection = (Boolean) ctx.getAttribute(FtpConstants.ATTR_DATA_PROT);
    boolean ssl = dataProtection != null && dataProtection;
    if (ssl) {
        SSLServerSocketFactory factory = ctx.getOptions().getSslContext().getServerSocketFactory();
        SSLServerSocket sslServerSocket = (SSLServerSocket) factory.createServerSocket(port, 1, localIp);
        sslServerSocket.setUseClientMode(false);
        enableCipherSuites(sslServerSocket);
        sock = sslServerSocket;
    } else {
        sock = ServerSocketFactory.getDefault().createServerSocket(port, 1, localIp);
    }
    sock.setSoTimeout(DATA_CHANNEL_TIMEOUT);
    return sock;
}

From source file:at.tugraz.ist.akm.webservice.server.SimpleWebServer.java

public synchronized boolean startServer() {
    if (false == mWakeLock.isHeld()) {
        mWakeLock.acquire();/*www  .j a v a  2s.  c  o m*/
    }
    if (this.isRunning()) {
        mLog.info("web service is already running at port [" + mServerThread.getPort() + "]");
        return true;
    }

    try {
        if (mServerConfig.isHttpsEnabled) {
            initSSLContext();
            final SSLServerSocketFactory sslServerSocketFactory = mSSLContext.getServerSocketFactory();
            mServerSocket = sslServerSocketFactory.createServerSocket(mServerConfig.port, 0, mSocketAddress);
        } else {
            mServerSocket = new ServerSocket(mServerConfig.port, 0, mSocketAddress);
        }
        statusbarIndicateConnectionUrl();
        mServerSocket.setReuseAddress(true);
        mServerSocket.setSoTimeout(2000);
        mIsServerRunning = true;
        mServerThread = new ServerThread(mServerSocket, mHttpContext, mRegistry);
        mServerThread.setDaemon(true);
        mServerThread.start();
        mLog.info("server started at port [" + mServerConfig.port + "]");

        return true;
    } catch (IOException ioException) {
        mLog.error("cannot bind [" + mServerConfig.protocolName + "] socket to [" + mSocketAddress + ":"
                + mServerConfig.port + "]", ioException);
        return false;
    }

}

From source file:com.predic8.membrane.core.transport.ssl.SSLContext.java

public ServerSocket createServerSocket(int port, int backlog, InetAddress bindAddress) throws IOException {
    SSLServerSocketFactory sslssf = sslc.getServerSocketFactory();
    SSLServerSocket sslss = (SSLServerSocket) sslssf.createServerSocket(port, backlog, bindAddress);
    applyCiphers(sslss);/* ww w .ja v a 2  s. c  o m*/
    if (protocols != null) {
        sslss.setEnabledProtocols(protocols);
    } else {
        String[] protocols = sslss.getEnabledProtocols();
        Set<String> set = new HashSet<String>();
        for (String protocol : protocols) {
            if (protocol.equals("SSLv3") || protocol.equals("SSLv2Hello")) {
                continue;
            }
            set.add(protocol);
        }
        sslss.setEnabledProtocols(set.toArray(new String[0]));
    }
    sslss.setWantClientAuth(wantClientAuth);
    sslss.setNeedClientAuth(needClientAuth);
    return sslss;
}

From source file:org.hyperic.hq.bizapp.agent.server.SSLConnectionListener.java

public void setup(int timeout) throws AgentStartException {
    AgentConfig cfg = this.getConfig();
    AgentKeystoreConfig keystoreConfig = new AgentKeystoreConfig();
    SSLProvider provider = new DefaultSSLProviderImpl(keystoreConfig, keystoreConfig.isAcceptUnverifiedCert());
    SSLContext context = provider.getSSLContext();
    SSLServerSocketFactory sFactory = context.getServerSocketFactory();

    InetAddress addr;/*from www. j a  v  a 2 s .  c  o  m*/

    try {
        addr = cfg.getListenIpAsAddr();
    } catch (UnknownHostException exc) {
        throw new AgentStartException(
                "Failed to setup listen socket on '" + cfg.getListenIp() + "': unknown host");
    }

    int port = cfg.getListenPort();
    // Better to retry until this succeeds rather than give up and not allowing
    // the agent to start
    while (true) {
        try {
            listenSock = (SSLServerSocket) sFactory.createServerSocket(port, 50, addr);
            listenSock.setEnabledCipherSuites(
                    getSupportedAndEnabledCiphers(cfg.getEnabledCipherList(), sFactory));
            listenSock.setSoTimeout(timeout);
            break;
        } catch (IOException exc) {
            if (listenSock != null) {
                try {
                    listenSock.close();
                } catch (IOException e1) {
                    log.debug(e1, e1);
                }
            }
            log.warn("Failed to listen at " + cfg.getListenIp() + ":" + port + ": " + exc.getMessage()
                    + ".  Will retry until up.");
            log.debug(exc, exc);
            try {
                Thread.sleep(30000);
            } catch (InterruptedException e) {
                log.debug(e, e);
            }
        }
    }
}