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 2009/10/30 15:35:05 UTC
svn commit: r831313 -
/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
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();