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 2014/10/14 11:25:29 UTC

svn commit: r1631694 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio: integration/TestCustomSSL.java testserver/HttpCoreNIOTestBase.java testserver/SSLTestContexts.java

Author: olegk
Date: Tue Oct 14 09:25:29 2014
New Revision: 1631694

URL: http://svn.apache.org/r1631694
Log:
Cleaned up test SSL code

Removed:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/testserver/SSLTestContexts.java
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java?rev=1631694&r1=1631693&r2=1631694&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java Tue Oct 14 09:25:29 2014
@@ -27,6 +27,17 @@
 
 package org.apache.http.nio.integration;
 
+import java.io.IOException;
+import java.math.BigInteger;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.util.concurrent.Future;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
@@ -44,23 +55,15 @@ import org.apache.http.nio.testserver.Cl
 import org.apache.http.nio.testserver.HttpClientNio;
 import org.apache.http.nio.testserver.HttpServerNio;
 import org.apache.http.nio.testserver.ServerConnectionFactory;
-import org.apache.http.nio.testserver.SSLTestContexts;
 import org.apache.http.nio.testserver.SimpleIOReactorExceptionHandler;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpCoreContext;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.ssl.SSLContextBuilder;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
 
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.net.InetSocketAddress;
-import java.util.concurrent.Future;
-
 public class TestCustomSSL {
 
     protected HttpServerNio server;
@@ -116,15 +119,22 @@ public class TestCustomSSL {
 
         };
 
-        this.server = new HttpServerNio(
-                new ServerConnectionFactory(
-                        SSLTestContexts.createServerSSLContext(), sslSetupHandler));
+        final URL keyStoreURL = getClass().getResource("/test.keystore");
+        final String storePassword = "nopassword";
+        final SSLContext serverSSLContext = SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray())
+                .build();
+        this.server = new HttpServerNio(new ServerConnectionFactory(serverSSLContext, sslSetupHandler));
         this.server.setExceptionHandler(new SimpleIOReactorExceptionHandler());
         this.server.setTimeout(5000);
+
+        final SSLContext clientSSLContext = SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .build();
+
         this.client = new HttpClientNio(
-                new BasicNIOConnFactory(
-                        new ClientConnectionFactory(
-                                SSLTestContexts.createClientSSLContext()), null));
+                new BasicNIOConnFactory(new ClientConnectionFactory(clientSSLContext), null));
         this.client.setExceptionHandler(new SimpleIOReactorExceptionHandler());
         this.client.setTimeout(5000);
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java?rev=1631694&r1=1631693&r2=1631694&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java Tue Oct 14 09:25:29 2014
@@ -27,7 +27,12 @@
 
 package org.apache.http.nio.testserver;
 
+import java.net.URL;
+
+import javax.net.ssl.SSLContext;
+
 import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
+import org.apache.http.ssl.SSLContextBuilder;
 import org.junit.After;
 
 /**
@@ -55,16 +60,32 @@ public abstract class HttpCoreNIOTestBas
         return this.scheme;
     }
 
+    protected SSLContext createServerSSLContext() throws Exception {
+        final URL keyStoreURL = getClass().getResource("/test.keystore");
+        final String storePassword = "nopassword";
+        return SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray())
+                .build();
+    }
+
+    protected SSLContext createClientSSLContext() throws Exception {
+        final URL keyStoreURL = getClass().getResource("/test.keystore");
+        final String storePassword = "nopassword";
+        return SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .build();
+    }
+
     protected ServerConnectionFactory createServerConnectionFactory() throws Exception {
         return new ServerConnectionFactory(
-                this.scheme.equals(ProtocolScheme.https) ? SSLTestContexts.createServerSSLContext() : null);
+                this.scheme.equals(ProtocolScheme.https) ? createServerSSLContext() : null);
     }
 
     protected BasicNIOConnFactory createClientConnectionFactory() throws Exception {
         return new BasicNIOConnFactory(
                 new ClientConnectionFactory(),
-                this.scheme.equals(ProtocolScheme.https) ? new ClientConnectionFactory(
-                        SSLTestContexts.createClientSSLContext()) : null);
+                this.scheme.equals(ProtocolScheme.https) ? new ClientConnectionFactory(createClientSSLContext()) : null);
 
     }