hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [24/50] httpcomponents-core git commit: [HTTPCORE-450] Add a Provider parameter in SSLContextBuilder.
Date Tue, 09 May 2017 20:01:50 GMT
[HTTPCORE-450] Add a Provider parameter in SSLContextBuilder.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1790053
13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/d2ac506f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/d2ac506f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/d2ac506f

Branch: refs/heads/4.4.x
Commit: d2ac506f990911c56a19ae94f78daddd18dff494
Parents: 0962ff4
Author: Gary D. Gregory <ggregory@apache.org>
Authored: Mon Apr 3 22:13:57 2017 +0000
Committer: Gary D. Gregory <ggregory@apache.org>
Committed: Mon Apr 3 22:13:57 2017 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt                                   | 12 ++++++++++++
 .../java/org/apache/http/ssl/SSLContextBuilder.java | 16 ++++++++++++++--
 .../org/apache/http/ssl/TestSSLContextBuilder.java  | 13 +++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d2ac506f/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index d4e9264..46173c4 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,3 +1,15 @@
+Release 4.4.7
+-------------------
+
+This is a maintenance release that fixes a number of issues discovered since 4.4.6.
+
+Changelog
+-------------------
+
+* HTTPCORE-450: Add a Provider parameter in SSLContextBuilder.
+  Contributed by lujianbo <387852424 at qq dot com>, Gary Gregory <ggregory at apache.org>
+
+
 Release 4.4.6
 -------------------
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d2ac506f/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java b/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java
index 067a0c4..2fe30b9 100644
--- a/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java
+++ b/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java
@@ -39,6 +39,7 @@ import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 import java.security.Principal;
 import java.security.PrivateKey;
+import java.security.Provider;
 import java.security.SecureRandom;
 import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
@@ -80,6 +81,7 @@ public class SSLContextBuilder {
     private final Set<KeyManager> keymanagers;
     private final Set<TrustManager> trustmanagers;
     private SecureRandom secureRandom;
+    private Provider provider;
 
     public static SSLContextBuilder create() {
         return new SSLContextBuilder();
@@ -101,6 +103,11 @@ public class SSLContextBuilder {
         return this;
     }
 
+    public SSLContextBuilder setProvider(final Provider provider) {
+        this.provider = provider;
+        return this;
+    }
+
     public SSLContextBuilder loadTrustMaterial(
             final KeyStore truststore,
             final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException
{
@@ -266,8 +273,13 @@ public class SSLContextBuilder {
     }
 
     public SSLContext build() throws NoSuchAlgorithmException, KeyManagementException {
-        final SSLContext sslcontext = SSLContext.getInstance(
-                this.protocol != null ? this.protocol : TLS);
+        final SSLContext sslcontext;
+        final String protocolStr = this.protocol != null ? this.protocol : TLS;
+        if (this.provider != null) {
+            sslcontext = SSLContext.getInstance(protocolStr, this.provider);
+        } else {
+            sslcontext = SSLContext.getInstance(protocolStr);
+        }
         initSSLContext(sslcontext, keymanagers, trustmanagers, secureRandom);
         return sslcontext;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d2ac506f/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java b/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java
index 61992be..ae132f0 100644
--- a/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java
+++ b/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java
@@ -37,6 +37,7 @@ import java.net.SocketException;
 import java.net.URL;
 import java.security.KeyStore;
 import java.security.Principal;
+import java.security.Security;
 import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
@@ -618,4 +619,16 @@ public class TestSSLContextBuilder {
         }
     }
 
+    @Test
+    public void testBuildWithProvider() throws Exception {
+        final URL resource1 = getClass().getResource("/test-server.keystore");
+        final String storePassword = "nopassword";
+        final String keyPassword = "nopassword";
+        final SSLContext sslContext=SSLContextBuilder.create()
+                .setProvider(Security.getProvider("SunJSSE"))
+                .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray())
+                .build();
+        Assert.assertTrue(sslContext.getProvider().getName().equals("SunJSSE"));
+    }
+
 }


Mime
View raw message