• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.conscrypt;
18 
19 import java.io.IOException;
20 import java.net.InetAddress;
21 import java.net.Socket;
22 import java.net.UnknownHostException;
23 import javax.net.ssl.SSLSocketFactory;
24 
25 public abstract class BaseOpenSSLSocketAdapterFactory extends SSLSocketFactory {
26 
27     private final OpenSSLSocketFactoryImpl delegate;
28 
BaseOpenSSLSocketAdapterFactory(OpenSSLSocketFactoryImpl delegate)29     protected BaseOpenSSLSocketAdapterFactory(OpenSSLSocketFactoryImpl delegate) {
30         this.delegate = delegate;
31     }
32 
33     @Override
getDefaultCipherSuites()34     public String[] getDefaultCipherSuites() {
35         return delegate.getDefaultCipherSuites();
36     }
37 
38     @Override
getSupportedCipherSuites()39     public String[] getSupportedCipherSuites() {
40         return delegate.getSupportedCipherSuites();
41     }
42 
43     @Override
createSocket()44     public Socket createSocket() throws IOException {
45         return wrap((OpenSSLSocketImpl) delegate.createSocket());
46     }
47 
48     @Override
createSocket(String hostname, int port)49     public Socket createSocket(String hostname, int port)
50             throws IOException, UnknownHostException {
51         return wrap((OpenSSLSocketImpl) delegate.createSocket(hostname, port));
52     }
53 
54     @Override
createSocket(String hostname, int port, InetAddress localHost, int localPort)55     public Socket createSocket(String hostname, int port, InetAddress localHost, int localPort)
56             throws IOException, UnknownHostException {
57         return wrap(
58                 (OpenSSLSocketImpl) delegate.createSocket(hostname, port, localHost, localPort));
59     }
60     @Override
createSocket(InetAddress address, int port)61     public Socket createSocket(InetAddress address, int port) throws IOException {
62         return wrap((OpenSSLSocketImpl) delegate.createSocket(address, port));
63     }
64 
65     @Override
createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)66     public Socket createSocket(InetAddress address,
67                                int port,
68                                InetAddress localAddress,
69                                int localPort)
70             throws IOException {
71         return wrap(
72                 (OpenSSLSocketImpl) delegate.createSocket(address, port, localAddress, localPort));
73     }
74 
75     @Override
createSocket(Socket s, String hostname, int port, boolean autoClose)76     public Socket createSocket(Socket s, String hostname, int port, boolean autoClose)
77             throws IOException {
78         return wrap((OpenSSLSocketImpl) delegate.createSocket(s, hostname, port, autoClose));
79     }
80 
81     /**
82      * Wraps the provided unbundled conscrypt SSLSocket into a platform bundled conscrypt
83      * SSLSocket.
84      */
wrap(OpenSSLSocketImpl sock)85     protected abstract Socket wrap(OpenSSLSocketImpl sock) throws IOException;
86 }
87