1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.apache.harmony.xnet.provider.jsse; 18 19 import java.io.IOException; 20 import java.net.InetAddress; 21 import java.net.Socket; 22 import java.net.UnknownHostException; 23 import java.security.KeyManagementException; 24 25 public class OpenSSLSocketFactoryImpl extends javax.net.ssl.SSLSocketFactory { 26 27 private SSLParametersImpl sslParameters; 28 private IOException instantiationException; 29 30 public OpenSSLSocketFactoryImpl() { 31 super(); 32 try { 33 sslParameters = SSLParametersImpl.getDefault(); 34 } catch (KeyManagementException e) { 35 instantiationException = 36 new IOException("Delayed instantiation exception:"); 37 instantiationException.initCause(e); 38 } 39 } 40 41 public OpenSSLSocketFactoryImpl(SSLParametersImpl sslParameters) { 42 super(); 43 this.sslParameters = sslParameters; 44 } 45 46 public String[] getDefaultCipherSuites() { 47 return NativeCrypto.getDefaultCipherSuites(); 48 } 49 50 public String[] getSupportedCipherSuites() { 51 return NativeCrypto.getSupportedCipherSuites(); 52 } 53 54 public Socket createSocket() throws IOException { 55 if (instantiationException != null) { 56 throw instantiationException; 57 } 58 return new OpenSSLSocketImpl((SSLParametersImpl) sslParameters.clone()); 59 } 60 61 public Socket createSocket(String host, int port) throws IOException, UnknownHostException { 62 return new OpenSSLSocketImpl(host, port, (SSLParametersImpl) sslParameters.clone()); 63 } 64 65 public Socket createSocket(String host, int port, InetAddress localHost, int localPort) 66 throws IOException, UnknownHostException { 67 return new OpenSSLSocketImpl(host, 68 port, 69 localHost, 70 localPort, 71 (SSLParametersImpl) sslParameters.clone()); 72 } 73 74 public Socket createSocket(InetAddress host, int port) throws IOException { 75 return new OpenSSLSocketImpl(host, port, (SSLParametersImpl) sslParameters.clone()); 76 } 77 78 public Socket createSocket(InetAddress address, 79 int port, 80 InetAddress localAddress, 81 int localPort) 82 throws IOException { 83 return new OpenSSLSocketImpl(address, 84 port, 85 localAddress, 86 localPort, 87 (SSLParametersImpl) sslParameters.clone()); 88 } 89 90 public Socket createSocket(Socket s, String host, int port, boolean autoClose) 91 throws IOException { 92 return new OpenSSLSocketImplWrapper(s, 93 host, 94 port, 95 autoClose, 96 (SSLParametersImpl) sslParameters.clone()); 97 } 98 } 99