hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r831313 - /httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
Date Fri, 30 Oct 2009 14:35:05 GMT
Author: olegk
Date: Fri Oct 30 14:35:04 2009
New Revision: 831313

URL: http://svn.apache.org/viewvc?rev=831313&view=rev
Log:
SSL test cases to fall back onto SunX509 implementation of SSL classes the default implementation
is not available / functional

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java?rev=831313&r1=831312&r2=831313&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
Fri Oct 30 14:35:04 2009
@@ -33,6 +33,7 @@
 import java.math.BigInteger;
 import java.security.KeyFactory;
 import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
@@ -100,6 +101,24 @@
         
     }
     
+    private KeyManagerFactory createKeyManagerFactory() throws NoSuchAlgorithmException {
+        String algo = KeyManagerFactory.getDefaultAlgorithm();
+        try {
+            return KeyManagerFactory.getInstance(algo);
+        } catch (NoSuchAlgorithmException ex) {
+            return KeyManagerFactory.getInstance("SunX509");
+        }
+    }
+    
+    private TrustManagerFactory createTrustManagerFactory() throws NoSuchAlgorithmException
{
+        String algo = TrustManagerFactory.getDefaultAlgorithm();
+        try {
+            return TrustManagerFactory.getInstance(algo);
+        } catch (NoSuchAlgorithmException ex) {
+            return TrustManagerFactory.getInstance("SunX509");
+        }
+    }
+    
     public void testCreateSocket() throws Exception {
         String password = "changeit";
         char[] pwd = password.toCharArray();
@@ -131,13 +150,11 @@
         ks.setKeyEntry("RSA_KEY", pk, pwd, chain);
         ks.setCertificateEntry("CERT", chain[2]); // Let's trust ourselves. :-)
 
-        KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory
-                .getDefaultAlgorithm());
+        KeyManagerFactory kmfactory = createKeyManagerFactory();
         kmfactory.init(ks, pwd);
         KeyManager[] keymanagers = kmfactory.getKeyManagers();
             
-        TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
-                TrustManagerFactory.getDefaultAlgorithm());
+        TrustManagerFactory tmfactory = createTrustManagerFactory();
         tmfactory.init(ks);
         TrustManager[] trustmanagers = tmfactory.getTrustManagers();
         



Mime
View raw message