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.ServerSocket;
22import java.security.KeyManagementException;
23
24public class OpenSSLServerSocketFactoryImpl extends javax.net.ssl.SSLServerSocketFactory {
25
26    private SSLParameters sslParameters;
27    private IOException instantiationException;
28
29    public OpenSSLServerSocketFactoryImpl() {
30        super();
31        try {
32            this.sslParameters = SSLParameters.getDefault();
33            this.sslParameters.setUseClientMode(false);
34        } catch (KeyManagementException e) {
35            instantiationException =
36                new IOException("Delayed instantiation exception:");
37            instantiationException.initCause(e);
38        }
39    }
40
41    public OpenSSLServerSocketFactoryImpl(SSLParameters sslParameters) {
42        this.sslParameters = sslParameters;
43    }
44
45    public String[] getDefaultCipherSuites() {
46        // TODO There might be a better way to implement this...
47        return OpenSSLServerSocketImpl.nativegetsupportedciphersuites();
48    }
49
50    public String[] getSupportedCipherSuites() {
51        return OpenSSLServerSocketImpl.nativegetsupportedciphersuites();
52    }
53
54    public ServerSocket createServerSocket() throws IOException {
55        return new OpenSSLServerSocketImpl((SSLParameters) sslParameters.clone());
56    }
57
58    public ServerSocket createServerSocket(int port) throws IOException {
59        return new OpenSSLServerSocketImpl(port, (SSLParameters) sslParameters.clone());
60    }
61
62    public ServerSocket createServerSocket(int port, int backlog)
63            throws IOException {
64        return new OpenSSLServerSocketImpl(port, backlog, (SSLParameters) sslParameters.clone());
65    }
66
67    public ServerSocket createServerSocket(int port, int backlog,
68            InetAddress iAddress) throws IOException {
69        return new OpenSSLServerSocketImpl(port, backlog, iAddress, (SSLParameters) sslParameters.clone());
70    }
71}
72