Search in sources :

Example 56 with SSLHandshakeException

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

the class RouteSelector method connectFailed.

/**
   * Clients should invoke this method when they encounter a connectivity
   * failure on a connection returned by this route selector.
   */
public void connectFailed(Connection connection, IOException failure) {
    Route failedRoute = connection.getRoute();
    if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
        // Tell the proxy selector when we fail to connect on a fresh connection.
        proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
    }
    failedRoutes.add(failedRoute);
    if (!(failure instanceof SSLHandshakeException)) {
        // If the problem was not related to SSL then it will also fail with
        // a different Tls mode therefore we can be proactive about it.
        failedRoutes.add(failedRoute.flipTlsMode());
    }
}
Also used : Route(com.squareup.okhttp.Route) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 57 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project netty by netty.

the class SocketSslClientRenegotiateTest method testSslRenegotiationRejected.

public void testSslRenegotiationRejected(ServerBootstrap sb, Bootstrap cb) throws Throwable {
    reset();
    sb.childHandler(new ChannelInitializer<Channel>() {

        @Override
        @SuppressWarnings("deprecation")
        public void initChannel(Channel sch) throws Exception {
            serverChannel = sch;
            serverSslHandler = serverCtx.newHandler(sch.alloc());
            sch.pipeline().addLast("ssl", serverSslHandler);
            sch.pipeline().addLast("handler", serverHandler);
        }
    });
    cb.handler(new ChannelInitializer<Channel>() {

        @Override
        @SuppressWarnings("deprecation")
        public void initChannel(Channel sch) throws Exception {
            clientChannel = sch;
            clientSslHandler = clientCtx.newHandler(sch.alloc());
            sch.pipeline().addLast("ssl", clientSslHandler);
            sch.pipeline().addLast("handler", clientHandler);
        }
    });
    Channel sc = sb.bind().sync().channel();
    cb.connect().sync();
    Future<Channel> clientHandshakeFuture = clientSslHandler.handshakeFuture();
    clientHandshakeFuture.sync();
    String renegotiation = "SSL_RSA_WITH_3DES_EDE_CBC_SHA";
    clientSslHandler.engine().setEnabledCipherSuites(new String[] { renegotiation });
    clientSslHandler.renegotiate().await();
    serverChannel.close().awaitUninterruptibly();
    clientChannel.close().awaitUninterruptibly();
    sc.close().awaitUninterruptibly();
    try {
        if (serverException.get() != null) {
            throw serverException.get();
        }
        fail();
    } catch (DecoderException e) {
        assertTrue(e.getCause() instanceof SSLHandshakeException);
    }
    if (clientException.get() != null) {
        throw clientException.get();
    }
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) Channel(io.netty.channel.Channel) DecoderException(io.netty.handler.codec.DecoderException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ClosedChannelException(java.nio.channels.ClosedChannelException) CertificateException(java.security.cert.CertificateException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 58 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project okhttp by square.

the class ConnectionSpecSelectorTest method nonRetryableSSLHandshakeException.

@Test
public void nonRetryableSSLHandshakeException() throws Exception {
    ConnectionSpecSelector connectionSpecSelector = createConnectionSpecSelector(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS);
    SSLSocket socket = createSocketWithEnabledProtocols(TlsVersion.TLS_1_1, TlsVersion.TLS_1_0);
    connectionSpecSelector.configureSecureSocket(socket);
    SSLHandshakeException trustIssueException = new SSLHandshakeException("Certificate handshake exception");
    trustIssueException.initCause(new CertificateException());
    boolean retry = connectionSpecSelector.connectionFailed(trustIssueException);
    assertFalse(retry);
    socket.close();
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) CertificateException(java.security.cert.CertificateException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.Test)

Example 59 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project okhttp by square.

the class URLConnectionTest method connectViaHttpsToUntrustedServer.

/**
   * Verify that we don't retry connections on certificate verification errors.
   *
   * http://code.google.com/p/android/issues/detail?id=13178
   */
@Test
public void connectViaHttpsToUntrustedServer() throws IOException, InterruptedException {
    server.useHttps(sslClient.socketFactory, false);
    // unused
    server.enqueue(new MockResponse());
    connection = urlFactory.open(server.url("/foo").url());
    try {
        connection.getInputStream();
        fail();
    } catch (SSLHandshakeException expected) {
        assertTrue(expected.getCause() instanceof CertificateException);
    }
    assertEquals(0, server.getRequestCount());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) CertificateException(java.security.cert.CertificateException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.junit.Test)

Example 60 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project android_frameworks_base by ParanoidAndroid.

the class Connection method openHttpConnection.

/**
     * @return true on success
     */
private boolean openHttpConnection(Request req) {
    long now = SystemClock.uptimeMillis();
    int error = EventHandler.OK;
    Exception exception = null;
    try {
        // reset the certificate to null before opening a connection
        mCertificate = null;
        mHttpClientConnection = openConnection(req);
        if (mHttpClientConnection != null) {
            mHttpClientConnection.setSocketTimeout(SOCKET_TIMEOUT);
            mHttpContext.setAttribute(HTTP_CONNECTION, mHttpClientConnection);
        } else {
            // we tried to do SSL tunneling, failed,
            // and need to drop the request;
            // we have already informed the handler
            req.mFailCount = RETRY_REQUEST_LIMIT;
            return false;
        }
    } catch (UnknownHostException e) {
        if (HttpLog.LOGV)
            HttpLog.v("Failed to open connection");
        error = EventHandler.ERROR_LOOKUP;
        exception = e;
    } catch (IllegalArgumentException e) {
        if (HttpLog.LOGV)
            HttpLog.v("Illegal argument exception");
        error = EventHandler.ERROR_CONNECT;
        req.mFailCount = RETRY_REQUEST_LIMIT;
        exception = e;
    } catch (SSLConnectionClosedByUserException e) {
        // hack: if we have an SSL connection failure,
        // we don't want to reconnect
        req.mFailCount = RETRY_REQUEST_LIMIT;
        // no error message
        return false;
    } catch (SSLHandshakeException e) {
        // hack: if we have an SSL connection failure,
        // we don't want to reconnect
        req.mFailCount = RETRY_REQUEST_LIMIT;
        if (HttpLog.LOGV)
            HttpLog.v("SSL exception performing handshake");
        error = EventHandler.ERROR_FAILED_SSL_HANDSHAKE;
        exception = e;
    } catch (IOException e) {
        error = EventHandler.ERROR_CONNECT;
        exception = e;
    }
    if (HttpLog.LOGV) {
        long now2 = SystemClock.uptimeMillis();
        HttpLog.v("Connection.openHttpConnection() " + (now2 - now) + " " + mHost);
    }
    if (error == EventHandler.OK) {
        return true;
    } else {
        if (req.mFailCount < RETRY_REQUEST_LIMIT) {
            // requeue
            mRequestFeeder.requeueRequest(req);
            req.mFailCount++;
        } else {
            httpFailure(req, error, exception);
        }
        return error == EventHandler.OK;
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) ParseException(org.apache.http.ParseException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) HttpException(org.apache.http.HttpException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Aggregations

SSLHandshakeException (javax.net.ssl.SSLHandshakeException)90 IOException (java.io.IOException)29 Test (org.junit.Test)22 CertificateException (java.security.cert.CertificateException)18 URL (java.net.URL)15 SSLException (javax.net.ssl.SSLException)15 SocketException (java.net.SocketException)13 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)12 SSLProtocolException (javax.net.ssl.SSLProtocolException)10 Socket (java.net.Socket)9 SSLSocket (javax.net.ssl.SSLSocket)9 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)8 SocketTimeoutException (java.net.SocketTimeoutException)7 SSLSession (javax.net.ssl.SSLSession)7 InputStream (java.io.InputStream)6 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 Channel (io.netty.channel.Channel)5 InetSocketAddress (java.net.InetSocketAddress)5 MalformedURLException (java.net.MalformedURLException)5 ClosedChannelException (java.nio.channels.ClosedChannelException)5