OpenSSLSocketFactoryImpl.java revision 0c131a2ca38465b7d1df4eaee63ac73ce4d5986d
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 17package org.apache.harmony.xnet.provider.jsse; 18 19import java.io.IOException; 20import java.net.InetAddress; 21import java.net.Socket; 22import java.net.UnknownHostException; 23import java.security.KeyManagementException; 24 25import org.apache.harmony.xnet.provider.jsse.SSLParameters; 26 27public class OpenSSLSocketFactoryImpl extends javax.net.ssl.SSLSocketFactory { 28 29 private SSLParameters sslParameters; 30 private IOException instantiationException; 31 32 public OpenSSLSocketFactoryImpl() { 33 super(); 34 try { 35 sslParameters = SSLParameters.getDefault(); 36 } catch (KeyManagementException e) { 37 instantiationException = 38 new IOException("Delayed instantiation exception:"); 39 instantiationException.initCause(e); 40 } 41 } 42 43 public OpenSSLSocketFactoryImpl(SSLParameters sslParameters) { 44 super(); 45 this.sslParameters = sslParameters; 46 } 47 48 public String[] getDefaultCipherSuites() { 49 return NativeCrypto.getDefaultCipherSuites(); 50 } 51 52 public String[] getSupportedCipherSuites() { 53 return NativeCrypto.getSupportedCipherSuites(); 54 } 55 56 public Socket createSocket() throws IOException { 57 if (instantiationException != null) { 58 throw instantiationException; 59 } 60 return new OpenSSLSocketImpl((SSLParameters) sslParameters.clone()); 61 } 62 63 public Socket createSocket(String host, int port) throws IOException, UnknownHostException { 64 return new OpenSSLSocketImpl(host, port, (SSLParameters) sslParameters.clone()); 65 } 66 67 public Socket createSocket(String host, int port, InetAddress localHost, int localPort) 68 throws IOException, UnknownHostException { 69 return new OpenSSLSocketImpl(host, 70 port, 71 localHost, 72 localPort, 73 (SSLParameters) sslParameters.clone()); 74 } 75 76 public Socket createSocket(InetAddress host, int port) throws IOException { 77 return new OpenSSLSocketImpl(host, port, (SSLParameters) sslParameters.clone()); 78 } 79 80 public Socket createSocket(InetAddress address, 81 int port, 82 InetAddress localAddress, 83 int localPort) 84 throws IOException { 85 return new OpenSSLSocketImpl(address, 86 port, 87 localAddress, 88 localPort, 89 (SSLParameters) sslParameters.clone()); 90 } 91 92 public Socket createSocket(Socket s, String host, int port, boolean autoClose) 93 throws IOException { 94 return new OpenSSLSocketImplWrapper(s, 95 host, 96 port, 97 autoClose, 98 (SSLParameters) sslParameters.clone()); 99 } 100} 101