You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rw...@apache.org on 2008/04/28 00:08:55 UTC

svn commit: r652024 - /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java

Author: rwinston
Date: Sun Apr 27 15:08:53 2008
New Revision: 652024

URL: http://svn.apache.org/viewvc?rev=652024&view=rev
Log:
NET-216

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java?rev=652024&r1=652023&r2=652024&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java (original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPSClient.java Sun Apr 27 15:08:53 2008
@@ -95,7 +95,6 @@
     public FTPSClient() throws NoSuchAlgorithmException {
         this.protocol = DEFAULT_PROTOCOL;
         this.isImplicit = false;
-        context = SSLContext.getInstance(protocol);
     }
 
     /**
@@ -107,7 +106,6 @@
     public FTPSClient(boolean isImplicit) throws NoSuchAlgorithmException {
         this.protocol = DEFAULT_PROTOCOL;
         this.isImplicit = isImplicit;
-        context = SSLContext.getInstance(protocol);
     }
 
     /**
@@ -119,7 +117,6 @@
     public FTPSClient(String protocol) throws NoSuchAlgorithmException {
         this.protocol = protocol;
         this.isImplicit = false;
-        context = SSLContext.getInstance(protocol);
     }
 
     /**
@@ -133,7 +130,6 @@
             throws NoSuchAlgorithmException {
         this.protocol = protocol;
         this.isImplicit = isImplicit;
-        context = SSLContext.getInstance(protocol);
     }
 
 
@@ -193,6 +189,28 @@
     }
 
     /**
+     * Performs a lazy init of the SSL context 
+     * @throws IOException 
+     */
+    private void initSslContext() throws IOException {
+        if(context == null) {
+            try  {
+                context = SSLContext.getInstance(protocol);
+    
+                context.init(new KeyManager[] { getKeyManager() } , new TrustManager[] { getTrustManager() } , null);
+            } catch (KeyManagementException e) {
+                IOException ioe = new IOException("Could not initialize SSL context");
+                ioe.initCause(e);
+                throw ioe;
+            } catch (NoSuchAlgorithmException e) {
+                IOException ioe = new IOException("Could not initialize SSL context");
+                ioe.initCause(e);
+                throw ioe;
+            }
+        }
+    }
+    
+    /**
      * SSL/TLS negotiation. Acquires an SSL socket of a control 
      * connection and carries out handshake processing.
      * @throws IOException A handicap breaks out by sever negotiation.
@@ -201,11 +219,7 @@
         // Evacuation not ssl socket.
         planeSocket = _socket_;
         
-        try {
-			context.init(new KeyManager[] { getKeyManager() } , new TrustManager[] { getTrustManager() } , null);
-		} catch (KeyManagementException e) {
-			e.printStackTrace();
-		}
+        initSslContext();
 
         SSLSocketFactory ssf = context.getSocketFactory();
         String ip = _socket_.getInetAddress().getHostAddress();
@@ -414,7 +428,12 @@
             setServerSocketFactory(null);
         } else {
             setSocketFactory(new FTPSSocketFactory(context));
-            setServerSocketFactory(SSLServerSocketFactory.getDefault());
+
+            initSslContext();
+            
+            SSLServerSocketFactory ssf = context.getServerSocketFactory();
+
+            setServerSocketFactory(ssf);
         }
     }