0N/A/*
5356N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.ssl;
0N/A
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport javax.net.ssl.SSLSocketFactory;
0N/Aimport javax.net.ssl.SSLSocket;
0N/A
0N/A
0N/A/**
0N/A * Implementation of an SSL socket factory. This provides the public
0N/A * hooks to create SSL sockets, using a "high level" programming
0N/A * interface which encapsulates system security policy defaults rather than
0N/A * offering application flexibility. In particular, it uses a configurable
0N/A * authentication context (and the keys held there) rather than offering
0N/A * any flexibility about which keys to use; that context defaults to the
0N/A * process-default context, but may be explicitly specified.
0N/A *
0N/A * @author David Brownell
0N/A */
3988N/Afinal public class SSLSocketFactoryImpl extends SSLSocketFactory {
3988N/A
0N/A private static SSLContextImpl defaultContext;
0N/A private SSLContextImpl context;
0N/A
0N/A /**
0N/A * Constructor used to instantiate the default factory. This method is
0N/A * only called if the old "ssl.SocketFactory.provider" property in the
0N/A * java.security file is set.
0N/A */
0N/A public SSLSocketFactoryImpl() throws Exception {
3988N/A this.context = SSLContextImpl.DefaultSSLContext.getDefaultImpl();
0N/A }
0N/A
0N/A /**
0N/A * Constructs an SSL socket factory.
0N/A */
0N/A SSLSocketFactoryImpl(SSLContextImpl context) {
0N/A this.context = context;
0N/A }
0N/A
0N/A /**
0N/A * Creates an unconnected socket.
0N/A *
0N/A * @return the unconnected socket
0N/A * @see java.net.Socket#connect(java.net.SocketAddress, int)
0N/A */
0N/A public Socket createSocket() {
0N/A return new SSLSocketImpl(context);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an SSL connection to a named host at a specified port.
0N/A * This acts as the SSL client, and may authenticate itself or rejoin
0N/A * existing SSL sessions allowed by the authentication context which
0N/A * has been configured.
0N/A *
0N/A * @param host name of the host with which to connect
0N/A * @param port number of the server's port
0N/A */
0N/A public Socket createSocket(String host, int port)
0N/A throws IOException, UnknownHostException
0N/A {
0N/A return new SSLSocketImpl(context, host, port);
0N/A }
0N/A
0N/A /**
0N/A * Returns a socket layered over an existing socket to a
0N/A * ServerSocket on the named host, at the given port. This
0N/A * constructor can be used when tunneling SSL through a proxy. The
0N/A * host and port refer to the logical destination server. This
0N/A * socket is configured using the socket options established for
0N/A * this factory.
0N/A *
0N/A * @param s the existing socket
0N/A * @param host the server host
0N/A * @param port the server port
0N/A * @param autoClose close the underlying socket when this socket is closed
0N/A *
0N/A * @exception IOException if the connection can't be established
0N/A * @exception UnknownHostException if the host is not known
0N/A */
0N/A public Socket createSocket(Socket s, String host, int port,
0N/A boolean autoClose) throws IOException {
0N/A return new SSLSocketImpl(context, s, host, port, autoClose);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Constructs an SSL connection to a server at a specified address
0N/A * and TCP port. This acts as the SSL client, and may authenticate
0N/A * itself or rejoin existing SSL sessions allowed by the authentication
0N/A * context which has been configured.
0N/A *
0N/A * @param address the server's host
0N/A * @param port its port
0N/A */
0N/A public Socket createSocket(InetAddress address, int port)
0N/A throws IOException
0N/A {
0N/A return new SSLSocketImpl(context, address, port);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Constructs an SSL connection to a named host at a specified port.
0N/A * This acts as the SSL client, and may authenticate itself or rejoin
0N/A * existing SSL sessions allowed by the authentication context which
0N/A * has been configured. The socket will also bind() to the local
0N/A * address and port supplied.
0N/A */
0N/A public Socket createSocket(String host, int port,
0N/A InetAddress clientAddress, int clientPort)
0N/A throws IOException
0N/A {
0N/A return new SSLSocketImpl(context, host, port,
0N/A clientAddress, clientPort);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an SSL connection to a server at a specified address
0N/A * and TCP port. This acts as the SSL client, and may authenticate
0N/A * itself or rejoin existing SSL sessions allowed by the authentication
0N/A * context which has been configured. The socket will also bind() to
0N/A * the local address and port supplied.
0N/A */
0N/A public Socket createSocket(InetAddress address, int port,
0N/A InetAddress clientAddress, int clientPort)
0N/A throws IOException
0N/A {
0N/A return new SSLSocketImpl(context, address, port,
0N/A clientAddress, clientPort);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the subset of the supported cipher suites which are
0N/A * enabled by default. These cipher suites all provide a minimum
0N/A * quality of service whereby the server authenticates itself
0N/A * (preventing person-in-the-middle attacks) and where traffic
0N/A * is encrypted to provide confidentiality.
0N/A */
0N/A public String[] getDefaultCipherSuites() {
3988N/A return context.getDefaultCipherSuiteList(false).toStringArray();
0N/A }
0N/A
0N/A /**
0N/A * Returns the names of the cipher suites which could be enabled for use
0N/A * on an SSL connection. Normally, only a subset of these will actually
0N/A * be enabled by default, since this list may include cipher suites which
0N/A * do not support the mutual authentication of servers and clients, or
0N/A * which do not protect data confidentiality. Servers may also need
0N/A * certain kinds of certificates to use certain cipher suites.
0N/A */
0N/A public String[] getSupportedCipherSuites() {
5356N/A return context.getSupportedCipherSuiteList().toStringArray();
0N/A }
0N/A}