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.conscrypt;
18
19import java.io.IOException;
20import java.net.InetAddress;
21import java.net.ServerSocket;
22import java.security.KeyManagementException;
23
24public class OpenSSLServerSocketFactoryImpl extends javax.net.ssl.SSLServerSocketFactory {
25
26    private SSLParametersImpl sslParameters;
27    private IOException instantiationException;
28
29    public OpenSSLServerSocketFactoryImpl() {
30        try {
31            this.sslParameters = SSLParametersImpl.getDefault();
32            this.sslParameters.setUseClientMode(false);
33        } catch (KeyManagementException e) {
34            instantiationException =
35                new IOException("Delayed instantiation exception:");
36            instantiationException.initCause(e);
37        }
38    }
39
40    public OpenSSLServerSocketFactoryImpl(SSLParametersImpl sslParameters) {
41        this.sslParameters = (SSLParametersImpl) sslParameters.clone();
42        this.sslParameters.setUseClientMode(false);
43    }
44
45    @Override
46    public String[] getDefaultCipherSuites() {
47        return sslParameters.getEnabledCipherSuites();
48    }
49
50    @Override
51    public String[] getSupportedCipherSuites() {
52        return NativeCrypto.getSupportedCipherSuites();
53    }
54
55    @Override
56    public ServerSocket createServerSocket() throws IOException {
57        return new OpenSSLServerSocketImpl((SSLParametersImpl) sslParameters.clone());
58    }
59
60    @Override
61    public ServerSocket createServerSocket(int port) throws IOException {
62        return new OpenSSLServerSocketImpl(port, (SSLParametersImpl) sslParameters.clone());
63    }
64
65    @Override
66    public ServerSocket createServerSocket(int port, int backlog)
67            throws IOException {
68        return new OpenSSLServerSocketImpl(port,
69                                           backlog,
70                                           (SSLParametersImpl) sslParameters.clone());
71    }
72
73    @Override
74    public ServerSocket createServerSocket(int port,
75                                           int backlog,
76                                           InetAddress iAddress) throws IOException {
77        return new OpenSSLServerSocketImpl(port,
78                                           backlog,
79                                           iAddress,
80                                           (SSLParametersImpl) sslParameters.clone());
81    }
82}
83