Search in sources :

Example 66 with SSLSocket

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

the class HttpsURLConnectionImpl method getLocalPrincipal.

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

Example 67 with SSLSocket

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

the class HttpsURLConnectionImpl method getServerCertificates.

@Override
public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
    SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
    if (cacheResponse != null) {
        List<Certificate> result = cacheResponse.getServerCertificateChain();
        return result != null ? result.toArray(new Certificate[result.size()]) : null;
    }
    SSLSocket sslSocket = getSslSocket();
    if (sslSocket != null) {
        return sslSocket.getSession().getPeerCertificates();
    }
    return null;
}
Also used : SecureCacheResponse(java.net.SecureCacheResponse) SSLSocket(javax.net.ssl.SSLSocket) Certificate(java.security.cert.Certificate)

Example 68 with SSLSocket

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

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 69 with SSLSocket

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

the class HttpsURLConnectionImpl method getCipherSuite.

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

Example 70 with SSLSocket

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

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);
    }
    boolean useNpn = route.modernTls && route.address.transports.contains("spdy/3");
    if (useNpn) {
        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 (useNpn && (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)

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