You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/07/24 14:39:17 UTC

[httpcomponents-core] 03/03: TLS integration tests

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit f33d8c7672bdb5cce3fc2a2ca92f9bea6f2c3029
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Jul 24 15:51:04 2019 +0200

    TLS integration tests
---
 .../classic/ClassicServerAndRequesterTest.java     |   2 +-
 .../testing/classic/ClassicTLSIntegrationTest.java | 320 +++++++++++++++++++++
 .../core5/testing/nio/Http1TLSIntegrationTest.java | 186 ++++++++++++
 3 files changed, 507 insertions(+), 1 deletion(-)

diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerAndRequesterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerAndRequesterTest.java
index 1570584..a777a49 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerAndRequesterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicServerAndRequesterTest.java
@@ -157,7 +157,7 @@ public class ClassicServerAndRequesterTest {
         protected void before() throws Throwable {
             log.debug("Starting up test client");
             requester = RequesterBootstrap.bootstrap()
-                    .setSslContext(scheme == URIScheme.HTTPS  ? SSLTestContexts.createServerSSLContext() : null)
+                    .setSslContext(scheme == URIScheme.HTTPS  ? SSLTestContexts.createClientSSLContext() : null)
                     .setSocketConfig(SocketConfig.custom()
                             .setSoTimeout(TIMEOUT)
                             .build())
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java
new file mode 100644
index 0000000..95afd26
--- /dev/null
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java
@@ -0,0 +1,320 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.testing.classic;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLSession;
+
+import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.Methods;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.impl.bootstrap.HttpRequester;
+import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.bootstrap.RequesterBootstrap;
+import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.apache.hc.core5.http.io.SocketConfig;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.apache.hc.core5.http.io.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.apache.hc.core5.http.protocol.BasicHttpContext;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.http.ssl.TLS;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.ssl.SSLContexts;
+import org.apache.hc.core5.testing.SSLTestContexts;
+import org.apache.hc.core5.util.Timeout;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExternalResource;
+
+public class ClassicTLSIntegrationTest {
+
+    private static final Timeout TIMEOUT = Timeout.ofSeconds(30);
+
+    private HttpServer server;
+
+    @Rule
+    public ExternalResource serverResource = new ExternalResource() {
+
+        @Override
+        protected void after() {
+            if (server != null) {
+                try {
+                    server.close(CloseMode.IMMEDIATE);
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    private HttpRequester requester;
+
+    @Rule
+    public ExternalResource clientResource = new ExternalResource() {
+
+        @Override
+        protected void after() {
+            if (requester != null) {
+                try {
+                    requester.close(CloseMode.GRACEFUL);
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    @Test
+    public void testTLSSuccess() throws Exception {
+        server = ServerBootstrap.bootstrap()
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .setExceptionListener(LoggingExceptionListener.INSTANCE)
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .register("*", new EchoHandler())
+                .create();
+        server.start();
+
+        final AtomicReference<SSLSession> sslSessionRef = new AtomicReference<>(null);
+
+        requester = RequesterBootstrap.bootstrap()
+                .setSslContext(SSLTestContexts.createClientSSLContext())
+                .setSslSessionVerifier(new SSLSessionVerifier() {
+
+                    @Override
+                    public void verify(final HttpHost endpoint, final SSLSession sslSession) throws SSLException {
+                        sslSessionRef.set(sslSession);
+                    }
+
+                })
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
+                .create();
+
+        final HttpContext context = new BasicHttpContext();
+        final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
+        final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Methods.POST, "/stuff");
+        request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN));
+        try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) {
+            Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+            final String body1 = EntityUtils.toString(response1.getEntity());
+            Assert.assertThat(body1, CoreMatchers.equalTo("some stuff"));
+        }
+
+        final SSLSession sslSession = sslSessionRef.getAndSet(null);
+        final ProtocolVersion tlsVersion = TLS.parse(sslSession.getProtocol());
+        Assert.assertThat(tlsVersion.greaterEquals(TLS.V_1_2.version), CoreMatchers.equalTo(true));
+        Assert.assertThat(sslSession.getPeerPrincipal().getName(),
+                CoreMatchers.equalTo("CN=localhost,OU=Apache HttpComponents,O=Apache Software Foundation"));
+    }
+
+    @Test(expected = SSLHandshakeException.class)
+    public void testTLSTrustFailure() throws Exception {
+        server = ServerBootstrap.bootstrap()
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .setExceptionListener(LoggingExceptionListener.INSTANCE)
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .register("*", new EchoHandler())
+                .create();
+        server.start();
+
+        requester = RequesterBootstrap.bootstrap()
+                .setSslContext(SSLContexts.createDefault())
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
+                .create();
+
+        final HttpContext context = new BasicHttpContext();
+        final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
+        final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Methods.POST, "/stuff");
+        request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN));
+        try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) {
+            EntityUtils.consume(response1.getEntity());
+        }
+    }
+
+    @Test(expected = SSLHandshakeException.class)
+    public void testTLSClientAuthFailure() throws Exception {
+        server = ServerBootstrap.bootstrap()
+                .setSslContext(SSLTestContexts.createClientSSLContext())
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .setSslSetupHandler(new Callback<SSLParameters>() {
+
+                    @Override
+                    public void execute(final SSLParameters sslParameters) {
+                        sslParameters.setNeedClientAuth(true);
+                    }
+
+                })
+                .setExceptionListener(LoggingExceptionListener.INSTANCE)
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .register("*", new EchoHandler())
+                .create();
+        server.start();
+
+        requester = RequesterBootstrap.bootstrap()
+                .setSslContext(SSLTestContexts.createClientSSLContext())
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
+                .create();
+
+        final HttpContext context = new BasicHttpContext();
+        final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
+        final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Methods.POST, "/stuff");
+        request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN));
+        try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) {
+            EntityUtils.consume(response1.getEntity());
+        }
+    }
+
+    @Test(expected = IOException.class)
+    public void testSSLDisabledByDefault() throws Exception {
+        server = ServerBootstrap.bootstrap()
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .setSslSetupHandler(new Callback<SSLParameters>() {
+
+                    @Override
+                    public void execute(final SSLParameters sslParameters) {
+                        sslParameters.setProtocols(new String[]{"SSLv3"});
+                    }
+
+                })
+                .create();
+        server.start();
+
+        requester = RequesterBootstrap.bootstrap()
+                .setSslContext(SSLTestContexts.createClientSSLContext())
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
+                .create();
+
+        final HttpContext context = new BasicHttpContext();
+        final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
+        final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Methods.POST, "/stuff");
+        request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN));
+        try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) {
+            EntityUtils.consume(response1.getEntity());
+        }
+    }
+
+    @Test
+    public void testWeakCiphersDisabledByDefault() throws Exception {
+
+        requester = RequesterBootstrap.bootstrap()
+                .setSslContext(SSLTestContexts.createClientSSLContext())
+                .setSocketConfig(SocketConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE)
+                .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
+                .create();
+
+        final String[] weakCiphersSuites = {
+                "SSL_RSA_WITH_RC4_128_SHA",
+                "SSL_RSA_WITH_3DES_EDE_CBC_SHA",
+                "TLS_DH_anon_WITH_AES_128_CBC_SHA",
+                "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
+                "SSL_RSA_WITH_NULL_SHA",
+                "SSL_RSA_WITH_3DES_EDE_CBC_SHA",
+                "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
+                "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
+                "TLS_DH_anon_WITH_AES_256_GCM_SHA384",
+                "TLS_ECDH_anon_WITH_AES_256_CBC_SHA",
+                "TLS_RSA_WITH_NULL_SHA256",
+                "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
+                "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
+                "TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
+                "SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5"
+        };
+
+        for (final String cipherSuite : weakCiphersSuites) {
+            try {
+                server = ServerBootstrap.bootstrap()
+                        .setSslContext(SSLTestContexts.createServerSSLContext())
+                        .setSslSetupHandler(new Callback<SSLParameters>() {
+
+                            @Override
+                            public void execute(final SSLParameters sslParameters) {
+                                sslParameters.setProtocols(new String[]{cipherSuite});
+                            }
+
+                        })
+                        .create();
+                server.start();
+
+                final HttpContext context = new BasicHttpContext();
+                final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
+                final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Methods.POST, "/stuff");
+                request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN));
+                try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) {
+                    EntityUtils.consume(response1.getEntity());
+                }
+
+                Assert.fail("IOException expected");
+            } catch (final IOException | IllegalArgumentException expected) {
+            } finally {
+                server.close(CloseMode.IMMEDIATE);
+            }
+        }
+    }
+
+}
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1TLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1TLSIntegrationTest.java
new file mode 100644
index 0000000..4852687
--- /dev/null
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1TLSIntegrationTest.java
@@ -0,0 +1,186 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.testing.nio;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+
+import org.apache.hc.core5.function.Supplier;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.Methods;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.impl.bootstrap.AsyncRequesterBootstrap;
+import org.apache.hc.core5.http.impl.bootstrap.AsyncServerBootstrap;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
+import org.apache.hc.core5.http.nio.ssl.BasicServerTlsStrategy;
+import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.support.BasicResponseConsumer;
+import org.apache.hc.core5.http.protocol.UriPatternMatcher;
+import org.apache.hc.core5.http.ssl.TLS;
+import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.net.NamedEndpoint;
+import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.ListenerEndpoint;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
+import org.apache.hc.core5.testing.SSLTestContexts;
+import org.apache.hc.core5.testing.classic.LoggingConnPoolListener;
+import org.apache.hc.core5.util.Timeout;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExternalResource;
+
+public class Http1TLSIntegrationTest {
+
+    private static final Timeout TIMEOUT = Timeout.ofSeconds(30);
+
+    private HttpAsyncServer server;
+
+    @Rule
+    public ExternalResource serverResource = new ExternalResource() {
+
+        @Override
+        protected void after() {
+            if (server != null) {
+                try {
+                    server.close(CloseMode.IMMEDIATE);
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    private HttpAsyncRequester requester;
+
+    @Rule
+    public ExternalResource clientResource = new ExternalResource() {
+
+        @Override
+        protected void after() {
+            if (requester != null) {
+                try {
+                    requester.close(CloseMode.GRACEFUL);
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    @Test
+    public void testBasicSSL() throws Exception {
+        server = AsyncServerBootstrap.bootstrap()
+                .setLookupRegistry(new UriPatternMatcher<Supplier<AsyncServerExchangeHandler>>())
+                .setIOReactorConfig(
+                        IOReactorConfig.custom()
+                                .setSoTimeout(TIMEOUT)
+                                .build())
+                .setTlsStrategy(new BasicServerTlsStrategy(SSLTestContexts.createServerSSLContext(), SecureAllPortsStrategy.INSTANCE))
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE_SERVER)
+                .setIOSessionDecorator(LoggingIOSessionDecorator.INSTANCE)
+                .setExceptionCallback(LoggingExceptionCallback.INSTANCE)
+                .setIOSessionListener(LoggingIOSessionListener.INSTANCE)
+                .register("*", new Supplier<AsyncServerExchangeHandler>() {
+
+                    @Override
+                    public AsyncServerExchangeHandler get() {
+                        return new EchoHandler(2048);
+                    }
+
+                })
+                .create();
+        server.start();
+
+        final AtomicReference<SSLSession> sslSessionRef = new AtomicReference<>(null);
+
+        requester = AsyncRequesterBootstrap.bootstrap()
+                .setIOReactorConfig(IOReactorConfig.custom()
+                        .setSoTimeout(TIMEOUT)
+                        .build())
+                .setTlsStrategy(new BasicClientTlsStrategy(
+                        SSLTestContexts.createClientSSLContext(),
+                        new SSLSessionVerifier() {
+
+                            @Override
+                            public TlsDetails verify(
+                                    final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
+                                sslSessionRef.set(sslEngine.getSession());
+                                return null;
+                            }
+
+                        }))
+                .setStreamListener(LoggingHttp1StreamListener.INSTANCE_CLIENT)
+                .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
+                .setIOSessionDecorator(LoggingIOSessionDecorator.INSTANCE)
+                .setExceptionCallback(LoggingExceptionCallback.INSTANCE)
+                .setIOSessionListener(LoggingIOSessionListener.INSTANCE)
+                .create();
+
+        server.start();
+        final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0));
+        final ListenerEndpoint listener = future.get();
+        final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
+        requester.start();
+
+        final HttpHost target = new HttpHost("https", "localhost", address.getPort());
+        final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
+                new BasicRequestProducer(Methods.POST, target, "/stuff",
+                        new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null);
+        final Message<HttpResponse, String> message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assert.assertThat(message1, CoreMatchers.notNullValue());
+        final HttpResponse response1 = message1.getHead();
+        Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+        final String body1 = message1.getBody();
+        Assert.assertThat(body1, CoreMatchers.equalTo("some stuff"));
+
+        final SSLSession sslSession = sslSessionRef.getAndSet(null);
+        final ProtocolVersion tlsVersion = TLS.parse(sslSession.getProtocol());
+        Assert.assertThat(tlsVersion.greaterEquals(TLS.V_1_2.version), CoreMatchers.equalTo(true));
+        Assert.assertThat(sslSession.getPeerPrincipal().getName(),
+                CoreMatchers.equalTo("CN=localhost,OU=Apache HttpComponents,O=Apache Software Foundation"));
+    }
+
+}