luehe       2003/08/08 16:40:17

  Modified:    util/java/org/apache/tomcat/util/net/jsse
                        JSSE14SocketFactory.java
  Log:
  Allow for customization of JSSE trust and key managers.
  
  Revision  Changes    Path
  1.5       +41 -17    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/jsse/JSSE14SocketFactory.java
  
  Index: JSSE14SocketFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/jsse/JSSE14SocketFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JSSE14SocketFactory.java  18 Jul 2003 05:26:45 -0000      1.4
  +++ JSSE14SocketFactory.java  8 Aug 2003 23:40:17 -0000       1.5
  @@ -71,6 +71,7 @@
   import javax.net.ssl.HandshakeCompletedEvent;
   import javax.net.ssl.TrustManagerFactory;
   import javax.net.ssl.SSLContext;
  +import javax.net.ssl.KeyManager;
   import javax.net.ssl.KeyManagerFactory;
   import javax.net.ssl.TrustManager;
   
  @@ -116,27 +117,13 @@
               String algorithm = (String)attributes.get("algorithm");
               if (algorithm == null) algorithm = defaultAlgorithm;
   
  -            // Set up KeyManager, which will extract server key
  -            KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
               String keystoreType = (String)attributes.get("keystoreType");
  -            if (keystoreType == null)
  -                keystoreType = defaultKeystoreType;
  -            String keystorePass = getKeystorePassword();
  -            kmf.init(getKeystore(keystoreType, keystorePass),
  -                     keystorePass.toCharArray());
  -
  -            // Set up TrustManager
  -            TrustManager[] tm = null;
  -            KeyStore trustStore = getTrustStore(keystoreType);
  -            if (trustStore != null) {
  -                TrustManagerFactory tmf = 
TrustManagerFactory.getInstance("SunX509");
  -                tmf.init(trustStore);
  -                tm = tmf.getTrustManagers();
  -            }
   
               // Create and init SSLContext
               SSLContext context = SSLContext.getInstance(protocol); 
  -            context.init(kmf.getKeyManagers(), tm, new SecureRandom());
  +            context.init(getKeyManagers(keystoreType, algorithm),
  +                         getTrustManagers(keystoreType),
  +                         new SecureRandom());
   
               // create proxy
               sslProxy = context.getServerSocketFactory();
  @@ -151,4 +138,41 @@
           }
       }
   
  +    /**
  +     * Gets the initialized key managers.
  +     */
  +    protected KeyManager[] getKeyManagers(String keystoreType,
  +                                          String algorithm)
  +                throws Exception {
  +
  +        if (keystoreType == null) {
  +            keystoreType = defaultKeystoreType;
  +        }
  +
  +        String keystorePass = getKeystorePassword();
  +
  +        KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
  +        kmf.init(getKeystore(keystoreType, keystorePass),
  +                 keystorePass.toCharArray());
  +
  +        return kmf.getKeyManagers();
  +    }
  +
  +    /**
  +     * Gets the intialized trust managers.
  +     */
  +    protected TrustManager[] getTrustManagers(String keystoreType)
  +                throws Exception {
  +
  +        TrustManager[] tm = null;
  +
  +        KeyStore trustStore = getTrustStore(keystoreType);
  +        if (trustStore != null) {
  +            TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
  +            tmf.init(trustStore);
  +            tm = tmf.getTrustManagers();
  +        }
  +
  +        return tm;
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to