jdk/src/java.base/share/classes/javax/net/ssl/SSLSocketFactory.java
author redestad
Tue, 03 May 2016 15:50:54 +0200
changeset 37781 71ed5645f17c
parent 37593 824750ada3d6
child 37782 ad8fe7507ecc
permissions -rw-r--r--
8155775: Re-examine naming of privileged methods to access System properties Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.net.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.net.SocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
    32
import java.io.InputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.*;
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    34
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>SSLSocketFactory</code>s create <code>SSLSocket</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see SSLSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public abstract class SSLSocketFactory extends SocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static SSLSocketFactory theFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static boolean propertyChecked;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final boolean DEBUG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static {
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
    54
        String s = GetPropertyAction.privilegedGetProperty("javax.net.debug", "")
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 30033
diff changeset
    55
                .toLowerCase(Locale.ENGLISH);
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 30033
diff changeset
    56
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        DEBUG = s.contains("all") || s.contains("ssl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static void log(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            System.out.println(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Constructor is used only by subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public SSLSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Returns the default SSL socket factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p>The first time this method is called, the security property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * "ssl.SocketFactory.provider" is examined. If it is non-null, a class by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * that name is loaded and instantiated. If that is successful and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * object is an instance of SSLSocketFactory, it is made the default SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * socket factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * <p>Otherwise, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * <code>SSLContext.getDefault().getSocketFactory()</code>. If that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * call fails, an inoperative factory is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @return the default <code>SocketFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @see SSLContext#getDefault
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static synchronized SocketFactory getDefault() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (theFactory != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return theFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (propertyChecked == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            propertyChecked = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            String clsName = getSecurityProperty("ssl.SocketFactory.provider");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            if (clsName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                log("setting up default SSLSocketFactory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                try {
10596
39b3a979e600 7090158: Networking Libraries don't build with javac -Werror
chegar
parents: 7039
diff changeset
    99
                    Class<?> cls = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                        cls = Class.forName(clsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        ClassLoader cl = ClassLoader.getSystemClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                        if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                            cls = cl.loadClass(clsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    log("class " + clsName + " is loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    SSLSocketFactory fac = (SSLSocketFactory)cls.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    log("instantiated an instance of class " + clsName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    theFactory = fac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    return fac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    log("SSLSocketFactory instantiation failed: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    theFactory = new DefaultSSLSocketFactory(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    return theFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            return SSLContext.getDefault().getSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return new DefaultSSLSocketFactory(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    static String getSecurityProperty(final String name) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   129
        return AccessController.doPrivileged(new PrivilegedAction<>() {
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   130
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                String s = java.security.Security.getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    s = s.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    if (s.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        s = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns the list of cipher suites which are enabled by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Unless a different list is enabled, handshaking on an SSL connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * will use one of these cipher suites.  The minimum quality of service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * for these defaults requires confidentiality protection and server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * authentication (that is, no anonymous cipher suites).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see #getSupportedCipherSuites()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return array of the cipher suites enabled by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public abstract String [] getDefaultCipherSuites();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns the names of the cipher suites which could be enabled for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * on an SSL connection.  Normally, only a subset of these will actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * be enabled by default, since this list may include cipher suites which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * do not meet quality of service requirements for those defaults.  Such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * cipher suites are useful in specialized applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see #getDefaultCipherSuites()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return an array of cipher suite names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public abstract String [] getSupportedCipherSuites();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Returns a socket layered over an existing socket connected to the named
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * host, at the given port.  This constructor can be used when tunneling SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * through a proxy or when negotiating the use of SSL over an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * socket. The host and port refer to the logical peer destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * This socket is configured using the socket options established for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * this factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param s the existing socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param host the server host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param port the server port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param autoClose close the underlying socket when this socket is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return a socket connected to the specified host and port
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @throws IOException if an I/O error occurs when creating the socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @throws NullPointerException if the parameter s is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public abstract Socket createSocket(Socket s, String host,
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   185
            int port, boolean autoClose) throws IOException;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   186
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   187
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   188
     * Creates a server mode {@link Socket} layered over an
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   189
     * existing connected socket, and is able to read data which has
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   190
     * already been consumed/removed from the {@link Socket}'s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   191
     * underlying {@link InputStream}.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   192
     * <p>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   193
     * This method can be used by a server application that needs to
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   194
     * observe the inbound data but still create valid SSL/TLS
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   195
     * connections: for example, inspection of Server Name Indication
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   196
     * (SNI) extensions (See section 3 of <A
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   197
     * HREF="http://www.ietf.org/rfc/rfc6066.txt">TLS Extensions
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   198
     * (RFC6066)</A>).  Data that has been already removed from the
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   199
     * underlying {@link InputStream} should be loaded into the
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   200
     * {@code consumed} stream before this method is called, perhaps
14663
49b7de969579 8001751: Javadoc warnings in JSSE code
xuelei
parents: 14514
diff changeset
   201
     * using a {@link java.io.ByteArrayInputStream}.  When this
49b7de969579 8001751: Javadoc warnings in JSSE code
xuelei
parents: 14514
diff changeset
   202
     * {@link Socket} begins handshaking, it will read all of the data in
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   203
     * {@code consumed} until it reaches {@code EOF}, then all further
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   204
     * data is read from the underlying {@link InputStream} as
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   205
     * usual.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   206
     * <p>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   207
     * The returned socket is configured using the socket options
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   208
     * established for this factory, and is set to use server mode when
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   209
     * handshaking (see {@link SSLSocket#setUseClientMode(boolean)}).
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   210
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   211
     * @param  s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   212
     *         the existing socket
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   213
     * @param  consumed
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   214
     *         the consumed inbound network data that has already been
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   215
     *         removed from the existing {@link Socket}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   216
     *         {@link InputStream}.  This parameter may be
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   217
     *         {@code null} if no data has been removed.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   218
     * @param  autoClose close the underlying socket when this socket is closed.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   219
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   220
     * @return the {@link Socket} compliant with the socket options
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   221
     *         established for this factory
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   222
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   223
     * @throws IOException if an I/O error occurs when creating the socket
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   224
     * @throws UnsupportedOperationException if the underlying provider
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   225
     *         does not implement the operation
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   226
     * @throws NullPointerException if {@code s} is {@code null}
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   227
     *
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   228
     * @since 1.8
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   229
     */
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   230
    public Socket createSocket(Socket s, InputStream consumed,
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   231
            boolean autoClose) throws IOException {
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   232
        throw new UnsupportedOperationException();
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10596
diff changeset
   233
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
// file private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
class DefaultSSLSocketFactory extends SSLSocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    private Exception reason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    DefaultSSLSocketFactory(Exception reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        this.reason = reason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    private Socket throwException() throws SocketException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        throw (SocketException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            new SocketException(reason.toString()).initCause(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   251
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public Socket createSocket()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return throwException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   258
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public Socket createSocket(String host, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return throwException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   265
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public Socket createSocket(Socket s, String host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                int port, boolean autoClose)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return throwException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   273
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public Socket createSocket(InetAddress address, int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return throwException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   280
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public Socket createSocket(String host, int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        InetAddress clientAddress, int clientPort)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return throwException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   288
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public Socket createSocket(InetAddress address, int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        InetAddress clientAddress, int clientPort)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return throwException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   296
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public String [] getDefaultCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 14194
diff changeset
   301
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public String [] getSupportedCipherSuites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}