Search in sources :

Example 46 with SSLSocket

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

the class HTTPSServer method stopHTTPSServer.

protected synchronized void stopHTTPSServer() throws HTTPSServerException {
    logger.log(2, "HTTPS_SERVER/STOP_HTTPS_SERVER");
    try {
        thread = null;
        try {
            SSLSocket outputSSLSocket = HTTPS.createSSLSocket();
            outputSSLSocket.connect(new InetSocketAddress(APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS, sslServerSocket.getLocalPort()));
            outputSSLSocket.close();
        } catch (Exception e) {
        }
        try {
            sslServerSocket.close();
        } catch (Exception e) {
        }
    } catch (Exception e) {
        logger.log(2, "HTTPS_SERVER/STOP_HTTPS_SERVER: EXCEPTION", e);
        throw new HTTPSServerException("HTTPS_SERVER/STOP_HTTPS_SERVER", e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket)

Example 47 with SSLSocket

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

the class HTTPSServer method run.

public void run() {
    while (thread != null) {
        try {
            SSLSocket inputSSLSocket = (SSLSocket) sslServerSocket.accept();
            if (thread != null) {
                HTTPSServerWorker httpsServerWorker = new HTTPSServerWorker(this, inputSSLSocket);
                startHTTPSServerWorker(httpsServerWorker);
            } else {
                inputSSLSocket.close();
            }
        } catch (Exception e) {
            if (thread != null) {
                logger.log(2, "HTTPS_SERVER: EXCEPTION", e);
            }
        }
    }
}
Also used : SSLSocket(javax.net.ssl.SSLSocket)

Example 48 with SSLSocket

use of javax.net.ssl.SSLSocket in project k-9 by k9mail.

the class DefaultTrustedSocketFactory method createSocket.

public Socket createSocket(Socket socket, String host, int port, String clientCertificateAlias) throws NoSuchAlgorithmException, KeyManagementException, MessagingException, IOException {
    TrustManager[] trustManagers = new TrustManager[] { TrustManagerFactory.get(host, port) };
    KeyManager[] keyManagers = null;
    if (!TextUtils.isEmpty(clientCertificateAlias)) {
        keyManagers = new KeyManager[] { new KeyChainKeyManager(context, clientCertificateAlias) };
    }
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagers, trustManagers, null);
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    Socket trustedSocket;
    if (socket == null) {
        trustedSocket = socketFactory.createSocket();
    } else {
        trustedSocket = socketFactory.createSocket(socket, host, port, true);
    }
    SSLSocket sslSocket = (SSLSocket) trustedSocket;
    hardenSocket(sslSocket);
    setSniHost(socketFactory, sslSocket, host);
    return trustedSocket;
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) KeyManager(javax.net.ssl.KeyManager) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) TrustManager(javax.net.ssl.TrustManager)

Example 49 with SSLSocket

use of javax.net.ssl.SSLSocket in project mongo-java-driver by mongodb.

the class SocketStreamHelper method initialize.

static void initialize(final Socket socket, final ServerAddress address, final SocketSettings settings, final SslSettings sslSettings) throws IOException {
    socket.setTcpNoDelay(true);
    socket.setSoTimeout(settings.getReadTimeout(MILLISECONDS));
    socket.setKeepAlive(settings.isKeepAlive());
    if (settings.getReceiveBufferSize() > 0) {
        socket.setReceiveBufferSize(settings.getReceiveBufferSize());
    }
    if (settings.getSendBufferSize() > 0) {
        socket.setSendBufferSize(settings.getSendBufferSize());
    }
    if (sslSettings.isEnabled() || socket instanceof SSLSocket) {
        if (!(socket instanceof SSLSocket)) {
            throw new MongoInternalException("SSL is enabled but the socket is not an instance of javax.net.ssl.SSLSocket");
        }
        SSLSocket sslSocket = (SSLSocket) socket;
        SSLParameters sslParameters = sslSocket.getSSLParameters();
        enableSni(address, sslParameters);
        if (!sslSettings.isInvalidHostNameAllowed()) {
            enableHostNameVerification(sslParameters);
        }
        sslSocket.setSSLParameters(sslParameters);
    }
    socket.connect(address.getSocketAddress(), settings.getConnectTimeout(MILLISECONDS));
}
Also used : SSLParameters(javax.net.ssl.SSLParameters) SSLSocket(javax.net.ssl.SSLSocket) MongoInternalException(com.mongodb.MongoInternalException)

Example 50 with SSLSocket

use of javax.net.ssl.SSLSocket in project ignition by mttkay.

the class EasySSLSocketFactory method connectSocket.

/**
     * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
     *      java.lang.String, int, java.net.InetAddress, int, org.apache.http.params.HttpParams)
     */
@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0) {
            // indicates "any"
            localPort = 0;
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }
    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket)

Aggregations

SSLSocket (javax.net.ssl.SSLSocket)326 IOException (java.io.IOException)101 Test (org.junit.Test)62 SSLContext (javax.net.ssl.SSLContext)59 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)59 Socket (java.net.Socket)57 OutputStream (java.io.OutputStream)50 InetSocketAddress (java.net.InetSocketAddress)39 CertificateException (java.security.cert.CertificateException)33 SSLException (javax.net.ssl.SSLException)32 SSLSession (javax.net.ssl.SSLSession)31 InputStream (java.io.InputStream)30 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)30 SSLServerSocket (javax.net.ssl.SSLServerSocket)27 SocketTimeoutException (java.net.SocketTimeoutException)24 SocketException (java.net.SocketException)23 ServerSocket (java.net.ServerSocket)22 UnknownHostException (java.net.UnknownHostException)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)21 InputStreamReader (java.io.InputStreamReader)19