1 16 17 package org.apache.tomcat.util.net.jsse; 18 19 import java.io.IOException ; 20 import java.security.KeyStore ; 21 import java.security.SecureRandom ; 22 import java.security.Security ; 23 import java.security.Provider ; 24 25 import javax.net.ssl.SSLServerSocket; 26 import javax.net.ssl.SSLSocket; 27 28 35 36 46 public class JSSE13SocketFactory extends JSSESocketFactory 47 { 48 51 protected boolean clientAuth = false; 52 53 public JSSE13SocketFactory () { 54 super(); 55 } 56 57 68 void init() throws IOException { 69 try { 70 try { 71 Class ssps = Class.forName("sun.security.provider.Sun"); 72 Security.addProvider ((Provider )ssps.newInstance()); 73 }catch(Exception cnfe) { 74 } 76 Security.addProvider (new com.sun.net.ssl.internal.ssl.Provider()); 77 78 String clientAuthStr = (String )attributes.get("clientauth"); 79 if("true".equalsIgnoreCase(clientAuthStr) || 80 "yes".equalsIgnoreCase(clientAuthStr) || 81 "want".equalsIgnoreCase(clientAuthStr)) { 82 clientAuth = true; 83 } 84 85 String protocol = (String )attributes.get("protocol"); 87 if (protocol == null) protocol = defaultProtocol; 88 89 String algorithm = (String )attributes.get("algorithm"); 91 if (algorithm == null) algorithm = defaultAlgorithm; 92 93 com.sun.net.ssl.KeyManagerFactory kmf = 95 com.sun.net.ssl.KeyManagerFactory.getInstance(algorithm); 96 String keystoreType = (String )attributes.get("keystoreType"); 97 if (keystoreType == null) { 98 keystoreType = defaultKeystoreType; 99 } 100 String keystorePass = getKeystorePassword(); 101 kmf.init(getKeystore(keystoreType, keystorePass), 102 keystorePass.toCharArray()); 103 104 com.sun.net.ssl.TrustManager[] tm = null; 106 String truststoreType = (String )attributes.get("truststoreType"); 107 if(truststoreType == null) { 108 truststoreType = keystoreType; 109 } 110 KeyStore trustStore = getTrustStore(truststoreType); 111 if (trustStore != null) { 112 com.sun.net.ssl.TrustManagerFactory tmf = 113 com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509"); 114 tmf.init(trustStore); 115 tm = tmf.getTrustManagers(); 116 } 117 118 com.sun.net.ssl.SSLContext context = 120 com.sun.net.ssl.SSLContext.getInstance(protocol); 121 context.init(kmf.getKeyManagers(), tm, new SecureRandom ()); 122 123 sslProxy = context.getServerSocketFactory(); 125 126 String requestedCiphers = (String )attributes.get("ciphers"); 128 enabledCiphers = getEnabledCiphers(requestedCiphers, 129 sslProxy.getSupportedCipherSuites()); 130 131 } catch(Exception e) { 132 if( e instanceof IOException ) 133 throw (IOException )e; 134 throw new IOException (e.getMessage()); 135 } 136 } 137 protected String [] getEnabledProtocols(SSLServerSocket socket, 138 String requestedProtocols){ 139 return null; 140 } 141 protected void setEnabledProtocols(SSLServerSocket socket, 142 String [] protocols){ 143 } 144 145 protected void configureClientAuth(SSLServerSocket socket){ 146 socket.setNeedClientAuth(clientAuth); 147 } 148 149 protected void configureClientAuth(SSLSocket socket){ 150 socket.setNeedClientAuth(clientAuth); 154 } 155 156 } 157 | Popular Tags |