src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43701 jdk/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java@fe8c324ba97c
child 50768 68fa3d4026ea
child 56542 56aaa6cb3693
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
     2
 * Copyright (c) 1999, 2017, 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
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.net.Socket;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
    30
import java.io.*;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    31
import java.util.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.*;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    34
import java.security.cert.Certificate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    38
import sun.security.provider.certpath.AlgorithmChecker;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
    39
import sun.security.action.GetPropertyAction;
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
    40
import sun.security.validator.Validator;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    41
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
    42
public abstract class SSLContextImpl extends SSLContextSpi {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final Debug debug = Debug.getInstance("ssl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private final EphemeralKeyManager ephemeralKeyManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private final SSLSessionContextImpl clientCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private final SSLSessionContextImpl serverCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private boolean isInitialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private X509ExtendedKeyManager keyManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private X509TrustManager trustManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private SecureRandom secureRandom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
    56
    // DTLS cookie exchange manager
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
    57
    private volatile HelloCookieManager helloCookieManager;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
    58
36132
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
    59
    private final boolean clientEnableStapling = Debug.getBooleanProperty(
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
    60
            "jdk.tls.client.enableStatusRequestExtension", true);
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
    61
    private final boolean serverEnableStapling = Debug.getBooleanProperty(
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
    62
            "jdk.tls.server.enableStatusRequestExtension", false);
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
    63
    private final static Collection<CipherSuite> clientCustomizedCipherSuites =
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
    64
            getCustomizedCipherSuites("jdk.tls.client.cipherSuites");
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
    65
    private final static Collection<CipherSuite> serverCustomizedCipherSuites =
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
    66
            getCustomizedCipherSuites("jdk.tls.server.cipherSuites");
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
    67
36132
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
    68
    private volatile StatusResponseManager statusResponseManager;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30904
diff changeset
    69
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
    70
    SSLContextImpl() {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
    71
        ephemeralKeyManager = new EphemeralKeyManager();
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
    72
        clientCache = new SSLSessionContextImpl();
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
    73
        serverCache = new SSLSessionContextImpl();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
    76
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected void engineInit(KeyManager[] km, TrustManager[] tm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                SecureRandom sr) throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        isInitialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        keyManager = chooseKeyManager(km);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (tm == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                TrustManagerFactory tmf = TrustManagerFactory.getInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                        TrustManagerFactory.getDefaultAlgorithm());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                tmf.init((KeyStore)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                tm = tmf.getTrustManagers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                // eat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        trustManager = chooseTrustManager(tm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (sr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            secureRandom = JsseJce.getSecureRandom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } else {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    97
            if (SunJSSE.isFIPS() &&
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    98
                        (sr.getProvider() != SunJSSE.cryptoProvider)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                throw new KeyManagementException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    ("FIPS mode: SecureRandom must be from provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    + SunJSSE.cryptoProvider.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            secureRandom = sr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         * The initial delay of seeding the random number generator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         * could be long enough to cause the initial handshake on our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         * first connection to timeout and fail. Make sure it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         * primed and ready by getting some initial output from it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (debug != null && Debug.isOn("sslctx")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            System.out.println("trigger seeding of SecureRandom");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        secureRandom.nextInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (debug != null && Debug.isOn("sslctx")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.println("done seeding SecureRandom");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   119
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        isInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private X509TrustManager chooseTrustManager(TrustManager[] tm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        // We only use the first instance of X509TrustManager passed to us.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        for (int i = 0; tm != null && i < tm.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (tm[i] instanceof X509TrustManager) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   128
                if (SunJSSE.isFIPS() &&
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   129
                        !(tm[i] instanceof X509TrustManagerImpl)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    throw new KeyManagementException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        ("FIPS mode: only SunJSSE TrustManagers may be used");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   133
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   134
                if (tm[i] instanceof X509ExtendedTrustManager) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   135
                    return (X509TrustManager)tm[i];
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   136
                } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   137
                    return new AbstractTrustManagerWrapper(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   138
                                        (X509TrustManager)tm[i]);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   139
                }
2
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
        // nothing found, return a dummy X509TrustManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return DummyX509TrustManager.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private X509ExtendedKeyManager chooseKeyManager(KeyManager[] kms)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throws KeyManagementException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        for (int i = 0; kms != null && i < kms.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            KeyManager km = kms[i];
12874
14df9c7c18e1 7174244: NPE in Krb5ProxyImpl.getServerKeys()
xuelei
parents: 12677
diff changeset
   151
            if (!(km instanceof X509KeyManager)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            if (SunJSSE.isFIPS()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                // In FIPS mode, require that one of SunJSSE's own keymanagers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                // is used. Otherwise, we cannot be sure that only keys from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                // the FIPS token are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                if ((km instanceof X509KeyManagerImpl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                            || (km instanceof SunX509KeyManagerImpl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    return (X509ExtendedKeyManager)km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    // throw exception, we don't want to silently use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    // dummy keymanager without telling the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    throw new KeyManagementException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                        ("FIPS mode: only SunJSSE KeyManagers may be used");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            if (km instanceof X509ExtendedKeyManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                return (X509ExtendedKeyManager)km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (debug != null && Debug.isOn("sslctx")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                System.out.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    "X509KeyManager passed to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    "SSLContext.init():  need an " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    "X509ExtendedKeyManager for SSLEngine use");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   177
            return new AbstractKeyManagerWrapper((X509KeyManager)km);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        // nothing found, return a dummy X509ExtendedKeyManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return DummyX509KeyManager.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   184
    abstract SSLEngine createSSLEngineImpl();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   185
    abstract SSLEngine createSSLEngineImpl(String host, int port);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   186
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   187
    @Override
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   188
    protected SSLEngine engineCreateSSLEngine() {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   189
        if (!isInitialized) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   190
            throw new IllegalStateException("SSLContext is not initialized");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   191
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   192
        return createSSLEngineImpl();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   193
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   194
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   195
    @Override
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   196
    protected SSLEngine engineCreateSSLEngine(String host, int port) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   197
        if (!isInitialized) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   198
            throw new IllegalStateException("SSLContext is not initialized");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   199
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   200
        return createSSLEngineImpl(host, port);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   201
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   202
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
   203
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected SSLSocketFactory engineGetSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (!isInitialized) {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   206
            throw new IllegalStateException("SSLContext is not initialized");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   208
       return new SSLSocketFactoryImpl(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
   211
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    protected SSLServerSocketFactory engineGetServerSocketFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (!isInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            throw new IllegalStateException("SSLContext is not initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return new SSLServerSocketFactoryImpl(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
   219
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    protected SSLSessionContext engineGetClientSessionContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return clientCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
   224
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    protected SSLSessionContext engineGetServerSessionContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return serverCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    SecureRandom getSecureRandom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return secureRandom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    X509ExtendedKeyManager getX509KeyManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return keyManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    X509TrustManager getX509TrustManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return trustManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    EphemeralKeyManager getEphemeralKeyManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return ephemeralKeyManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   245
    // Used for DTLS in server mode only, see ServerHandshaker.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   246
    HelloCookieManager getHelloCookieManager() {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   247
        if (!isInitialized) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   248
            throw new IllegalStateException("SSLContext is not initialized");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   249
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   250
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   251
        if (helloCookieManager != null) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   252
            return helloCookieManager;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   253
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   254
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   255
        synchronized (this) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   256
            if (helloCookieManager == null) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   257
                helloCookieManager = getHelloCookieManager(secureRandom);
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   258
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   259
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   260
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   261
        return helloCookieManager;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   262
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   263
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   264
    HelloCookieManager getHelloCookieManager(SecureRandom secureRandom) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   265
        throw new UnsupportedOperationException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   266
                "Cookie exchange applies to DTLS only");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   267
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   268
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30904
diff changeset
   269
    StatusResponseManager getStatusResponseManager() {
36132
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   270
        if (serverEnableStapling && statusResponseManager == null) {
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   271
            synchronized (this) {
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   272
                if (statusResponseManager == null) {
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   273
                    if (debug != null && Debug.isOn("sslctx")) {
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   274
                        System.out.println(
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   275
                                "Initializing StatusResponseManager");
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   276
                    }
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   277
                    statusResponseManager = new StatusResponseManager();
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   278
                }
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   279
            }
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   280
        }
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   281
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30904
diff changeset
   282
        return statusResponseManager;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30904
diff changeset
   283
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30904
diff changeset
   284
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   285
    // Get supported ProtocolList.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   286
    abstract ProtocolList getSuportedProtocolList();
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   287
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   288
    // Get default ProtocolList for server mode.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   289
    abstract ProtocolList getServerDefaultProtocolList();
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   290
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   291
    // Get default ProtocolList for client mode.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   292
    abstract ProtocolList getClientDefaultProtocolList();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   293
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   294
    // Get supported CipherSuiteList.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   295
    abstract CipherSuiteList getSupportedCipherSuiteList();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   296
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   297
    // Get default CipherSuiteList for server mode.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   298
    abstract CipherSuiteList getServerDefaultCipherSuiteList();
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   299
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   300
    // Get default CipherSuiteList for client mode.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   301
    abstract CipherSuiteList getClientDefaultCipherSuiteList();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   302
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14664
diff changeset
   303
    // Get default ProtocolList.
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   304
    ProtocolList getDefaultProtocolList(boolean roleIsServer) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   305
        return roleIsServer ? getServerDefaultProtocolList()
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   306
                            : getClientDefaultProtocolList();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   307
    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   308
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   309
    // Get default CipherSuiteList.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   310
    CipherSuiteList getDefaultCipherSuiteList(boolean roleIsServer) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   311
        return roleIsServer ? getServerDefaultCipherSuiteList()
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   312
                            : getClientDefaultCipherSuiteList();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   313
    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   314
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   315
    /**
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   316
     * Return whether a protocol list is the original default enabled
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   317
     * protocols.  See: SSLSocket/SSLEngine.setEnabledProtocols()
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   318
     */
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   319
    boolean isDefaultProtocolList(ProtocolList protocols) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   320
        return (protocols == getServerDefaultProtocolList()) ||
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   321
               (protocols == getClientDefaultProtocolList());
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   322
    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   323
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   324
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   325
     * Return whether a protocol list is the original default enabled
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   326
     * protocols.  See: SSLSocket/SSLEngine.setEnabledProtocols()
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   327
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   328
    boolean isDefaultCipherSuiteList(CipherSuiteList cipherSuites) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   329
        return (cipherSuites == getServerDefaultCipherSuiteList()) ||
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   330
               (cipherSuites == getClientDefaultCipherSuiteList());
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   331
    }
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   332
36132
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   333
    /**
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   334
     * Return whether client or server side stapling has been enabled
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   335
     * for this SSLContextImpl
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   336
     * @param isClient true if the caller is operating in a client side role,
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   337
     * false if acting as a server.
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   338
     * @return true if stapling has been enabled for the specified role, false
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   339
     * otherwise.
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   340
     */
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   341
    boolean isStaplingEnabled(boolean isClient) {
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   342
        return isClient ? clientEnableStapling : serverEnableStapling;
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   343
    }
c99a60377145 8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents: 34826
diff changeset
   344
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   345
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   346
    /*
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   347
     * Return the list of all available CipherSuites that are supported
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   348
     * using currently installed providers.
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   349
     */
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   350
    private static CipherSuiteList getApplicableSupportedCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   351
            ProtocolList protocols) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   352
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   353
        return getApplicableCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   354
                CipherSuite.allowedCipherSuites(),
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   355
                protocols, CipherSuite.SUPPORTED_SUITES_PRIORITY);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   356
    }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   357
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   358
    /*
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   359
     * Return the list of all available CipherSuites that are default enabled
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   360
     * in client or server side.
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   361
     */
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   362
    private static CipherSuiteList getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   363
            ProtocolList protocols, boolean isClient) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   364
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   365
        if (isClient) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   366
            if (!clientCustomizedCipherSuites.isEmpty()) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   367
                return getApplicableCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   368
                        clientCustomizedCipherSuites,
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   369
                        protocols, CipherSuite.SUPPORTED_SUITES_PRIORITY);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   370
            }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   371
        } else {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   372
            if (!serverCustomizedCipherSuites.isEmpty()) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   373
                return getApplicableCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   374
                        serverCustomizedCipherSuites,
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   375
                        protocols, CipherSuite.SUPPORTED_SUITES_PRIORITY);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   376
            }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   377
        }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   378
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   379
        return getApplicableCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   380
                CipherSuite.allowedCipherSuites(),
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   381
                protocols, CipherSuite.DEFAULT_SUITES_PRIORITY);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   382
    }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   383
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   384
    /*
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   385
     * Return the list of available CipherSuites which are applicable to
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   386
     * the specified protocols.
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   387
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   388
    private static CipherSuiteList getApplicableCipherSuiteList(
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   389
            Collection<CipherSuite> allowedCipherSuites,
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   390
            ProtocolList protocols, int minPriority) {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   391
12874
14df9c7c18e1 7174244: NPE in Krb5ProxyImpl.getServerKeys()
xuelei
parents: 12677
diff changeset
   392
        TreeSet<CipherSuite> suites = new TreeSet<>();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   393
        if (!(protocols.collection().isEmpty()) &&
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   394
                protocols.min.v != ProtocolVersion.NONE.v) {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   395
            for (CipherSuite suite : allowedCipherSuites) {
12874
14df9c7c18e1 7174244: NPE in Krb5ProxyImpl.getServerKeys()
xuelei
parents: 12677
diff changeset
   396
                if (!suite.allowed || suite.priority < minPriority) {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   397
                    continue;
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   398
                }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   399
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   400
                if (suite.isAvailable() &&
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   401
                        !protocols.min.obsoletes(suite) &&
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   402
                        protocols.max.supports(suite)) {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   403
                    if (SSLAlgorithmConstraints.DEFAULT.permits(
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   404
                            EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   405
                            suite.name, null)) {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   406
                        suites.add(suite);
42221
6bd0eb3735b8 8170035: When determining the ciphersuite lists, there is no debug output for disabled suites.
jnimeh
parents: 40700
diff changeset
   407
                    } else {
6bd0eb3735b8 8170035: When determining the ciphersuite lists, there is no debug output for disabled suites.
jnimeh
parents: 40700
diff changeset
   408
                        if (debug != null && Debug.isOn("sslctx") &&
6bd0eb3735b8 8170035: When determining the ciphersuite lists, there is no debug output for disabled suites.
jnimeh
parents: 40700
diff changeset
   409
                                Debug.isOn("verbose")) {
6bd0eb3735b8 8170035: When determining the ciphersuite lists, there is no debug output for disabled suites.
jnimeh
parents: 40700
diff changeset
   410
                            System.out.println(
6bd0eb3735b8 8170035: When determining the ciphersuite lists, there is no debug output for disabled suites.
jnimeh
parents: 40700
diff changeset
   411
                                    "Ignoring disabled cipher suite: " +
6bd0eb3735b8 8170035: When determining the ciphersuite lists, there is no debug output for disabled suites.
jnimeh
parents: 40700
diff changeset
   412
                                            suite.name);
6bd0eb3735b8 8170035: When determining the ciphersuite lists, there is no debug output for disabled suites.
jnimeh
parents: 40700
diff changeset
   413
                        }
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   414
                    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   415
                } else if (debug != null &&
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   416
                        Debug.isOn("sslctx") && Debug.isOn("verbose")) {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   417
                    if (protocols.min.obsoletes(suite)) {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   418
                        System.out.println(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   419
                            "Ignoring obsoleted cipher suite: " + suite);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   420
                    } else if (!protocols.max.supports(suite)) {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   421
                        System.out.println(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   422
                            "Ignoring unsupported cipher suite: " + suite);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   423
                    } else {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   424
                        System.out.println(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   425
                            "Ignoring unavailable cipher suite: " + suite);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   426
                    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   427
                }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   428
            }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   429
        }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   430
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   431
        return new CipherSuiteList(suites);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   432
    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   433
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   434
    /*
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   435
     * Get the customized cipher suites specified by the given system property.
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   436
     */
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   437
    private static Collection<CipherSuite> getCustomizedCipherSuites(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   438
            String propertyName) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   439
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   440
        String property = GetPropertyAction.privilegedGetProperty(propertyName);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   441
        if (debug != null && Debug.isOn("sslctx")) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   442
            System.out.println(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   443
                    "System property " + propertyName + " is set to '" +
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   444
                    property + "'");
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   445
        }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   446
        if (property != null && property.length() != 0) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   447
            // remove double quote marks from beginning/end of the property
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   448
            if (property.length() > 1 && property.charAt(0) == '"' &&
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   449
                    property.charAt(property.length() - 1) == '"') {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   450
                property = property.substring(1, property.length() - 1);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   451
            }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   452
        }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   453
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   454
        if (property != null && property.length() != 0) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   455
            String[] cipherSuiteNames = property.split(",");
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   456
            Collection<CipherSuite> cipherSuites =
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   457
                        new ArrayList<>(cipherSuiteNames.length);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   458
            for (int i = 0; i < cipherSuiteNames.length; i++) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   459
                cipherSuiteNames[i] = cipherSuiteNames[i].trim();
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   460
                if (cipherSuiteNames[i].isEmpty()) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   461
                    continue;
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   462
                }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   463
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   464
                CipherSuite suite;
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   465
                try {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   466
                    suite = CipherSuite.valueOf(cipherSuiteNames[i]);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   467
                } catch (IllegalArgumentException iae) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   468
                    if (debug != null && Debug.isOn("sslctx")) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   469
                        System.out.println(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   470
                                "Unknown or unsupported cipher suite name: " +
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   471
                                cipherSuiteNames[i]);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   472
                    }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   473
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   474
                    continue;
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   475
                }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   476
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   477
                if (suite.isAvailable()) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   478
                    cipherSuites.add(suite);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   479
                } else {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   480
                    if (debug != null && Debug.isOn("sslctx")) {
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   481
                        System.out.println(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   482
                                "The current installed providers do not " +
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   483
                                "support cipher suite: " + cipherSuiteNames[i]);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   484
                    }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   485
                }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   486
            }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   487
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   488
            return cipherSuites;
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   489
        }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   490
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   491
        return Collections.emptyList();
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   492
    }
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   493
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   494
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   495
    private static String[] getAvailableProtocols(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   496
            ProtocolVersion[] protocolCandidates) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   497
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   498
        List<String> availableProtocols = Collections.<String>emptyList();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   499
        if (protocolCandidates !=  null && protocolCandidates.length != 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   500
            availableProtocols = new ArrayList<>(protocolCandidates.length);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   501
            for (ProtocolVersion p : protocolCandidates) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   502
                if (ProtocolVersion.availableProtocols.contains(p)) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   503
                    availableProtocols.add(p.name);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   504
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   505
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   506
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   507
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   508
        return availableProtocols.toArray(new String[0]);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   509
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   510
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   511
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   512
    /*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   513
     * The SSLContext implementation for SSL/(D)TLS algorithm
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   514
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   515
     * SSL/TLS protocols specify the forward compatibility and version
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   516
     * roll-back attack protections, however, a number of SSL/TLS server
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   517
     * vendors did not implement these aspects properly, and some current
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   518
     * SSL/TLS servers may refuse to talk to a TLS 1.1 or later client.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   519
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   520
     * Considering above interoperability issues, SunJSSE will not set
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   521
     * TLS 1.1 and TLS 1.2 as the enabled protocols for client by default.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   522
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   523
     * For SSL/TLS servers, there is no such interoperability issues as
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   524
     * SSL/TLS clients. In SunJSSE, TLS 1.1 or later version will be the
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   525
     * enabled protocols for server by default.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   526
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   527
     * We may change the behavior when popular TLS/SSL vendors support TLS
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   528
     * forward compatibility properly.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   529
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   530
     * SSLv2Hello is no longer necessary.  This interoperability option was
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   531
     * put in place in the late 90's when SSLv3/TLS1.0 were relatively new
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   532
     * and there were a fair number of SSLv2-only servers deployed.  Because
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   533
     * of the security issues in SSLv2, it is rarely (if ever) used, as
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   534
     * deployments should now be using SSLv3 and TLSv1.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   535
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   536
     * Considering the issues of SSLv2Hello, we should not enable SSLv2Hello
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   537
     * by default. Applications still can use it by enabling SSLv2Hello with
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   538
     * the series of setEnabledProtocols APIs.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   539
     */
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   540
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   541
    /*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   542
     * The base abstract SSLContext implementation for the Transport Layer
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   543
     * Security (TLS) protocols.
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   544
     *
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   545
     * This abstract class encapsulates supported and the default server
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   546
     * SSL/TLS parameters.
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   547
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   548
     * @see SSLContext
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   549
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   550
    private abstract static class AbstractTLSContext extends SSLContextImpl {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   551
        private static final ProtocolList supportedProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   552
        private static final ProtocolList serverDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   553
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   554
        private static final CipherSuiteList supportedCipherSuiteList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   555
        private static final CipherSuiteList serverDefaultCipherSuiteList;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   556
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   557
        static {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   558
            if (SunJSSE.isFIPS()) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   559
                supportedProtocolList = new ProtocolList(new String[] {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   560
                    ProtocolVersion.TLS10.name,
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   561
                    ProtocolVersion.TLS11.name,
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   562
                    ProtocolVersion.TLS12.name
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   563
                });
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   564
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   565
                serverDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   566
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   567
                    ProtocolVersion.TLS10,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   568
                    ProtocolVersion.TLS11,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   569
                    ProtocolVersion.TLS12
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   570
                }));
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   571
            } else {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   572
                supportedProtocolList = new ProtocolList(new String[] {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   573
                    ProtocolVersion.SSL20Hello.name,
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   574
                    ProtocolVersion.SSL30.name,
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   575
                    ProtocolVersion.TLS10.name,
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   576
                    ProtocolVersion.TLS11.name,
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   577
                    ProtocolVersion.TLS12.name
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   578
                });
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   579
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   580
                serverDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   581
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   582
                    ProtocolVersion.SSL20Hello,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   583
                    ProtocolVersion.SSL30,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   584
                    ProtocolVersion.TLS10,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   585
                    ProtocolVersion.TLS11,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   586
                    ProtocolVersion.TLS12
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   587
                }));
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   588
            }
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   589
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   590
            supportedCipherSuiteList = getApplicableSupportedCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   591
                    supportedProtocolList);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   592
            serverDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   593
                    serverDefaultProtocolList, false);
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   594
        }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   595
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
   596
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   597
        ProtocolList getSuportedProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   598
            return supportedProtocolList;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   599
        }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   600
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
   601
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   602
        CipherSuiteList getSupportedCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   603
            return supportedCipherSuiteList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   604
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   605
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   606
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   607
        ProtocolList getServerDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   608
            return serverDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   609
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   610
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   611
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   612
        CipherSuiteList getServerDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   613
            return serverDefaultCipherSuiteList;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   614
        }
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   615
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   616
        @Override
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   617
        SSLEngine createSSLEngineImpl() {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   618
            return new SSLEngineImpl(this, false);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   619
        }
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   620
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   621
        @Override
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   622
        SSLEngine createSSLEngineImpl(String host, int port) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   623
            return new SSLEngineImpl(this, host, port, false);
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   624
        }
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   625
    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   626
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   627
    /*
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   628
     * The SSLContext implementation for SSLv3 and TLS10 algorithm
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   629
     *
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   630
     * @see SSLContext
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   631
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   632
    public static final class TLS10Context extends AbstractTLSContext {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   633
        private static final ProtocolList clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   634
        private static final CipherSuiteList clientDefaultCipherSuiteList;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   635
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   636
        static {
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   637
            if (SunJSSE.isFIPS()) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   638
                clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   639
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   640
                    ProtocolVersion.TLS10
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   641
                }));
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   642
            } else {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   643
                clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   644
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   645
                    ProtocolVersion.SSL30,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   646
                    ProtocolVersion.TLS10
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   647
                }));
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   648
            }
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   649
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   650
            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   651
                    clientDefaultProtocolList, true);
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   652
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   653
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   654
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   655
        ProtocolList getClientDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   656
            return clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   657
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   658
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   659
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   660
        CipherSuiteList getClientDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   661
            return clientDefaultCipherSuiteList;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   662
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   663
    }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   664
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   665
    /*
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   666
     * The SSLContext implementation for TLS11 algorithm
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   667
     *
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   668
     * @see SSLContext
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   669
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   670
    public static final class TLS11Context extends AbstractTLSContext {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   671
        private static final ProtocolList clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   672
        private static final CipherSuiteList clientDefaultCipherSuiteList;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   673
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   674
        static {
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   675
            if (SunJSSE.isFIPS()) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   676
                clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   677
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   678
                    ProtocolVersion.TLS10,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   679
                    ProtocolVersion.TLS11
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   680
                }));
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   681
            } else {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   682
                clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   683
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   684
                    ProtocolVersion.SSL30,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   685
                    ProtocolVersion.TLS10,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   686
                    ProtocolVersion.TLS11
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   687
                }));
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   688
            }
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   689
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   690
            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   691
                    clientDefaultProtocolList, true);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   692
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   693
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   694
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   695
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   696
        ProtocolList getClientDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   697
            return clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   698
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   699
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   700
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   701
        CipherSuiteList getClientDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   702
            return clientDefaultCipherSuiteList;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   703
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   704
    }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   705
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   706
    /*
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   707
     * The SSLContext implementation for TLS12 algorithm
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   708
     *
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   709
     * @see SSLContext
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   710
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   711
    public static final class TLS12Context extends AbstractTLSContext {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   712
        private static final ProtocolList clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   713
        private static final CipherSuiteList clientDefaultCipherSuiteList;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   714
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   715
        static {
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   716
            if (SunJSSE.isFIPS()) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   717
                clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   718
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   719
                    ProtocolVersion.TLS10,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   720
                    ProtocolVersion.TLS11,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   721
                    ProtocolVersion.TLS12
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   722
                }));
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   723
            } else {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   724
                clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   725
                        getAvailableProtocols(new ProtocolVersion[] {
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   726
                    ProtocolVersion.SSL30,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   727
                    ProtocolVersion.TLS10,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   728
                    ProtocolVersion.TLS11,
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   729
                    ProtocolVersion.TLS12
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   730
                }));
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   731
            }
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   732
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   733
            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   734
                    clientDefaultProtocolList, true);
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   735
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   736
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   737
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   738
        ProtocolList getClientDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   739
            return clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   740
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   741
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   742
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   743
        CipherSuiteList getClientDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   744
            return clientDefaultCipherSuiteList;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   745
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   746
    }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   747
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   748
    /*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   749
     * The interface for the customized SSL/(D)TLS SSLContext.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   750
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   751
     * @see SSLContext
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   752
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   753
    private static class CustomizedSSLProtocols {
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   754
        private static final String PROPERTY_NAME = "jdk.tls.client.protocols";
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   755
        static IllegalArgumentException reservedException = null;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   756
        static ArrayList<ProtocolVersion>
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   757
                                customizedProtocols = new ArrayList<>();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   758
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   759
        // Don't want a java.lang.LinkageError for illegal system property.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   760
        //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   761
        // Please don't throw exception in this static block.  Otherwise,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   762
        // java.lang.LinkageError may be thrown during the instantiation of
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   763
        // the provider service. Instead, please handle the initialization
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   764
        // exception in the caller's constructor.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   765
        static {
37781
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   766
            String property = GetPropertyAction
71ed5645f17c 8155775: Re-examine naming of privileged methods to access System properties
redestad
parents: 37593
diff changeset
   767
                    .privilegedGetProperty(PROPERTY_NAME);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   768
            if (property != null && property.length() != 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   769
                // remove double quote marks from beginning/end of the property
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   770
                if (property.length() > 1 && property.charAt(0) == '"' &&
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   771
                        property.charAt(property.length() - 1) == '"') {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   772
                    property = property.substring(1, property.length() - 1);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   773
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   774
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   775
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   776
            if (property != null && property.length() != 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   777
                String[] protocols = property.split(",");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   778
                for (int i = 0; i < protocols.length; i++) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   779
                    protocols[i] = protocols[i].trim();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   780
                    // Is it a supported protocol name?
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   781
                    try {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   782
                        ProtocolVersion pro =
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   783
                                ProtocolVersion.valueOf(protocols[i]);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   784
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   785
                        if (SunJSSE.isFIPS() &&
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   786
                                ((pro.v == ProtocolVersion.SSL30.v) ||
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   787
                                 (pro.v == ProtocolVersion.SSL20Hello.v))) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   788
                            reservedException = new IllegalArgumentException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   789
                                    PROPERTY_NAME + ": " + pro +
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   790
                                    " is not FIPS compliant");
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   791
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   792
                            break;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   793
                        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   794
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   795
                        // ignore duplicated protocols
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   796
                        if (!customizedProtocols.contains(pro)) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   797
                            customizedProtocols.add(pro);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   798
                        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   799
                    } catch (IllegalArgumentException iae) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   800
                        reservedException = new IllegalArgumentException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   801
                                PROPERTY_NAME + ": " + protocols[i] +
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   802
                                " is not a standard SSL protocol name", iae);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   803
                    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   804
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   805
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   806
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   807
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   808
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   809
    /*
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   810
     * The SSLContext implementation for customized TLS protocols
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   811
     *
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   812
     * @see SSLContext
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   813
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   814
    private static class CustomizedTLSContext extends AbstractTLSContext {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   815
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   816
        private static final ProtocolList clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   817
        private static final CipherSuiteList clientDefaultCipherSuiteList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   818
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   819
        private static IllegalArgumentException reservedException = null;
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   820
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   821
        // Don't want a java.lang.LinkageError for illegal system property.
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   822
        //
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   823
        // Please don't throw exception in this static block.  Otherwise,
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   824
        // java.lang.LinkageError may be thrown during the instantiation of
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   825
        // the provider service. Instead, let's handle the initialization
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   826
        // exception in constructor.
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   827
        static {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   828
            reservedException = CustomizedSSLProtocols.reservedException;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   829
            if (reservedException == null) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   830
                ArrayList<ProtocolVersion>
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   831
                        customizedTLSProtocols = new ArrayList<>();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   832
                for (ProtocolVersion protocol :
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   833
                        CustomizedSSLProtocols.customizedProtocols) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   834
                    if (!protocol.isDTLSProtocol()) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   835
                        customizedTLSProtocols.add(protocol);
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   836
                    }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   837
                }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   838
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   839
                // candidates for available protocols
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   840
                ProtocolVersion[] candidates;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   841
                if (customizedTLSProtocols.isEmpty()) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   842
                    // Use the default enabled client protocols if no
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   843
                    // customized TLS protocols.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   844
                    if (SunJSSE.isFIPS()) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   845
                        candidates = new ProtocolVersion[] {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   846
                            ProtocolVersion.TLS10,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   847
                            ProtocolVersion.TLS11,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   848
                            ProtocolVersion.TLS12
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   849
                        };
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   850
                    } else {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   851
                        candidates = new ProtocolVersion[] {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   852
                            ProtocolVersion.SSL30,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   853
                            ProtocolVersion.TLS10,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   854
                            ProtocolVersion.TLS11,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   855
                            ProtocolVersion.TLS12
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   856
                        };
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   857
                    }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   858
                } else {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   859
                    // Use the customized TLS protocols.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   860
                    candidates =
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   861
                            new ProtocolVersion[customizedTLSProtocols.size()];
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   862
                    candidates = customizedTLSProtocols.toArray(candidates);
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   863
                }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   864
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   865
                clientDefaultProtocolList = new ProtocolList(
28555
c7bf34f7b215 8061210: Issues in TLS
xuelei
parents: 25859
diff changeset
   866
                        getAvailableProtocols(candidates));
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   867
                clientDefaultCipherSuiteList =
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   868
                        getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
   869
                                clientDefaultProtocolList, true);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   870
            } else {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   871
                clientDefaultProtocolList = null;       // unlikely to be used
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   872
                clientDefaultCipherSuiteList = null;    // unlikely to be used
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   873
            }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   874
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   875
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   876
        protected CustomizedTLSContext() {
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   877
            if (reservedException != null) {
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   878
                throw reservedException;
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   879
            }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   880
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   881
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   882
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   883
        ProtocolList getClientDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   884
            return clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   885
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   886
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   887
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   888
        CipherSuiteList getClientDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   889
            return clientDefaultCipherSuiteList;
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   890
        }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   891
    }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   892
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   893
    /*
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   894
     * The SSLContext implementation for default "TLS" algorithm
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   895
     *
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   896
     * @see SSLContext
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   897
     */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
   898
    public static final class TLSContext extends CustomizedTLSContext {
22068
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   899
        // use the default constructor and methods
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   900
    }
95a7a3cd72a0 7093640: Enable client-side TLS 1.2 by default
xuelei
parents: 21278
diff changeset
   901
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   902
    // lazy initialization holder class idiom for static default parameters
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   903
    //
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   904
    // See Effective Java Second Edition: Item 71.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   905
    private static final class DefaultManagersHolder {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   906
        private static final String NONE = "NONE";
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   907
        private static final String P11KEYSTORE = "PKCS11";
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   908
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   909
        private static final TrustManager[] trustManagers;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   910
        private static final KeyManager[] keyManagers;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   911
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   912
        static Exception reservedException = null;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   913
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   914
        static {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   915
            TrustManager[] tmMediator;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   916
            try {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   917
                tmMediator = getTrustManagers();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   918
            } catch (Exception e) {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   919
                reservedException = e;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   920
                tmMediator = new TrustManager[0];
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   921
            }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   922
            trustManagers = tmMediator;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   923
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   924
            if (reservedException == null) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   925
                KeyManager[] kmMediator;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   926
                try {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   927
                    kmMediator = getKeyManagers();
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   928
                } catch (Exception e) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   929
                    reservedException = e;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   930
                    kmMediator = new KeyManager[0];
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   931
                }
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   932
                keyManagers = kmMediator;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   933
            } else {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   934
                keyManagers = new KeyManager[0];
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   935
            }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   936
        }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   937
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   938
        private static TrustManager[] getTrustManagers() throws Exception {
43009
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   939
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   940
                    TrustManagerFactory.getDefaultAlgorithm());
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   941
            if ("SunJSSE".equals(tmf.getProvider().getName())) {
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   942
                // The implementation will load the default KeyStore
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   943
                // automatically.  Cached trust materials may be used
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   944
                // for performance improvement.
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   945
                tmf.init((KeyStore)null);
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   946
            } else {
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   947
                // Use the explicitly specified KeyStore for third party's
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   948
                // TrustManagerFactory implementation.
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   949
                KeyStore ks = TrustStoreManager.getTrustedKeyStore();
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   950
                tmf.init(ks);
5af9f7aa93e5 8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents: 42221
diff changeset
   951
            }
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   952
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   953
            return tmf.getTrustManagers();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   954
        }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   955
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
   956
        private static KeyManager[] getKeyManagers() throws Exception {
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   957
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   958
            final Map<String,String> props = new HashMap<>();
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   959
            AccessController.doPrivileged(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   960
                        new PrivilegedExceptionAction<Object>() {
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
   961
                @Override
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   962
                public Object run() throws Exception {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   963
                    props.put("keyStore",  System.getProperty(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   964
                                "javax.net.ssl.keyStore", ""));
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   965
                    props.put("keyStoreType", System.getProperty(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   966
                                "javax.net.ssl.keyStoreType",
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   967
                                KeyStore.getDefaultType()));
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   968
                    props.put("keyStoreProvider", System.getProperty(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   969
                                "javax.net.ssl.keyStoreProvider", ""));
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   970
                    props.put("keyStorePasswd", System.getProperty(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   971
                                "javax.net.ssl.keyStorePassword", ""));
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   972
                    return null;
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   973
                }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   974
            });
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   975
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   976
            final String defaultKeyStore = props.get("keyStore");
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   977
            String defaultKeyStoreType = props.get("keyStoreType");
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   978
            String defaultKeyStoreProvider = props.get("keyStoreProvider");
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   979
            if (debug != null && Debug.isOn("defaultctx")) {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   980
                System.out.println("keyStore is : " + defaultKeyStore);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   981
                System.out.println("keyStore type is : " +
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   982
                                        defaultKeyStoreType);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   983
                System.out.println("keyStore provider is : " +
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   984
                                        defaultKeyStoreProvider);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   985
            }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   986
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   987
            if (P11KEYSTORE.equals(defaultKeyStoreType) &&
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   988
                    !NONE.equals(defaultKeyStore)) {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   989
                throw new IllegalArgumentException("if keyStoreType is "
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   990
                    + P11KEYSTORE + ", then keyStore must be " + NONE);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   991
            }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   992
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   993
            FileInputStream fs = null;
10125
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
   994
            KeyStore ks = null;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
   995
            char[] passwd = null;
10125
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
   996
            try {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
   997
                if (defaultKeyStore.length() != 0 &&
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
   998
                        !NONE.equals(defaultKeyStore)) {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
   999
                    fs = AccessController.doPrivileged(
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1000
                            new PrivilegedExceptionAction<FileInputStream>() {
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1001
                        @Override
10125
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1002
                        public FileInputStream run() throws Exception {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1003
                            return new FileInputStream(defaultKeyStore);
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1004
                        }
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1005
                    });
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1006
                }
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1007
10125
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1008
                String defaultKeyStorePassword = props.get("keyStorePasswd");
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1009
                if (defaultKeyStorePassword.length() != 0) {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1010
                    passwd = defaultKeyStorePassword.toCharArray();
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1011
                }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1012
10125
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1013
                /**
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1014
                 * Try to initialize key store.
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1015
                 */
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1016
                if ((defaultKeyStoreType.length()) != 0) {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1017
                    if (debug != null && Debug.isOn("defaultctx")) {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1018
                        System.out.println("init keystore");
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1019
                    }
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1020
                    if (defaultKeyStoreProvider.length() == 0) {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1021
                        ks = KeyStore.getInstance(defaultKeyStoreType);
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1022
                    } else {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1023
                        ks = KeyStore.getInstance(defaultKeyStoreType,
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1024
                                            defaultKeyStoreProvider);
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1025
                    }
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1026
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1027
                    // if defaultKeyStore is NONE, fs will be null
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1028
                    ks.load(fs, passwd);
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1029
                }
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1030
            } finally {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1031
                if (fs != null) {
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1032
                    fs.close();
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1033
                    fs = null;
c70d99150c40 7059709: close the IO in a final block
xuelei
parents: 9246
diff changeset
  1034
                }
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1035
            }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1036
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1037
            /*
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1038
             * Try to initialize key manager.
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1039
             */
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1040
            if (debug != null && Debug.isOn("defaultctx")) {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1041
                System.out.println("init keymanager of type " +
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1042
                    KeyManagerFactory.getDefaultAlgorithm());
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1043
            }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1044
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1045
                KeyManagerFactory.getDefaultAlgorithm());
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1046
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1047
            if (P11KEYSTORE.equals(defaultKeyStoreType)) {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1048
                kmf.init(ks, null); // do not pass key passwd if using token
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1049
            } else {
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1050
                kmf.init(ks, passwd);
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1051
            }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1052
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1053
            return kmf.getKeyManagers();
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1054
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1055
    }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1056
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1057
    // lazy initialization holder class idiom for static default parameters
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1058
    //
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1059
    // See Effective Java Second Edition: Item 71.
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1060
    private static final class DefaultSSLContextHolder {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1061
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1062
        private static final SSLContextImpl sslContext;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1063
        static Exception reservedException = null;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1064
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1065
        static {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1066
            SSLContextImpl mediator = null;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1067
            if (DefaultManagersHolder.reservedException != null) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1068
                reservedException = DefaultManagersHolder.reservedException;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1069
            } else {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1070
                try {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1071
                    mediator = new DefaultSSLContext();
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1072
                } catch (Exception e) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1073
                    reservedException = e;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1074
                }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1075
            }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1076
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1077
            sslContext = mediator;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1078
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1079
    }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1080
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1081
    /*
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1082
     * The SSLContext implementation for default "Default" algorithm
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1083
     *
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1084
     * @see SSLContext
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1085
     */
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1086
    public static final class DefaultSSLContext extends CustomizedTLSContext {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1087
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1088
        // public constructor for SSLContext.getInstance("Default")
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1089
        public DefaultSSLContext() throws Exception {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1090
            if (DefaultManagersHolder.reservedException != null) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1091
                throw DefaultManagersHolder.reservedException;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1092
            }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1093
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1094
            try {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1095
                super.engineInit(DefaultManagersHolder.keyManagers,
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1096
                        DefaultManagersHolder.trustManagers, null);
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1097
            } catch (Exception e) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1098
                if (debug != null && Debug.isOn("defaultctx")) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1099
                    System.out.println("default context init failed: " + e);
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1100
                }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1101
                throw e;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1102
            }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1103
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1104
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1105
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1106
        protected void engineInit(KeyManager[] km, TrustManager[] tm,
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1107
            SecureRandom sr) throws KeyManagementException {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1108
            throw new KeyManagementException
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1109
                ("Default SSLContext is initialized automatically");
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1110
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1111
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1112
        static SSLContextImpl getDefaultImpl() throws Exception {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1113
            if (DefaultSSLContextHolder.reservedException != null) {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1114
                throw DefaultSSLContextHolder.reservedException;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1115
            }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1116
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1117
            return DefaultSSLContextHolder.sslContext;
9246
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1118
        }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1119
    }
