hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1783809 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TrustAllStrategy.java httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
Date Mon, 20 Feb 2017 22:50:39 GMT
Author: ggregory
Date: Mon Feb 20 22:50:39 2017
New Revision: 1783809

URL: http://svn.apache.org/viewvc?rev=1783809&view=rev
Log:
[HTTPCLIENT-1817] Add a "Trust All" TrustStrategy implementation.

Added:
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TrustAllStrategy.java
Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1783809&r1=1783808&r2=1783809&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Mon Feb 20 22:50:39 2017
@@ -16,6 +16,9 @@ Changelog:
 * [HTTPCLIENT-1786] Port from Apache Commons Logging to Apache Log4j 2.
   Contributed by Gary Gregory <ggregory at apache.org>
 
+* [HTTPCLIENT-1817] Add a "Trust All" TrustStrategy implementation.
+  Contributed by Gary Gregory <ggregory at apache.org>
+
 Release 5.0-ALPHA1
 -------------------
 

Added: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TrustAllStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TrustAllStrategy.java?rev=1783809&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TrustAllStrategy.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/TrustAllStrategy.java
Mon Feb 20 22:50:39 2017
@@ -0,0 +1,51 @@
+/*
+ * ====================================================================
+ * 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.client5.http.ssl;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import org.apache.hc.core5.ssl.TrustStrategy;
+
+/**
+ * A trust strategy that accepts all certificates as trusted. Verification of
+ * all other certificates is done by the trust manager configured in the SSL
+ * context.
+ *
+ * @since 4.5.4
+ * @since 5.0-alpha2
+ */
+public class TrustAllStrategy implements TrustStrategy {
+
+	public static final TrustAllStrategy INSTANCE = new TrustAllStrategy();
+
+	@Override
+	public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException
{
+		return true;
+	}
+
+}

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java?rev=1783809&r1=1783808&r2=1783809&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
Mon Feb 20 22:50:39 2017
@@ -30,6 +30,9 @@ package org.apache.hc.client5.http.ssl;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.util.concurrent.TimeUnit;
@@ -200,14 +203,7 @@ public class TestSSLSocketFactory {
     }
 
     @Test
-    public void testSSLTrustVerificationOverride() throws Exception {
-        this.server = ServerBootstrap.bootstrap()
-                .setSslContext(SSLTestContexts.createServerSSLContext())
-                .create();
-        this.server.start();
-
-        final HttpContext context = new BasicHttpContext();
-
+    public void testSSLTrustVerificationOverrideWithCustsom() throws Exception {
         final TrustStrategy trustStrategy = new TrustStrategy() {
 
             @Override
@@ -217,6 +213,28 @@ public class TestSSLSocketFactory {
             }
 
         };
+        testSSLTrustVerificationOverride(trustStrategy);
+    }
+
+    @Test
+    public void testSSLTrustVerificationOverrideWithTrustSelfSignedStrategy() throws Exception
{
+        testSSLTrustVerificationOverride(TrustSelfSignedStrategy.INSTANCE);
+    }
+
+    @Test
+    public void testSSLTrustVerificationOverrideWithTrustAllStrategy() throws Exception {
+        testSSLTrustVerificationOverride(TrustAllStrategy.INSTANCE);
+    }
+
+	private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
+			throws Exception, IOException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException
{
+		this.server = ServerBootstrap.bootstrap()
+                .setSslContext(SSLTestContexts.createServerSSLContext())
+                .create();
+        this.server.start();
+
+        final HttpContext context = new BasicHttpContext();
+
         final SSLContext sslcontext = SSLContexts.custom()
             .loadTrustMaterial(null, trustStrategy)
             .build();
@@ -229,7 +247,7 @@ public class TestSSLSocketFactory {
         final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
         final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress, null, context);
         sslSocket.close();
-    }
+	}
 
     @Test
     public void testTLSOnly() throws Exception {



Mime
View raw message