1 10 11 package javax.rmi.ssl; 12 13 import java.io.IOException ; 14 import java.io.Serializable ; 15 import java.net.Socket ; 16 import java.rmi.server.RMIClientSocketFactory ; 17 import java.util.StringTokenizer ; 18 import javax.net.SocketFactory; 19 import javax.net.ssl.SSLSocket; 20 import javax.net.ssl.SSLSocketFactory; 21 22 58 public class SslRMIClientSocketFactory 59 implements RMIClientSocketFactory , Serializable { 60 61 64 public SslRMIClientSocketFactory() { 65 } 79 80 99 public Socket createSocket(String host, int port) throws IOException { 100 final SocketFactory sslSocketFactory = getDefaultClientSocketFactory(); 103 final SSLSocket sslSocket = (SSLSocket) 106 sslSocketFactory.createSocket(host, port); 107 final String enabledCipherSuites = (String ) 110 System.getProperty("javax.rmi.ssl.client.enabledCipherSuites"); 111 if (enabledCipherSuites != null) { 112 StringTokenizer st = new StringTokenizer (enabledCipherSuites, ","); 113 int tokens = st.countTokens(); 114 String enabledCipherSuitesList[] = new String [tokens]; 115 for (int i = 0 ; i < tokens; i++) { 116 enabledCipherSuitesList[i] = st.nextToken(); 117 } 118 try { 119 sslSocket.setEnabledCipherSuites(enabledCipherSuitesList); 120 } catch (IllegalArgumentException e) { 121 throw (IOException ) 122 new IOException (e.getMessage()).initCause(e); 123 } 124 } 125 final String enabledProtocols = (String ) 128 System.getProperty("javax.rmi.ssl.client.enabledProtocols"); 129 if (enabledProtocols != null) { 130 StringTokenizer st = new StringTokenizer (enabledProtocols, ","); 131 int tokens = st.countTokens(); 132 String enabledProtocolsList[] = new String [tokens]; 133 for (int i = 0 ; i < tokens; i++) { 134 enabledProtocolsList[i] = st.nextToken(); 135 } 136 try { 137 sslSocket.setEnabledProtocols(enabledProtocolsList); 138 } catch (IllegalArgumentException e) { 139 throw (IOException ) 140 new IOException (e.getMessage()).initCause(e); 141 } 142 } 143 return sslSocket; 146 } 147 148 160 public boolean equals(Object obj) { 161 if (obj == null) return false; 162 if (obj == this) return true; 163 return this.getClass().equals(obj.getClass()); 164 } 165 166 173 public int hashCode() { 174 return this.getClass().hashCode(); 175 } 176 177 private static SocketFactory defaultSocketFactory = null; 189 190 private static synchronized SocketFactory getDefaultClientSocketFactory() { 191 if (defaultSocketFactory == null) 192 defaultSocketFactory = SSLSocketFactory.getDefault(); 193 return defaultSocketFactory; 194 } 195 196 private static final long serialVersionUID = -8310631444933958385L; 197 } 198 | Popular Tags |