001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.xnet.provider.jsse;
022:
023: import org.apache.harmony.xnet.provider.jsse.SSLSocketWrapper;
024:
025: import java.io.IOException;
026: import java.net.InetAddress;
027: import java.net.Socket;
028: import java.net.UnknownHostException;
029: import java.security.KeyManagementException;
030:
031: import javax.net.ssl.SSLSocketFactory;
032:
033: /**
034: * Implementation of SSLSocketFactory.
035: */
036: public class SSLSocketFactoryImpl extends SSLSocketFactory {
037:
038: private SSLParameters sslParameters;
039: private IOException instantiationException;
040:
041: /**
042: * Constructor.
043: */
044: public SSLSocketFactoryImpl() {
045: super ();
046: try {
047: sslParameters = SSLParameters.getDefault();
048: } catch (KeyManagementException e) {
049: instantiationException = new IOException(
050: "Delayed instantiation exception:");
051: instantiationException.initCause(e);
052: }
053: }
054:
055: /**
056: * Constructor.
057: */
058: protected SSLSocketFactoryImpl(SSLParameters sslParameters) {
059: super ();
060: this .sslParameters = sslParameters;
061: }
062:
063: /**
064: * @see javax.net.ssl.SSLSocketFactory#getDefaultCipherSuites()
065: */
066: public String[] getDefaultCipherSuites() {
067: if (instantiationException != null) {
068: return new String[0];
069: }
070: return sslParameters.getEnabledCipherSuites();
071: }
072:
073: /**
074: * @see javax.net.ssl.SSLSocketFactory#getSupportedCipherSuites()
075: */
076: public String[] getSupportedCipherSuites() {
077: if (instantiationException != null) {
078: return new String[0];
079: }
080: return CipherSuite.getSupportedCipherSuiteNames();
081: }
082:
083: /**
084: * @see javax.net.ssl.SSLSocketFactory#createSocket(Socket,String,int,boolean)
085: */
086: public Socket createSocket(Socket s, String host, int port,
087: boolean autoClose) throws IOException {
088: if (instantiationException != null) {
089: throw instantiationException;
090: }
091: return new SSLSocketWrapper(s, autoClose,
092: (SSLParameters) sslParameters.clone());
093: }
094:
095: // -------------- Methods inherided from SocketFactory --------------
096:
097: /**
098: * @see javax.net.SocketFactory#createSocket()
099: */
100: public Socket createSocket() throws IOException {
101: if (instantiationException != null) {
102: throw instantiationException;
103: }
104: return new SSLSocketImpl((SSLParameters) sslParameters.clone());
105: }
106:
107: /**
108: * @see javax.net.SocketFactory#createSocket(String,int)
109: */
110: public Socket createSocket(String host, int port)
111: throws IOException, UnknownHostException {
112: if (instantiationException != null) {
113: throw instantiationException;
114: }
115: return new SSLSocketImpl(host, port,
116: (SSLParameters) sslParameters.clone());
117: }
118:
119: /**
120: * @see javax.net.SocketFactory#createSocket(String,int,InetAddress,int)
121: */
122: public Socket createSocket(String host, int port,
123: InetAddress localHost, int localPort) throws IOException,
124: UnknownHostException {
125: if (instantiationException != null) {
126: throw instantiationException;
127: }
128: return new SSLSocketImpl(host, port, localHost, localPort,
129: (SSLParameters) sslParameters.clone());
130: }
131:
132: /**
133: * @see javax.net.SocketFactory#createSocket(InetAddress,int)
134: */
135: public Socket createSocket(InetAddress host, int port)
136: throws IOException {
137: if (instantiationException != null) {
138: throw instantiationException;
139: }
140: return new SSLSocketImpl(host, port,
141: (SSLParameters) sslParameters.clone());
142: }
143:
144: /**
145: * @see javax.net.SocketFactory#createSocket(InetAddress,int,InetAddress,int)
146: */
147: public Socket createSocket(InetAddress address, int port,
148: InetAddress localAddress, int localPort) throws IOException {
149: if (instantiationException != null) {
150: throw instantiationException;
151: }
152: return new SSLSocketImpl(address, port, localAddress,
153: localPort, (SSLParameters) sslParameters.clone());
154: }
155:
156: // ------------------------------------------------------------------
157: }
|