01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: *
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package javax.rmi.ssl;
20:
21: import java.io.IOException;
22: import java.io.Serializable;
23: import java.net.Socket;
24: import java.rmi.server.RMIClientSocketFactory;
25: import java.security.AccessController;
26:
27: import javax.net.ssl.SSLSocket;
28: import javax.net.ssl.SSLSocketFactory;
29:
30: import org.apache.harmony.rmi.internal.nls.Messages;
31:
32: public class SslRMIClientSocketFactory implements
33: RMIClientSocketFactory, Serializable {
34:
35: private static final long serialVersionUID = -8310631444933958385L;
36:
37: private static SSLSocketFactory factory;
38:
39: public SslRMIClientSocketFactory() {
40: if (factory == null) {
41: factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
42: }
43: }
44:
45: public Socket createSocket(String host, int port)
46: throws IOException {
47:
48: SSLSocket soc = (SSLSocket) factory.createSocket(host, port);
49: String[] enabled = AccessController
50: .doPrivileged(new java.security.PrivilegedAction<String[]>() {
51: public String[] run() {
52: return new String[] {
53: System
54: .getProperty("javax.rmi.ssl.client.enabledCipherSuites"), //$NON-NLS-1$
55: System
56: .getProperty("javax.rmi.ssl.client.enabledProtocols") }; //$NON-NLS-1$
57: }
58: });
59: try {
60: if (enabled[0] != null) { //enabledCipherSuites
61: soc.setEnabledCipherSuites(enabled[0].split(",")); //$NON-NLS-1$
62: }
63:
64: if (enabled[1] != null) { //enabledProtocols
65: soc.setEnabledProtocols(enabled[1].split(",")); //$NON-NLS-1$
66: }
67: } catch (IllegalArgumentException e) {
68: // rmi.96=Error in socket creation
69: IOException ioe = new IOException(Messages
70: .getString("rmi.96")); //$NON-NLS-1$
71: ioe.initCause(e);
72: soc.close();
73: throw ioe;
74: }
75:
76: return soc;
77: }
78:
79: public boolean equals(Object obj) {
80: return this .getClass().equals(obj.getClass());
81: }
82:
83: public int hashCode() {
84: return "javax.rmi.ssl.SslRMIClientSocketFactory".hashCode(); //$NON-NLS-1$
85: }
86:
87: }
|