c459f79af46b 6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents: 7043
diff changeset
  1120
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1121
    /*
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1122
     * The base abstract SSLContext implementation for the Datagram Transport
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1123
     * Layer Security (DTLS) protocols.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1124
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1125
     * This abstract class encapsulates supported and the default server DTLS
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1126
     * parameters.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1127
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1128
     * @see SSLContext
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1129
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1130
    private abstract static class AbstractDTLSContext extends SSLContextImpl {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1131
        private static final ProtocolList supportedProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1132
        private static final ProtocolList serverDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1133
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1134
        private static final CipherSuiteList supportedCipherSuiteList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1135
        private static final CipherSuiteList serverDefaultCipherSuiteList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1136
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1137
        static {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1138
            // Both DTLSv1.0 and DTLSv1.2 can be used in FIPS mode.
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1139
            supportedProtocolList = new ProtocolList(new String[] {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1140
                ProtocolVersion.DTLS10.name,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1141
                ProtocolVersion.DTLS12.name
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1142
            });
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1143
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1144
            // available protocols for server mode
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1145
            serverDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1146
                    getAvailableProtocols(new ProtocolVersion[] {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1147
                ProtocolVersion.DTLS10,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1148
                ProtocolVersion.DTLS12
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1149
            }));
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1150
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1151
            supportedCipherSuiteList = getApplicableSupportedCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1152
                    supportedProtocolList);
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1153
            serverDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1154
                    serverDefaultProtocolList, false);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1155
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1156
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1157
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1158
        ProtocolList getSuportedProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1159
            return supportedProtocolList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1160
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1161
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1162
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1163
        CipherSuiteList getSupportedCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1164
            return supportedCipherSuiteList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1165
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1166
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1167
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1168
        ProtocolList getServerDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1169
            return serverDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1170
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1171
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1172
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1173
        CipherSuiteList getServerDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1174
            return serverDefaultCipherSuiteList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1175
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1176
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1177
        @Override
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1178
        SSLEngine createSSLEngineImpl() {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1179
            return new SSLEngineImpl(this, true);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1180
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1181
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1182
        @Override
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1183
        SSLEngine createSSLEngineImpl(String host, int port) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1184
            return new SSLEngineImpl(this, host, port, true);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1185
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1186
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1187
        @Override
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1188
        HelloCookieManager getHelloCookieManager(SecureRandom secureRandom) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1189
            return new HelloCookieManager(secureRandom);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1190
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1191
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1192
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1193
    /*
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1194
     * The SSLContext implementation for DTLSv1.0 algorithm.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1195
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1196
     * @see SSLContext
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1197
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1198
    public static final class DTLS10Context extends AbstractDTLSContext {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1199
        private static final ProtocolList clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1200
        private static final CipherSuiteList clientDefaultCipherSuiteList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1201
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1202
        static {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1203
            // available protocols for client mode
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1204
            clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1205
                    getAvailableProtocols(new ProtocolVersion[] {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1206
                ProtocolVersion.DTLS10
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1207
            }));
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1208
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1209
            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1210
                    clientDefaultProtocolList, true);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1211
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1212
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1213
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1214
        ProtocolList getClientDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1215
            return clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1216
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1217
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1218
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1219
        CipherSuiteList getClientDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1220
            return clientDefaultCipherSuiteList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1221
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1222
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1223
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1224
    /*
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1225
     * The SSLContext implementation for DTLSv1.2 algorithm.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1226
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1227
     * @see SSLContext
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1228
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1229
    public static final class DTLS12Context extends AbstractDTLSContext {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1230
        private static final ProtocolList clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1231
        private static final CipherSuiteList clientDefaultCipherSuiteList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1232
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1233
        static {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1234
            // available protocols for client mode
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1235
            clientDefaultProtocolList = new ProtocolList(
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1236
                    getAvailableProtocols(new ProtocolVersion[] {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1237
                ProtocolVersion.DTLS10,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1238
                ProtocolVersion.DTLS12
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1239
            }));
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1240
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1241
            clientDefaultCipherSuiteList = getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1242
                    clientDefaultProtocolList, true);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1243
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1244
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1245
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1246
        ProtocolList getClientDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1247
            return clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1248
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1249
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1250
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1251
        CipherSuiteList getClientDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1252
            return clientDefaultCipherSuiteList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1253
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1254
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1255
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1256
    /*
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1257
     * The SSLContext implementation for customized TLS protocols
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1258
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1259
     * @see SSLContext
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1260
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1261
    private static class CustomizedDTLSContext extends AbstractDTLSContext {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1262
        private static final ProtocolList clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1263
        private static final CipherSuiteList clientDefaultCipherSuiteList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1264
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1265
        private static IllegalArgumentException reservedException = null;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1266
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1267
        // Don't want a java.lang.LinkageError for illegal system property.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1268
        //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1269
        // Please don't throw exception in this static block.  Otherwise,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1270
        // java.lang.LinkageError may be thrown during the instantiation of
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1271
        // the provider service. Instead, let's handle the initialization
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1272
        // exception in constructor.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1273
        static {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1274
            reservedException = CustomizedSSLProtocols.reservedException;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1275
            if (reservedException == null) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1276
                ArrayList<ProtocolVersion>
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1277
                        customizedDTLSProtocols = new ArrayList<>();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1278
                for (ProtocolVersion protocol :
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1279
                        CustomizedSSLProtocols.customizedProtocols) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1280
                    if (protocol.isDTLSProtocol()) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1281
                        customizedDTLSProtocols.add(protocol);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1282
                    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1283
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1284
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1285
                // candidates for available protocols
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1286
                ProtocolVersion[] candidates;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1287
                if (customizedDTLSProtocols.isEmpty()) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1288
                    // Use the default enabled client protocols if no
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1289
                    // customized TLS protocols.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1290
                    //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1291
                    // Both DTLSv1.0 and DTLSv1.2 can be used in FIPS mode.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1292
                    candidates = new ProtocolVersion[] {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1293
                        ProtocolVersion.DTLS10,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1294
                        ProtocolVersion.DTLS12
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1295
                    };
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1296
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1297
                } else {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1298
                    // Use the customized TLS protocols.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1299
                    candidates =
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1300
                            new ProtocolVersion[customizedDTLSProtocols.size()];
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1301
                    candidates = customizedDTLSProtocols.toArray(candidates);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1302
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1303
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1304
                clientDefaultProtocolList = new ProtocolList(
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1305
                        getAvailableProtocols(candidates));
40275
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1306
                clientDefaultCipherSuiteList =
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1307
                        getApplicableEnabledCipherSuiteList(
6a37d5a9619d 8162362: Introduce system property to control enabled ciphersuites
xuelei
parents: 37781
diff changeset
  1308
                                clientDefaultProtocolList, true);
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1309
            } else {
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1310
                clientDefaultProtocolList = null;       // unlikely to be used
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1311
                clientDefaultCipherSuiteList = null;    // unlikely to be used
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1312
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1313
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1314
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1315
        protected CustomizedDTLSContext() {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1316
            if (reservedException != null) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1317
                throw reservedException;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1318
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1319
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1320
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1321
        @Override
34826
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1322
        ProtocolList getClientDefaultProtocolList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1323
            return clientDefaultProtocolList;
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1324
        }
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1325
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1326
        @Override
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1327
        CipherSuiteList getClientDefaultCipherSuiteList() {
4bbdce2630f8 8133070: Hot lock on BulkCipher.isAvailable
xuelei
parents: 32649
diff changeset
  1328
            return clientDefaultCipherSuiteList;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1329
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1330
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1331
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1332
    /*
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1333
     * The SSLContext implementation for default "DTLS" algorithm
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1334
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1335
     * @see SSLContext
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1336
     */
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1337
    public static final class DTLSContext extends CustomizedDTLSContext {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1338
        // use the default constructor and methods
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1339
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1340
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1343
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1344
final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1345
            implements X509TrustManager {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1346
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1347
    // the delegated trust manager
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1348
    private final X509TrustManager tm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1349
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1350
    AbstractTrustManagerWrapper(X509TrustManager tm) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1351
        this.tm = tm;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1352
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1353
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1354
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1355
    public void checkClientTrusted(X509Certificate[] chain, String authType)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1356
        throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1357
        tm.checkClientTrusted(chain, authType);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1358
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1359
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1360
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1361
    public void checkServerTrusted(X509Certificate[] chain, String authType)
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1362
        throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1363
        tm.checkServerTrusted(chain, authType);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1364
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1365
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1366
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1367
    public X509Certificate[] getAcceptedIssuers() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1368
        return tm.getAcceptedIssuers();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1369
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1370
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1371
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1372
    public void checkClientTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1373
                Socket socket) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1374
        tm.checkClientTrusted(chain, authType);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1375
        checkAdditionalTrust(chain, authType, socket, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1376
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1377
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1378
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1379
    public void checkServerTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1380
            Socket socket) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1381
        tm.checkServerTrusted(chain, authType);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1382
        checkAdditionalTrust(chain, authType, socket, false);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1383
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1384
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1385
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1386
    public void checkClientTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1387
            SSLEngine engine) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1388
        tm.checkClientTrusted(chain, authType);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1389
        checkAdditionalTrust(chain, authType, engine, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1390
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1391
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1392
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1393
    public void checkServerTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1394
            SSLEngine engine) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1395
        tm.checkServerTrusted(chain, authType);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1396
        checkAdditionalTrust(chain, authType, engine, false);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1397
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1398
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1399
    private void checkAdditionalTrust(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1400
                Socket socket, boolean isClient) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1401
        if (socket != null && socket.isConnected() &&
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1402
                                    socket instanceof SSLSocket) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1403
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1404
            SSLSocket sslSocket = (SSLSocket)socket;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1405
            SSLSession session = sslSocket.getHandshakeSession();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1406
            if (session == null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1407
                throw new CertificateException("No handshake session");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1408
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1409
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1410
            // check endpoint identity
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1411
            String identityAlg = sslSocket.getSSLParameters().
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1412
                                        getEndpointIdentificationAlgorithm();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1413
            if (identityAlg != null && identityAlg.length() != 0) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1414
                String hostname = session.getPeerHost();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1415
                X509TrustManagerImpl.checkIdentity(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1416
                                    hostname, chain[0], identityAlg);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1417
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1418
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1419
            // try the best to check the algorithm constraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1420
            ProtocolVersion protocolVersion =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1421
                ProtocolVersion.valueOf(session.getProtocol());
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1422
            AlgorithmConstraints constraints = null;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1423
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1424
                if (session instanceof ExtendedSSLSession) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1425
                    ExtendedSSLSession extSession =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1426
                                    (ExtendedSSLSession)session;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1427
                    String[] peerSupportedSignAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1428
                            extSession.getLocalSupportedSignatureAlgorithms();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1429
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1430
                    constraints = new SSLAlgorithmConstraints(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1431
                                    sslSocket, peerSupportedSignAlgs, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1432
                } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1433
                    constraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1434
                            new SSLAlgorithmConstraints(sslSocket, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1435
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1436
            } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1437
                constraints = new SSLAlgorithmConstraints(sslSocket, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1438
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1439
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
  1440
            checkAlgorithmConstraints(chain, constraints, isClient);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1441
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1442
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1443
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1444
    private void checkAdditionalTrust(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1445
            SSLEngine engine, boolean isClient) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1446
        if (engine != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1447
            SSLSession session = engine.getHandshakeSession();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1448
            if (session == null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1449
                throw new CertificateException("No handshake session");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1450
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1451
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1452
            // check endpoint identity
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1453
            String identityAlg = engine.getSSLParameters().
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1454
                                        getEndpointIdentificationAlgorithm();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1455
            if (identityAlg != null && identityAlg.length() != 0) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1456
                String hostname = session.getPeerHost();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1457
                X509TrustManagerImpl.checkIdentity(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1458
                                    hostname, chain[0], identityAlg);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1459
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1460
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1461
            // try the best to check the algorithm constraints
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1462
            ProtocolVersion protocolVersion =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1463
                ProtocolVersion.valueOf(session.getProtocol());
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1464
            AlgorithmConstraints constraints = null;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 28555
diff changeset
  1465
            if (protocolVersion.useTLS12PlusSpec()) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1466
                if (session instanceof ExtendedSSLSession) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1467
                    ExtendedSSLSession extSession =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1468
                                    (ExtendedSSLSession)session;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1469
                    String[] peerSupportedSignAlgs =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1470
                            extSession.getLocalSupportedSignatureAlgorithms();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1471
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1472
                    constraints = new SSLAlgorithmConstraints(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1473
                                    engine, peerSupportedSignAlgs, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1474
                } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1475
                    constraints =
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1476
                            new SSLAlgorithmConstraints(engine, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1477
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1478
            } else {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1479
                constraints = new SSLAlgorithmConstraints(engine, true);
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1480
            }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1481
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
  1482
            checkAlgorithmConstraints(chain, constraints, isClient);
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1483
        }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1484
    }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1485
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1486
    private void checkAlgorithmConstraints(X509Certificate[] chain,
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
  1487
            AlgorithmConstraints constraints, boolean isClient) throws CertificateException {
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1488
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1489
        try {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1490
            // Does the certificate chain end with a trusted certificate?
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1491
            int checkedLength = chain.length - 1;
12302
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents: 11037
diff changeset
  1492
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents: 11037
diff changeset
  1493
            Collection<X509Certificate> trustedCerts = new HashSet<>();
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents: 11037
diff changeset
  1494
            X509Certificate[] certs = tm.getAcceptedIssuers();
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents: 11037
diff changeset
  1495
            if ((certs != null) && (certs.length > 0)){
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents: 11037
diff changeset
  1496
                Collections.addAll(trustedCerts, certs);
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents: 11037
diff changeset
  1497
            }
0c8557ba0b8f 7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents: 11037
diff changeset
  1498
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1499
            if (trustedCerts.contains(chain[checkedLength])) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1500
                    checkedLength--;
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1501
            }
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1502
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1503
            // A forward checker, need to check from trust to target
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1504
            if (checkedLength >= 0) {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
  1505
                AlgorithmChecker checker =
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
  1506
                        new AlgorithmChecker(constraints, null,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 43009
diff changeset
  1507
                                (isClient ? Validator.VAR_TLS_CLIENT : Validator.VAR_TLS_SERVER));
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1508
                checker.init(false);
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1509
                for (int i = checkedLength; i >= 0; i--) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1510
                    Certificate cert = chain[i];
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1511
                    // We don't care about the unresolved critical extensions.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1512
                    checker.check(cert, Collections.<String>emptySet());
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1513
                }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1514
            }
11037
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1515
        } catch (CertPathValidatorException cpve) {
03c29eb4afa0 7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents: 10125
diff changeset
  1516
            throw new CertificateException(
40700
b75806acf716 8164846: CertificateException missing cause of underlying exception
coffeys
parents: 40275
diff changeset
  1517
                "Certificates do not conform to algorithm constraints", cpve);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1518
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1519
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1520
}
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1521
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
// Dummy X509TrustManager implementation, rejects all peer certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
// Used if the application did not specify a proper X509TrustManager.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1524
final class DummyX509TrustManager extends X509ExtendedTrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1525
            implements X509TrustManager {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    static final X509TrustManager INSTANCE = new DummyX509TrustManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    private DummyX509TrustManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * Given the partial or complete certificate chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * provided by the peer, build a certificate path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * to a trusted root and return if it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * validated and is trusted for client SSL authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * If not, it throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1540
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
    public void checkClientTrusted(X509Certificate[] chain, String authType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            "No X509TrustManager implementation avaiable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * Given the partial or complete certificate chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     * provided by the peer, build a certificate path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * to a trusted root and return if it can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     * validated and is trusted for server SSL authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * If not, it throws an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1554
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    public void checkServerTrusted(X509Certificate[] chain, String authType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            "No X509TrustManager implementation available");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     * Return an array of issuer certificates which are trusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * for authenticating peers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1565
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    public X509Certificate[] getAcceptedIssuers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        return new X509Certificate[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1569
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1570
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1571
    public void checkClientTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1572
                Socket socket) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1573
        throw new CertificateException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1574
            "No X509TrustManager implementation available");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1575
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1576
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1577
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1578
    public void checkServerTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1579
            Socket socket) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1580
        throw new CertificateException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1581
            "No X509TrustManager implementation available");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1582
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1583
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1584
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1585
    public void checkClientTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1586
            SSLEngine engine) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1587
        throw new CertificateException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1588
            "No X509TrustManager implementation available");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1589
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1590
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1591
    @Override
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1592
    public void checkServerTrusted(X509Certificate[] chain, String authType,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1593
            SSLEngine engine) throws CertificateException {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1594
        throw new CertificateException(
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1595
            "No X509TrustManager implementation available");
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1596
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
 * A wrapper class to turn a X509KeyManager into an X509ExtendedKeyManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
 */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1602
final class AbstractKeyManagerWrapper extends X509ExtendedKeyManager {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    private final X509KeyManager km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1606
    AbstractKeyManagerWrapper(X509KeyManager km) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        this.km = km;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1610
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    public String[] getClientAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        return km.getClientAliases(keyType, issuers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1615
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    public String chooseClientAlias(String[] keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        return km.chooseClientAlias(keyType, issuers, socket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1621
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    public String[] getServerAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        return km.getServerAliases(keyType, issuers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1626
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    public String chooseServerAlias(String keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        return km.chooseServerAlias(keyType, issuers, socket);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1632
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    public X509Certificate[] getCertificateChain(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        return km.getCertificateChain(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1637
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    public PrivateKey getPrivateKey(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        return km.getPrivateKey(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    // Inherit chooseEngineClientAlias() and chooseEngineServerAlias() from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    // X509ExtendedKeymanager. It defines them to return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
// Dummy X509KeyManager implementation, never returns any certificates/keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
// Used if the application did not specify a proper X509TrustManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
final class DummyX509KeyManager extends X509ExtendedKeyManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    static final X509ExtendedKeyManager INSTANCE = new DummyX509KeyManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    private DummyX509KeyManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * Get the matching aliases for authenticating the client side of a secure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * socket given the public key type and the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * certificate issuer authorities recognized by the peer (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1662
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    public String[] getClientAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * Choose an alias to authenticate the client side of a secure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * socket given the public key type and the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * certificate issuer authorities recognized by the peer (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1672
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
    public String chooseClientAlias(String[] keyTypes, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     * Choose an alias to authenticate the client side of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     * engine given the public key type and the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     * certificate issuer authorities recognized by the peer (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1683
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    public String chooseEngineClientAlias(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            String[] keyTypes, Principal[] issuers, SSLEngine engine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * Get the matching aliases for authenticating the server side of a secure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * socket given the public key type and the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * certificate issuer authorities recognized by the peer (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1694
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
    public String[] getServerAliases(String keyType, Principal[] issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * Choose an alias to authenticate the server side of a secure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * socket given the public key type and the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     * certificate issuer authorities recognized by the peer (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1704
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    public String chooseServerAlias(String keyType, Principal[] issuers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            Socket socket) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * Choose an alias to authenticate the server side of an engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * given the public key type and the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * certificate issuer authorities recognized by the peer (if any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1715
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    public String chooseEngineServerAlias(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            String keyType, Principal[] issuers, SSLEngine engine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * Returns the certificate chain associated with the given alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * @return the certificate chain (ordered with the user's certificate first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * and the root certificate authority last)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1729
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
    public X509Certificate[] getCertificateChain(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * Returns the key associated with the given alias, using the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * password to recover it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     * @return the requested key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 13815
diff changeset
  1742
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    public PrivateKey getPrivateKey(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
}