1 23 24 39 40 package com.sun.enterprise.admin.server.core.jmx.ssl; 41 42 import java.net.ServerSocket ; 43 import java.net.InetAddress ; 44 import javax.net.ssl.SSLServerSocket; 45 import javax.net.ssl.SSLServerSocketFactory; 46 import java.io.IOException ; 47 import java.rmi.server.RMIServerSocketFactory ; 48 import javax.net.ssl.KeyManager; 49 import javax.net.ssl.SSLContext; 50 import javax.net.ssl.TrustManager; 51 import javax.net.ssl.X509KeyManager; 52 import com.sun.enterprise.config.serverbeans.Ssl; 53 54 55 import com.sun.enterprise.server.pluggable.SecuritySupport; 56 import com.sun.enterprise.security.SecurityUtil; 57 import com.sun.enterprise.security.SSLUtils; 58 import com.sun.enterprise.security.ssl.J2EEKeyManager; 59 import java.security.SecureRandom ; 60 61 62 63 64 72 public class AdminSslServerSocketFactory implements RMIServerSocketFactory { 73 private final Ssl sslc; 74 75 private static final String DEFAULT_ADDRESS = "0.0.0.0"; 76 private String address = DEFAULT_ADDRESS; 77 78 public AdminSslServerSocketFactory(final Ssl sslc, String address) { 79 if (sslc == null) 80 throw new IllegalArgumentException ("Internal: null ssl configuration"); 81 this.sslc = sslc; 82 this.address = address; 83 } 84 85 89 public ServerSocket createServerSocket(final int port) throws IOException { 90 try { 91 95 final SSLContext ctx = SSLContext.getInstance("TLSv1"); 97 final KeyManager[] kms = SSLUtils.getKeyManagers(); 99 J2EEKeyManager[] jkms = new J2EEKeyManager[kms.length]; 100 for (int i = 0; i < kms.length; i++) { 101 jkms[i] = new J2EEKeyManager((X509KeyManager)kms[i], sslc.getCertNickname()); 102 } 103 final TrustManager[] tms = null; final SecureRandom sr = null; ctx.init(jkms, tms, sr); 107 final SSLServerSocketFactory sf = ctx.getServerSocketFactory(); 108 109 InetAddress bindAddress = null; 110 ServerSocket sss = null; 111 if (address.equals(DEFAULT_ADDRESS)) 112 sss = sf.createServerSocket(port); 113 else { 114 bindAddress = InetAddress.getByName(address); 115 sss = sf.createServerSocket(port, 0, bindAddress); 116 } 117 debug(sss); 118 return ( sss ); 119 } 120 catch (final Exception e) { 121 throw new IOException (e.getMessage()); 122 } 123 } 124 private void debug (final ServerSocket sss) { 125 final String prefix = "RMI/TLS Server Debug Message: " ; 127 final boolean DEBUG = Boolean.getBoolean("Debug"); 128 if (sss != null) { 129 if (DEBUG) { 130 System.out.println(prefix + "ServerSocket local port = " + sss.getLocalPort()); 131 System.out.println(prefix + "ServerSocket host address = " + sss.getInetAddress().getHostAddress()); 132 System.out.println(prefix + "ServerSocket bound status = " + sss.isBound()); 133 } 134 } 135 else { 136 System.out.println(prefix + " Catastrophe: no server socket"); 137 } 138 } 139 } 140 | Popular Tags |