Search in sources :

Example 46 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project bnd by bndtools.

the class HttpConnectorTest method testConnectHTTPSBadCerficate.

public static void testConnectHTTPSBadCerficate() throws Exception {
    DefaultURLConnector connector = new DefaultURLConnector();
    InputStream stream = null;
    try {
        stream = connector.connect(new URL(getUrl(false) + "bundles/dummybundle.jar"));
        fail("Expected SSLHandsakeException");
    } catch (SSLHandshakeException e) {
    // expected
    } finally {
        if (stream != null)
            IO.close(stream);
    }
}
Also used : InputStream(java.io.InputStream) URL(java.net.URL) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 47 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project rabbitmq-java-client by rabbitmq.

the class SslContextFactoryTest method doTestSetSslContextFactory.

private void doTestSetSslContextFactory(Supplier<ConnectionFactory> supplier) throws Exception {
    ConnectionFactory connectionFactory = supplier.get();
    SslContextFactory sslContextFactory = sslContextFactory();
    connectionFactory.setSslContextFactory(sslContextFactory);
    Connection connection = connectionFactory.newConnection("connection01");
    TestUtils.close(connection);
    try {
        connectionFactory.newConnection("connection02");
        fail("The SSL context of this client should not trust the server");
    } catch (SSLHandshakeException e) {
    // OK
    }
}
Also used : ConnectionFactory(com.rabbitmq.client.ConnectionFactory) SslContextFactory(com.rabbitmq.client.SslContextFactory) Connection(com.rabbitmq.client.Connection) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 48 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project dropbox-sdk-java by dropbox.

the class NetworkIOException method computeMessage.

private static String computeMessage(IOException ex) {
    String message = ex.getMessage();
    // useful for debugging.
    if (ex instanceof SSLHandshakeException) {
        Throwable innerCause = ex.getCause();
        if (innerCause instanceof CertPathValidatorException) {
            CertPathValidatorException cpve = (CertPathValidatorException) innerCause;
            message += "[CERT PATH: " + cpve.getCertPath() + "]";
        }
    }
    return message;
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 49 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project baseio by generallycloud.

the class SocketSelectorEventLoop method accept.

private void accept(NioSocketChannel channel) {
    try {
        ByteBuf buf = this.buf;
        buf.clear();
        buf.nioBuffer();
        int length = channel.read(buf);
        if (length < 1) {
            if (length == -1) {
                CloseUtil.close(channel);
            }
            return;
        }
        channel.active();
        byteBufReader.accept(channel, buf.flip());
    } catch (Throwable e) {
        if (e instanceof SSLHandshakeException) {
            // failed connect , the session should be null
            getSelector().finishConnect(null, e);
        }
        closeSocketChannel(channel, e);
    }
}
Also used : ByteBuf(com.generallycloud.baseio.buffer.ByteBuf) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 50 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project platform_frameworks_base by android.

the class TestUtils method assertUrlConnectionFails.

public static void assertUrlConnectionFails(SSLContext context, String host, int port) throws Exception {
    URL url = new URL("https://" + host + ":" + port);
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    connection.setSSLSocketFactory(context.getSocketFactory());
    try {
        connection.getInputStream();
        fail("Connection to " + host + ":" + port + " expected to fail");
    } catch (SSLHandshakeException expected) {
    // ignored.
    }
}
Also used : URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) 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