Search in sources :

Example 41 with SSLSocket

use of javax.net.ssl.SSLSocket in project Anki-Android by Ramblurr.

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)

Example 42 with SSLSocket

use of javax.net.ssl.SSLSocket in project OpenAttestation by OpenAttestation.

the class TASecureServer method waitForConnections.

public void waitForConnections() {
    SSLSocket sock = null;
    /*
         Take ownership of the TPM
         */
    takeOwnerShip();
    while (true) {
        try {
            sock = (SSLSocket) serverSock.accept();
            log.info("Have accepted new socket.");
            /*
                 Take ownership of the TPM. This time if already ownership is done 
                 * then this method will return. This is fix the bug where sometimes 
                 * tcsd is not up. 
                 */
            takeOwnerShip();
            handleConnection(sock.getInputStream(), sock.getOutputStream());
        } catch (Exception e) {
            log.error(null, e);
        } finally {
            try {
                log.info("Closing socket.");
                sock.close();
            } catch (IOException ex) {
                log.error(null, ex);
            }
        }
        log.info("Finished with socket, waiting for next connection.");
    }
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) IOException(java.io.IOException) IOException(java.io.IOException)

Example 43 with SSLSocket

use of javax.net.ssl.SSLSocket in project phonegap-facebook-plugin by Wizcorp.

the class Connection method upgradeToTls.

/**
   * Create an {@code SSLSocket} and perform the TLS handshake and certificate
   * validation.
   */
private void upgradeToTls(TunnelRequest tunnelRequest) throws IOException {
    Platform platform = Platform.get();
    // Make an SSL Tunnel on the first message pair of each SSL + proxy connection.
    if (requiresTunnel()) {
        makeTunnel(tunnelRequest);
    }
    // Create the wrapper over connected socket.
    socket = route.address.sslSocketFactory.createSocket(socket, route.address.uriHost, route.address.uriPort, true);
    SSLSocket sslSocket = (SSLSocket) socket;
    if (route.modernTls) {
        platform.enableTlsExtensions(sslSocket, route.address.uriHost);
    } else {
        platform.supportTlsIntolerantServer(sslSocket);
    }
    if (route.modernTls) {
        platform.setNpnProtocols(sslSocket, NPN_PROTOCOLS);
    }
    // Force handshake. This can throw!
    sslSocket.startHandshake();
    // Verify that the socket's certificates are acceptable for the target host.
    if (!route.address.hostnameVerifier.verify(route.address.uriHost, sslSocket.getSession())) {
        throw new IOException("Hostname '" + route.address.uriHost + "' was not verified");
    }
    out = sslSocket.getOutputStream();
    in = sslSocket.getInputStream();
    byte[] selectedProtocol;
    if (route.modernTls && (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) {
        if (Arrays.equals(selectedProtocol, SPDY3)) {
            // SPDY timeouts are set per-stream.
            sslSocket.setSoTimeout(0);
            spdyConnection = new SpdyConnection.Builder(route.address.getUriHost(), true, in, out).build();
        } else if (!Arrays.equals(selectedProtocol, HTTP_11)) {
            throw new IOException("Unexpected NPN transport " + new String(selectedProtocol, "ISO-8859-1"));
        }
    }
}
Also used : Platform(com.squareup.okhttp.internal.Platform) SSLSocket(javax.net.ssl.SSLSocket) IOException(java.io.IOException)

Example 44 with SSLSocket

use of javax.net.ssl.SSLSocket in project phonegap-facebook-plugin by Wizcorp.

the class HttpsURLConnectionImpl method getPeerPrincipal.

@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
    SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
    if (cacheResponse != null) {
        return cacheResponse.getPeerPrincipal();
    }
    SSLSocket sslSocket = getSslSocket();
    if (sslSocket != null) {
        return sslSocket.getSession().getPeerPrincipal();
    }
    return null;
}
Also used : SecureCacheResponse(java.net.SecureCacheResponse) SSLSocket(javax.net.ssl.SSLSocket)

Example 45 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)

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