1 23 package com.sun.web.security; 24 25 import java.io.*; 26 import java.net.*; 27 import java.security.KeyStore ; 28 import java.security.SecureRandom ; 29 30 import javax.net.ssl.HandshakeCompletedListener; 31 import javax.net.ssl.HandshakeCompletedEvent; 32 import javax.net.ssl.KeyManager; 33 import javax.net.ssl.SSLContext; 34 import javax.net.ssl.SSLServerSocket; 35 import javax.net.ssl.SSLServerSocketFactory; 36 import javax.net.ssl.TrustManager; 37 import org.apache.catalina.net.ServerSocketFactory; 38 import com.sun.enterprise.log.Log; 39 import com.sun.enterprise.util.LocalStringManagerImpl; 40 import com.sun.enterprise.security.SSLUtils; 41 import com.sun.enterprise.ServerConfiguration; 42 import com.sun.web.server.*; 43 import com.sun.enterprise.server.J2EEServer; 44 import java.util.logging.*; 45 import com.sun.logging.*; 46 47 48 55 56 public class SSLSocketFactory implements org.apache.catalina.net.ServerSocketFactory { 57 58 static Logger _logger=LogDomains.getLogger(LogDomains.WEB_LOGGER); 59 60 private static final boolean clientAuth = false; 61 62 private static LocalStringManagerImpl localStrings = 63 new LocalStringManagerImpl(SSLSocketFactory.class); 64 65 private SSLContext context = null; 66 private javax.net.ssl.SSLServerSocketFactory factory = null; 67 private String cipherSuites[]; 68 private static SecureRandom sr = J2EEServer.secureRandom; 69 private static KeyManager[] keyManagers = null; 70 private static TrustManager[] trustManagers = null; 71 72 73 77 public SSLSocketFactory () { 78 try { 79 if(keyManagers == null || trustManagers == null) { 80 SSLUtils.initStoresAtStartup(); 81 } 82 context = SSLContext.getInstance("TLS"); 83 context.init(keyManagers, trustManagers, sr); 84 85 factory = context.getServerSocketFactory(); 86 cipherSuites = factory.getSupportedCipherSuites(); 87 88 for(int i=0; i < cipherSuites.length; ++i) { 89 if (_logger.isLoggable(Level.FINEST)) { 90 _logger.log(Level.FINEST,"Suite: " + cipherSuites[i]); 91 } 92 } 93 94 } catch(Exception e) { 95 _logger.log(Level.SEVERE, 96 "web_security.excep_sslsockfact", e.getMessage()); 97 } 98 } 99 100 105 public ServerSocket createSocket (int port) 106 throws IOException 107 { 108 SSLServerSocket socket = 109 (SSLServerSocket) factory.createServerSocket(port); 110 init(socket); 111 return socket; 112 } 113 114 118 private void init(SSLServerSocket socket) { 119 socket.setNeedClientAuth(clientAuth); 122 } 123 124 129 public ServerSocket createSocket (int port, int backlog) 130 throws IOException 131 { 132 SSLServerSocket socket = (SSLServerSocket) 133 factory.createServerSocket(port, backlog); 134 init(socket); 135 return socket; 136 } 137 138 143 public ServerSocket createSocket (int port, int backlog, InetAddress ifAddress) 144 throws IOException 145 { 146 SSLServerSocket socket = (SSLServerSocket) 147 factory.createServerSocket(port, backlog, ifAddress); 148 init(socket); 149 return socket; 150 } 151 152 public static void setManagers(KeyManager[] kmgrs, TrustManager[] tmgrs) { 153 keyManagers = kmgrs; 154 trustManagers = tmgrs; 155 } 156 } 157 | Popular Tags |