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