Search in sources :

Example 6 with SslHandshakeListener

use of org.eclipse.jetty.io.ssl.SslHandshakeListener in project jetty.project by eclipse.

the class HttpClientTLSTest method testMismatchBetweenTLSProtocolAndTLSCiphersOnClient.

@Test
public void testMismatchBetweenTLSProtocolAndTLSCiphersOnClient() throws Exception {
    SslContextFactory serverTLSFactory = createSslContextFactory();
    startServer(serverTLSFactory, new EmptyServerHandler());
    CountDownLatch serverLatch = new CountDownLatch(1);
    connector.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            serverLatch.countDown();
        }
    });
    SslContextFactory clientTLSFactory = createSslContextFactory();
    // TLS 1.1 protocol, but only TLS 1.2 ciphers.
    clientTLSFactory.setIncludeProtocols("TLSv1.1");
    clientTLSFactory.setIncludeCipherSuites("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
    startClient(clientTLSFactory);
    CountDownLatch clientLatch = new CountDownLatch(1);
    client.addBean(new SslHandshakeListener() {

        @Override
        public void handshakeFailed(Event event, Throwable failure) {
            clientLatch.countDown();
        }
    });
    try {
        client.newRequest("localhost", connector.getLocalPort()).scheme(HttpScheme.HTTPS.asString()).timeout(5, TimeUnit.SECONDS).send();
        Assert.fail();
    } catch (ExecutionException x) {
    // Expected.
    }
    Assert.assertTrue(serverLatch.await(1, TimeUnit.SECONDS));
    Assert.assertTrue(clientLatch.await(1, TimeUnit.SECONDS));
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslHandshakeListener(org.eclipse.jetty.io.ssl.SslHandshakeListener) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)6 SslHandshakeListener (org.eclipse.jetty.io.ssl.SslHandshakeListener)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 Test (org.junit.Test)6 ExecutionException (java.util.concurrent.ExecutionException)4 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1