You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2017/05/04 22:30:05 UTC

svn commit: r1793914 - in /httpcomponents/httpcore/branches/4.4.x/httpcore/src: main/java/org/apache/http/ssl/SSLContextBuilder.java test/java/org/apache/http/ssl/TestSSLContextBuilder.java

Author: ggregory
Date: Thu May  4 22:30:05 2017
New Revision: 1793914

URL: http://svn.apache.org/viewvc?rev=1793914&view=rev
Log:
[HTTPCORE-450] Add a Provider parameter in SSLContextBuilder. Add SSLContextBuilder.setProvider(String).

Modified:
    httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java
    httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java

Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java?rev=1793914&r1=1793913&r2=1793914&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/ssl/SSLContextBuilder.java Thu May  4 22:30:05 2017
@@ -41,6 +41,7 @@ import java.security.Principal;
 import java.security.PrivateKey;
 import java.security.Provider;
 import java.security.SecureRandom;
+import java.security.Security;
 import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
@@ -122,6 +123,11 @@ public class SSLContextBuilder {
         return this;
     }
 
+    public SSLContextBuilder setProvider(final String name) {
+        this.provider = Security.getProvider(name);
+        return this;
+    }
+
     public SSLContextBuilder loadTrustMaterial(
             final KeyStore truststore,
             final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException {

Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java?rev=1793914&r1=1793913&r2=1793914&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/ssl/TestSSLContextBuilder.java Thu May  4 22:30:05 2017
@@ -631,4 +631,16 @@ public class TestSSLContextBuilder {
         Assert.assertTrue(sslContext.getProvider().getName().equals("SunJSSE"));
     }
 
+    @Test
+    public void testBuildWithProviderName() throws Exception {
+        final URL resource1 = getClass().getResource("/test-server.keystore");
+        final String storePassword = "nopassword";
+        final String keyPassword = "nopassword";
+        final SSLContext sslContext=SSLContextBuilder.create()
+                .setProvider("SunJSSE")
+                .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray())
+                .build();
+        Assert.assertTrue(sslContext.getProvider().getName().equals("SunJSSE"));
+    }
+
 }