abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r555438 - /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/ClientAuthSSLProtocolSocketFactory.java
Date Wed, 11 Jul 2007 23:48:40 GMT
Author: jmsnell
Date: Wed Jul 11 16:48:39 2007
New Revision: 555438

URL: http://svn.apache.org/viewvc?view=rev&rev=555438
Log:
Make it easy to create a ClientAuthSSLProtocolSocketFactory instance

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/ClientAuthSSLProtocolSocketFactory.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/ClientAuthSSLProtocolSocketFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/ClientAuthSSLProtocolSocketFactory.java?view=diff&rev=555438&r1=555437&r2=555438
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/ClientAuthSSLProtocolSocketFactory.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/ClientAuthSSLProtocolSocketFactory.java
Wed Jul 11 16:48:39 2007
@@ -40,28 +40,57 @@
 public class ClientAuthSSLProtocolSocketFactory 
   implements SecureProtocolSocketFactory {
 
-  private String keyStore = null;
-  private String keyStoreType = null;
-  private String keyPass = null;
   private String protocol = "TLS";
   private String kmfFactory = "ibmX509";
   private TrustManager tm = null;
   
+  private final String keyStorePass;
+  private final KeyStore ks;
+  
+  public ClientAuthSSLProtocolSocketFactory(KeyStore ks, String keyStorePass) {
+    this(ks,keyStorePass,"TLS","ibmX509",null);
+  }
+  
   public ClientAuthSSLProtocolSocketFactory(
-    String keyStore, 
-    String keyStoreType,
-    String keyPass,
-    String protocol,
+    KeyStore ks, 
+    String keyStorePass,
+    String protocol, 
     String kmfFactory,
     TrustManager tm) {
-      this.keyStore = keyStore;
-      this.keyStoreType = keyStoreType;
-      this.keyPass = keyPass;
+      if (ks == null) throw new IllegalArgumentException("Invalid Keystore");
+      this.ks = ks;
+      this.keyStorePass = keyStorePass;
       if (protocol != null) this.protocol = protocol;
       if (kmfFactory != null) this.kmfFactory = kmfFactory;
       if (tm != null) this.tm = tm;
   }
   
+  public ClientAuthSSLProtocolSocketFactory(
+    String keyStore, 
+    String keyStoreType,
+    String keyStorePass,
+    String protocol,
+    String kmfFactory,
+    TrustManager tm) {
+      this(
+        initKeyStore(keyStore,keyStoreType,keyStorePass),
+        keyStorePass,
+        protocol,
+        kmfFactory,tm);
+  }
+  
+  private static KeyStore initKeyStore(
+    String keyStore, 
+    String keyStoreType, 
+    String keyPass) {
+      KeyStore ks = null;
+      try {
+        ks = KeyStore.getInstance(keyStoreType);
+        ks.load(new FileInputStream(keyStore), keyPass.toCharArray());
+      } catch (Exception e) {}
+      return ks;
+  }
+  
   public Socket createSocket(
     Socket socket, 
     String host, 
@@ -105,13 +134,9 @@
     SSLSocket socket = null;
     try {
       KeyManagerFactory kmf;
-      KeyStore ks;
-      char[] passphrase = keyPass.toCharArray();
 
       context = SSLContext.getInstance(protocol);
       kmf = KeyManagerFactory.getInstance(kmfFactory);
-      ks = KeyStore.getInstance(keyStoreType);
-      ks.load(new FileInputStream(keyStore), passphrase);
 
       TrustManager tm = (this.tm != null) ? this.tm : new X509TrustManager() {
         public void checkClientTrusted(X509Certificate[] arg0, String arg1) 
@@ -123,7 +148,7 @@
         }
       };
       
-      kmf.init(ks, passphrase);
+      kmf.init(ks, keyStorePass.toCharArray());
       context.init(kmf.getKeyManagers(), new TrustManager[] {tm}, null);
       
       factory = context.getSocketFactory();



Mime
View raw message