src/java.base/share/classes/sun/security/ssl/SSLSessionImpl.java
author xuelei
Fri, 05 Apr 2019 11:28:23 -0700
changeset 54443 dfba4e321ab3
parent 54253 01d8eae542ff
child 55336 c2398053ee90
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8221882: Use fiber-friendly java.util.concurrent.locks in JSSE Reviewed-by: alanb, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54099
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 52890
diff changeset
     2
 * Copyright (c) 1996, 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: 4236
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: 4236
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: 4236
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    27
import java.math.BigInteger;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    28
import java.net.InetAddress;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.PrivateKey;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    31
import java.security.cert.CertificateEncodingException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.X509Certificate;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    33
import java.util.ArrayList;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    34
import java.util.Queue;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    35
import java.util.Collection;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    36
import java.util.Collections;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    37
import java.util.Enumeration;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    38
import java.util.List;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    39
import java.util.concurrent.ConcurrentHashMap;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    40
import java.util.concurrent.ConcurrentLinkedQueue;
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
    41
import java.util.concurrent.locks.ReentrantLock;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.crypto.SecretKey;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    43
import javax.net.ssl.ExtendedSSLSession;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    44
import javax.net.ssl.SNIServerName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.net.ssl.SSLPeerUnverifiedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.net.ssl.SSLPermission;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    47
import javax.net.ssl.SSLSessionBindingEvent;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    48
import javax.net.ssl.SSLSessionBindingListener;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    49
import javax.net.ssl.SSLSessionContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Implements the SSL session interface, and exposes the session context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * which is maintained by SSL servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <P> Servers have the ability to manage the sessions associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * their authentication context(s).  They can do this by enumerating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * IDs of the sessions which are cached, examining those sessions, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * perhaps invalidating a given session so that it can't be used again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * If servers do not explicitly manage the cache, sessions will linger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * until memory is low enough that the runtime environment purges cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * entries automatically to reclaim space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <P><em> The only reason this class is not package-private is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * there's no other public way to get at the server session context which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * is associated with any given authentication context. </em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    69
final class SSLSessionImpl extends ExtendedSSLSession {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * we only really need a single null session
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    static final SSLSessionImpl         nullSession = new SSLSessionImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * The state of a single session, as described in section 7.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * of the SSLv3 spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private final ProtocolVersion       protocolVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private final SessionId             sessionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private X509Certificate[]   peerCerts;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    83
    private CipherSuite         cipherSuite;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private SecretKey           masterSecret;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    85
    final boolean               useExtendedMasterSecret;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Information not part of the SSLv3 protocol spec, but used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * to support session management policies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    91
    private final long          creationTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private long                lastUsedTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private final String        host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private final int           port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private SSLSessionContextImpl       context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private boolean             invalidated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private X509Certificate[]   localCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private PrivateKey          localPrivateKey;
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
    99
    private final Collection<SignatureScheme>     localSupportedSignAlgs;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   100
    private String[]            peerSupportedSignAlgs;      // for certificate
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   101
    private boolean             useDefaultPeerSignAlgs = false;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   102
    private List<byte[]>        statusResponses;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   103
    private SecretKey           resumptionMasterSecret;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   104
    private SecretKey           preSharedKey;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   105
    private byte[]              pskIdentity;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   106
    private final long          ticketCreationTime = System.currentTimeMillis();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   107
    private int                 ticketAgeAdd;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
   108
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   109
    private int                 negotiatedMaxFragLen = -1;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
   110
    private int                 maximumPacketSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   112
    private final Queue<SSLSessionImpl> childSessions =
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   113
                                        new ConcurrentLinkedQueue<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /*
27068
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   116
     * Is the session currently re-established with a session-resumption
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   117
     * abbreviated initial handshake?
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   118
     *
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   119
     * Note that currently we only set this variable in client side.
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   120
     */
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   121
    private boolean isSessionResumption = false;
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   122
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   123
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Use of session caches is globally enabled/disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static boolean      defaultRejoinable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   128
    // server name indication
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   129
    final SNIServerName         serverNameIndication;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   130
    private final List<SNIServerName>    requestedServerNames;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   131
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   132
    // Counter used to create unique nonces in NewSessionTicket
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   133
    private BigInteger ticketNonceCounter = BigInteger.ONE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   135
    // The endpoint identification algorithm used to check certificates
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   136
    // in this session.
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   137
    private final String        identificationProtocol;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   138
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   139
    private final ReentrantLock sessionLock = new ReentrantLock();
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   140
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Create a new non-rejoinable session, using the default (null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * cipher spec.  This constructor returns a session which could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * be used either by a client or by a server, as a connection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * first opened and before handshaking begins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private SSLSessionImpl() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   148
        this.protocolVersion = ProtocolVersion.NONE;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   149
        this.cipherSuite = CipherSuite.C_NULL;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   150
        this.sessionId = new SessionId(false, null);
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   151
        this.host = null;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   152
        this.port = -1;
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
   153
        this.localSupportedSignAlgs = Collections.emptySet();
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   154
        this.serverNameIndication = null;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   155
        this.requestedServerNames = Collections.<SNIServerName>emptyList();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   156
        this.useExtendedMasterSecret = false;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   157
        this.creationTime = System.currentTimeMillis();
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   158
        this.identificationProtocol = null;
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   159
        this.boundValues = new ConcurrentHashMap<>();
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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Create a new session, using a given cipher spec.  This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * be rejoinable if session caching is enabled; the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * is intended mostly for use by serves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   167
    SSLSessionImpl(HandshakeContext hc, CipherSuite cipherSuite) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   168
        this(hc, cipherSuite,
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   169
            new SessionId(defaultRejoinable, hc.sslContext.getSecureRandom()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Record a new session, using a given cipher spec and session ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   175
    SSLSessionImpl(HandshakeContext hc, CipherSuite cipherSuite, SessionId id) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   176
        this(hc, cipherSuite, id, System.currentTimeMillis());
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   177
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   178
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   179
    /*
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   180
     * Record a new session, using a given cipher spec, session ID,
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   181
     * and creation time.
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   182
     * Note: For the unmodifiable collections and lists we are creating new
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   183
     * collections as inputs to avoid potential deep nesting of
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   184
     * unmodifiable collections that can cause StackOverflowErrors
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   185
     * (see JDK-6323374).
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   186
     */
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   187
    SSLSessionImpl(HandshakeContext hc,
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   188
            CipherSuite cipherSuite, SessionId id, long creationTime) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   189
        this.protocolVersion = hc.negotiatedProtocol;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.cipherSuite = cipherSuite;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   191
        this.sessionId = id;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   192
        this.host = hc.conContext.transport.getPeerHost();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   193
        this.port = hc.conContext.transport.getPeerPort();
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
   194
        this.localSupportedSignAlgs = hc.localSupportedSignAlgs == null ?
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
   195
                Collections.emptySet() :
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   196
                Collections.unmodifiableCollection(
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   197
                        new ArrayList<>(hc.localSupportedSignAlgs));
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   198
        this.serverNameIndication = hc.negotiatedServerName;
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   199
        this.requestedServerNames = Collections.unmodifiableList(
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   200
                new ArrayList<>(hc.getRequestedServerNames()));
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   201
        if (hc.sslConfig.isClientMode) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   202
            this.useExtendedMasterSecret =
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   203
                (hc.handshakeExtensions.get(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   204
                        SSLExtension.CH_EXTENDED_MASTER_SECRET) != null) &&
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   205
                (hc.handshakeExtensions.get(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   206
                        SSLExtension.SH_EXTENDED_MASTER_SECRET) != null);
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   207
        } else {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   208
            this.useExtendedMasterSecret =
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   209
                (hc.handshakeExtensions.get(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   210
                        SSLExtension.CH_EXTENDED_MASTER_SECRET) != null) &&
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   211
                (!hc.negotiatedProtocol.useTLS13PlusSpec());
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   212
        }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   213
        this.creationTime = creationTime;
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   214
        this.identificationProtocol = hc.sslConfig.identificationProtocol;
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   215
        this.boundValues = new ConcurrentHashMap<>();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   216
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   217
        if (SSLLogger.isOn && SSLLogger.isOn("session")) {
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   218
             SSLLogger.finest("Session initialized:  " + this);
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   219
        }
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   220
    }
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   221
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   222
    SSLSessionImpl(SSLSessionImpl baseSession, SessionId newId) {
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   223
        this.protocolVersion = baseSession.getProtocolVersion();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   224
        this.cipherSuite = baseSession.cipherSuite;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   225
        this.sessionId = newId;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   226
        this.host = baseSession.getPeerHost();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   227
        this.port = baseSession.getPeerPort();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   228
        this.localSupportedSignAlgs =
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   229
                baseSession.localSupportedSignAlgs == null ?
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   230
                Collections.emptySet() : baseSession.localSupportedSignAlgs;
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   231
        this.peerSupportedSignAlgs =
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   232
                baseSession.getPeerSupportedSignatureAlgorithms();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   233
        this.serverNameIndication = baseSession.serverNameIndication;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   234
        this.requestedServerNames = baseSession.getRequestedServerNames();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   235
        this.masterSecret = baseSession.getMasterSecret();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   236
        this.useExtendedMasterSecret = baseSession.useExtendedMasterSecret;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   237
        this.creationTime = baseSession.getCreationTime();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   238
        this.lastUsedTime = System.currentTimeMillis();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   239
        this.identificationProtocol = baseSession.getIdentificationProtocol();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   240
        this.localCerts = baseSession.localCerts;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   241
        this.peerCerts = baseSession.peerCerts;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   242
        this.statusResponses = baseSession.statusResponses;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   243
        this.resumptionMasterSecret = baseSession.resumptionMasterSecret;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   244
        this.context = baseSession.context;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   245
        this.negotiatedMaxFragLen = baseSession.negotiatedMaxFragLen;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   246
        this.maximumPacketSize = baseSession.maximumPacketSize;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   247
        this.boundValues = baseSession.boundValues;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   249
        if (SSLLogger.isOn && SSLLogger.isOn("session")) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   250
             SSLLogger.finest("Session initialized:  " + this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    void setMasterSecret(SecretKey secret) {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   255
        masterSecret = secret;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   256
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   257
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   258
    void setResumptionMasterSecret(SecretKey secret) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   259
        resumptionMasterSecret = secret;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   260
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   261
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   262
    void setPreSharedKey(SecretKey key) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   263
        preSharedKey = key;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   264
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   265
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   266
    void addChild(SSLSessionImpl session) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   267
        childSessions.add(session);
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   268
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   269
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   270
    void setTicketAgeAdd(int ticketAgeAdd) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   271
        this.ticketAgeAdd = ticketAgeAdd;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   272
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   273
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   274
    void setPskIdentity(byte[] pskIdentity) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   275
        this.pskIdentity = pskIdentity;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   276
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   277
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   278
    BigInteger incrTicketNonceCounter() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   279
        BigInteger result = ticketNonceCounter;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   280
        ticketNonceCounter = ticketNonceCounter.add(BigInteger.valueOf(1));
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   281
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Returns the master secret ... treat with extreme caution!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    SecretKey getMasterSecret() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return masterSecret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   291
    SecretKey getResumptionMasterSecret() {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   292
        return resumptionMasterSecret;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   293
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   294
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   295
    SecretKey getPreSharedKey() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   296
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   297
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   298
            return preSharedKey;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   299
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   300
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   301
        }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   302
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   303
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   304
    SecretKey consumePreSharedKey() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   305
        sessionLock.lock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   306
        try {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   307
            return preSharedKey;
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   308
        } finally {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   309
            preSharedKey = null;
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   310
            sessionLock.unlock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   311
        }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   312
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   313
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   314
    int getTicketAgeAdd() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   315
        return ticketAgeAdd;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   316
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   317
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   318
    String getIdentificationProtocol() {
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   319
        return this.identificationProtocol;
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   320
    }
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   321
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   322
    /* PSK identities created from new_session_ticket messages should only
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   323
     * be used once. This method will return the identity and then clear it
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   324
     * so it cannot be used again.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   325
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   326
    byte[] consumePskIdentity() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   327
        sessionLock.lock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   328
        try {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   329
            return pskIdentity;
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   330
        } finally {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   331
            pskIdentity = null;
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   332
            sessionLock.unlock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   333
        }
48225
718669e6b375 8148421: Transport Layer Security (TLS) Session Hash and Extended Master Secret Extension
xuelei
parents: 47216
diff changeset
   334
    }
718669e6b375 8148421: Transport Layer Security (TLS) Session Hash and Extended Master Secret Extension
xuelei
parents: 47216
diff changeset
   335
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    void setPeerCertificates(X509Certificate[] peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            peerCerts = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    void setLocalCertificates(X509Certificate[] local) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        localCerts = local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    void setLocalPrivateKey(PrivateKey privateKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        localPrivateKey = privateKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   350
    void setPeerSupportedSignatureAlgorithms(
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   351
            Collection<SignatureScheme> signatureSchemes) {
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   352
        peerSupportedSignAlgs =
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   353
            SignatureScheme.getAlgorithmNames(signatureSchemes);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   354
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   355
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   356
    // TLS 1.2 only
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   357
    //
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   358
    // Per RFC 5246, If the client supports only the default hash
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   359
    // and signature algorithms, it MAY omit the
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   360
    // signature_algorithms extension.  If the client does not
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   361
    // support the default algorithms, or supports other hash
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   362
    // and signature algorithms (and it is willing to use them
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   363
    // for verifying messages sent by the server, i.e., server
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   364
    // certificates and server key exchange), it MUST send the
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   365
    // signature_algorithms extension, listing the algorithms it
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   366
    // is willing to accept.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   367
    void setUseDefaultPeerSignAlgs() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   368
        useDefaultPeerSignAlgs = true;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   369
        peerSupportedSignAlgs = new String[] {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   370
            "SHA1withRSA", "SHA1withDSA", "SHA1withECDSA"};
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   371
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   372
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   373
    // Returns the connection session.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   374
    SSLSessionImpl finish() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   375
        if (useDefaultPeerSignAlgs) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   376
            this.peerSupportedSignAlgs = new String[0];
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   377
        }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   378
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   379
        return this;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
   380
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
   381
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   383
     * Provide status response data obtained during the SSL handshake.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   384
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   385
     * @param responses a {@link List} of responses in binary form.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   386
     */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   387
    void setStatusResponses(List<byte[]> responses) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   388
        if (responses != null && !responses.isEmpty()) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   389
            statusResponses = responses;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   390
        } else {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   391
            statusResponses = Collections.emptyList();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   392
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   393
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   394
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   395
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * Returns true iff this session may be resumed ... sessions are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * usually resumable.  Security policies may suggest otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * for example sessions that haven't been used for a while (say,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * a working day) won't be resumable, and sessions might have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * maximum lifetime in any case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    boolean isRejoinable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return sessionId != null && sessionId.length() != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            !invalidated && isLocalAuthenticationValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   407
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   408
    public boolean isValid() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   409
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   410
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   411
            return isRejoinable();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   412
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   413
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   414
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Check if the authentication used when establishing this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * is still valid. Returns true if no authentication was used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   421
    private boolean isLocalAuthenticationValid() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (localPrivateKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                // if the private key is no longer valid, getAlgorithm()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                // should throw an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                // (e.g. Smartcard has been removed from the reader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                localPrivateKey.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   433
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Returns the ID for this session.  The ID is fixed for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * duration of the session; neither it, nor its value, changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   441
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public byte[] getId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return sessionId.getId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * For server sessions, this returns the set of sessions which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * are currently valid in this process.  For client sessions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * this returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   451
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public SSLSessionContext getSessionContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         * An interim security policy until we can do something
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
         * more specific in 1.2. Only allow trusted code (code which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
         * can set system properties) to get an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
         * SSLSessionContext. This is to limit the ability of code to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
         * look up specific sessions or enumerate over them. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * code can only get session objects from successful SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         * connections which implies that they must have had permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         * to make the network connection in the first place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        SecurityManager sm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if ((sm = System.getSecurityManager()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            sm.checkPermission(new SSLPermission("getSSLSessionContext"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    SessionId getSessionId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return sessionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Returns the cipher spec in use on this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    CipherSuite getSuite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return cipherSuite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   485
     * Resets the cipher spec in use on this session
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   486
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   487
    void setSuite(CipherSuite suite) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   488
       cipherSuite = suite;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   489
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   490
        if (SSLLogger.isOn && SSLLogger.isOn("session")) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   491
             SSLLogger.finest("Negotiating session:  " + this);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   492
       }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   493
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   494
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   495
    /**
27068
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   496
     * Return true if the session is currently re-established with a
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   497
     * session-resumption abbreviated initial handshake.
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   498
     */
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   499
    boolean isSessionResumption() {
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   500
        return isSessionResumption;
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   501
    }
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   502
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   503
    /**
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   504
     * Resets whether the session is re-established with a session-resumption
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   505
     * abbreviated initial handshake.
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   506
     */
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   507
    void setAsSessionResumption(boolean flag) {
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   508
        isSessionResumption = flag;
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   509
    }
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   510
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   511
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Returns the name of the cipher suite in use on this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   514
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public String getCipherSuite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return getSuite().name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    ProtocolVersion getProtocolVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return protocolVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Returns the standard name of the protocol in use on this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   526
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    public String getProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return getProtocolVersion().name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Returns the hashcode for this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   534
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        return sessionId.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Returns true if sessions have same ids, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   542
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (obj == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (obj instanceof SSLSessionImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            SSLSessionImpl sess = (SSLSessionImpl) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return (sessionId != null) && (sessionId.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                        sess.getSessionId()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * Return the cert chain presented by the peer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * java.security.cert format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * Note: This method can be used only when using certificate-based
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   563
     * cipher suites; using it with non-certificate-based cipher suites
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   564
     * will throw an SSLPeerUnverifiedException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *  first in the chain, and with the "root" CA last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   569
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public java.security.cert.Certificate[] getPeerCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        // clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        // change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        // Certs are immutable objects, therefore we don't clone them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        // But do need to clone the array, so that nothing is inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        // into peerCerts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        return (java.security.cert.Certificate[])peerCerts.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * Return the cert chain presented to the peer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * java.security.cert format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Note: This method is useful only when using certificate-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * cipher suites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *  first in the chain, and with the "root" CA last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   595
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public java.security.cert.Certificate[] getLocalCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        // clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        // change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        // less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return (localCerts == null ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            (java.security.cert.Certificate[])localCerts.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Return the cert chain presented by the peer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * javax.security.cert format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Note: This method can be used only when using certificate-based
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   609
     * cipher suites; using it with non-certificate-based cipher suites
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   610
     * will throw an SSLPeerUnverifiedException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *  first in the chain, and with the "root" CA last.
29377
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 27068
diff changeset
   614
     *
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 27068
diff changeset
   615
     * @deprecated This method returns the deprecated
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 27068
diff changeset
   616
     *  {@code javax.security.cert.X509Certificate} type.
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 27068
diff changeset
   617
     *  Use {@code getPeerCertificates()} instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   619
    @Override
54099
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 52890
diff changeset
   620
    @SuppressWarnings("removal")
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 52890
diff changeset
   621
    @Deprecated(since="9", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public javax.security.cert.X509Certificate[] getPeerCertificateChain()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        // clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        // change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        javax.security.cert.X509Certificate[] certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        certs = new javax.security.cert.X509Certificate[peerCerts.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        for (int i = 0; i < peerCerts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            byte[] der = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                der = peerCerts[i].getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                certs[i] = javax.security.cert.X509Certificate.getInstance(der);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            } catch (CertificateEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                throw new SSLPeerUnverifiedException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            } catch (javax.security.cert.CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                throw new SSLPeerUnverifiedException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * Return the cert chain presented by the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Note: This method can be used only when using certificate-based
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   652
     * cipher suites; using it with non-certificate-based cipher suites
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   653
     * will throw an SSLPeerUnverifiedException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *  first in the chain, and with the "root" CA last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    public X509Certificate[] getCertificateChain()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
         * clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
         * change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
         * less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (peerCerts != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   666
            return peerCerts.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    /**
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   673
     * Return a List of status responses presented by the peer.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   674
     * Note: This method can be used only when using certificate-based
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   675
     * server authentication; otherwise an empty {@code List} will be returned.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   676
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   677
     * @return an unmodifiable {@code List} of byte arrays, each consisting
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   678
     * of a DER-encoded OCSP response (see RFC 6960).  If no responses have
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   679
     * been presented by the server or non-certificate based server
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   680
     * authentication is used then an empty {@code List} is returned.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   681
     */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   682
    @Override
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   683
    public List<byte[]> getStatusResponses() {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   684
        if (statusResponses == null || statusResponses.isEmpty()) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   685
            return Collections.emptyList();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   686
        } else {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   687
            // Clone both the list and the contents
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   688
            List<byte[]> responses = new ArrayList<>(statusResponses.size());
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   689
            for (byte[] respBytes : statusResponses) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   690
                responses.add(respBytes.clone());
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   691
            }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   692
            return Collections.unmodifiableList(responses);
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   693
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   694
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   695
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   696
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Returns the identity of the peer which was established as part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * defining the session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @return the peer's principal. Returns an X500Principal of the
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   701
     * end-entity certificate for X509-based cipher suites.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @throws SSLPeerUnverifiedException if the peer's identity has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *          been verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   706
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    public Principal getPeerPrincipal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                throws SSLPeerUnverifiedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   713
        return peerCerts[0].getSubjectX500Principal();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * Returns the principal that was sent to the peer during handshaking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @return the principal sent to the peer. Returns an X500Principal
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   720
     * of the end-entity certificate for X509-based cipher suites.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   721
     * If no principal was sent, then null is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   723
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    public Principal getLocalPrincipal() {
50987
e4a92c455d1c 8206355: SSLSessionImpl.getLocalPrincipal() throws NPE
ssahoo
parents: 50768
diff changeset
   725
        return ((localCerts == null || localCerts.length == 0) ? null :
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   726
                localCerts[0].getSubjectX500Principal());
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   727
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   729
    /*
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   730
     * Return the time the ticket for this session was created.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   731
     */
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   732
    public long getTicketCreationTime() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   733
        return ticketCreationTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * Returns the time this session was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   739
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    public long getCreationTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        return creationTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * Returns the last time this session was used to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * a connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   748
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public long getLastAccessedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        return (lastUsedTime != 0) ? lastUsedTime : creationTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    void setLastAccessedTime(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        lastUsedTime = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * Returns the network address of the session's peer.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * implementation does not insist that connections between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * different ports on the same host must necessarily belong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * to different sessions, though that is of course allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public InetAddress getPeerAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            return InetAddress.getByName(host);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        } catch (java.net.UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   772
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    public String getPeerHost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        return host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * Need to provide the port info for caching sessions based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * host and port. Accessed by SSLSessionContextImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   781
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public int getPeerPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        return port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    void setContext(SSLSessionContextImpl ctx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            context = ctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Invalidate a session.  Active connections may still exist, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * no connections will be able to rejoin this session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   796
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   797
    public void invalidate() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   798
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   799
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   800
            //
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   801
            // Can't invalidate the NULL session -- this would be
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   802
            // attempted when we get a handshaking error on a brand
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   803
            // new connection, with no "real" session yet.
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   804
            //
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   805
            if (this == nullSession) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   806
                return;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   807
            }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   808
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   809
            if (context != null) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   810
                context.remove(sessionId);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   811
                context = null;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   812
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   813
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   814
            if (invalidated) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   815
                return;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   816
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   817
            invalidated = true;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   818
            if (SSLLogger.isOn && SSLLogger.isOn("session")) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   819
                 SSLLogger.finest("Invalidated session:  " + this);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   820
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   821
            for (SSLSessionImpl child : childSessions) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   822
                child.invalidate();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   823
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   824
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   825
            sessionLock.unlock();
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   826
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Table of application-specific session data indexed by an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * key and the calling security context. This is important since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * sessions can be shared across different protection domains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   834
    private final ConcurrentHashMap<SecureKey, Object> boundValues;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * Assigns a session value.  Session change events are given if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * appropriate, to any original value as well as the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   840
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public void putValue(String key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        if ((key == null) || (value == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            throw new IllegalArgumentException("arguments can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        SecureKey secureKey = new SecureKey(key);
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   847
        Object oldValue = boundValues.put(secureKey, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        if (oldValue instanceof SSLSessionBindingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            SSLSessionBindingEvent e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            e = new SSLSessionBindingEvent(this, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            ((SSLSessionBindingListener)oldValue).valueUnbound(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        if (value instanceof SSLSessionBindingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            SSLSessionBindingEvent e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            e = new SSLSessionBindingEvent(this, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            ((SSLSessionBindingListener)value).valueBound(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * Returns the specified session value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   866
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    public Object getValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            throw new IllegalArgumentException("argument can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        SecureKey secureKey = new SecureKey(key);
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   873
        return boundValues.get(secureKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * Removes the specified session value, delivering a session changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * event as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   881
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    public void removeValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            throw new IllegalArgumentException("argument can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        SecureKey secureKey = new SecureKey(key);
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   888
        Object value = boundValues.remove(secureKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        if (value instanceof SSLSessionBindingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            SSLSessionBindingEvent e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            e = new SSLSessionBindingEvent(this, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            ((SSLSessionBindingListener)value).valueUnbound(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * Lists the names of the session values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   902
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    public String[] getValueNames() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   904
        ArrayList<Object> v = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        Object securityCtx = SecureKey.getCurrentSecurityContext();
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   906
        for (Enumeration<SecureKey> e = boundValues.keys();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   907
                e.hasMoreElements(); ) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   908
            SecureKey key = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            if (securityCtx.equals(key.getSecurityContext())) {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   910
                v.add(key.getAppKey());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   914
        return v.toArray(new String[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * Use large packet sizes now or follow RFC 2246 packet sizes (2^14)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * until changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * In the TLS specification (section 6.2.1, RFC2246), it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * recommended that the plaintext has more than 2^14 bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * However, some TLS implementations violate the specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * This is a workaround for interoperability with these stacks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * Application could accept large fragments up to 2^15 bytes by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * setting the system property jsse.SSLEngine.acceptLargeFragments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * to "true".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    private boolean acceptLargeFragments =
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   931
            Utilities.getBooleanProperty(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   932
                    "jsse.SSLEngine.acceptLargeFragments", false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * Expand the buffer size of both SSL/TLS network packet and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   938
    protected void expandBufferSizes() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   939
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   940
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   941
            acceptLargeFragments = true;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   942
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   943
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   944
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Gets the current size of the largest SSL/TLS packet that is expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * when using this session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   951
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   952
    public int getPacketBufferSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   953
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   954
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   955
            // Use the bigger packet size calculated from maximumPacketSize
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   956
            // and negotiatedMaxFragLen.
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   957
            int packetSize = 0;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   958
            if (negotiatedMaxFragLen > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   959
                packetSize = cipherSuite.calculatePacketSize(
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   960
                        negotiatedMaxFragLen, protocolVersion,
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   961
                        protocolVersion.isDTLS);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   962
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
   963
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   964
            if (maximumPacketSize > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   965
                return (maximumPacketSize > packetSize) ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   966
                        maximumPacketSize : packetSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   967
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   968
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   969
            if (packetSize != 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   970
               return packetSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   971
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
   972
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   973
            if (protocolVersion.isDTLS) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   974
                return DTLSRecord.maxRecordSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   975
            } else {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   976
                return acceptLargeFragments ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   977
                        SSLRecord.maxLargeRecordSize : SSLRecord.maxRecordSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   978
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   979
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   980
            sessionLock.unlock();
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
   981
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * Gets the current size of the largest application data that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * expected when using this session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   988
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   989
    public int getApplicationBufferSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   990
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   991
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   992
            // Use the bigger fragment size calculated from maximumPacketSize
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   993
            // and negotiatedMaxFragLen.
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   994
            int fragmentSize = 0;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   995
            if (maximumPacketSize > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   996
                fragmentSize = cipherSuite.calculateFragSize(
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   997
                        maximumPacketSize, protocolVersion,
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   998
                        protocolVersion.isDTLS);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   999
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1000
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1001
            if (negotiatedMaxFragLen > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1002
                return (negotiatedMaxFragLen > fragmentSize) ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1003
                        negotiatedMaxFragLen : fragmentSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1004
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1005
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1006
            if (fragmentSize != 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1007
                return fragmentSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1008
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1009
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1010
            if (protocolVersion.isDTLS) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1011
                return Record.maxDataSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1012
            } else {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1013
                int maxPacketSize = acceptLargeFragments ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1014
                            SSLRecord.maxLargeRecordSize : SSLRecord.maxRecordSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1015
                return (maxPacketSize - SSLRecord.headerSize);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1016
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1017
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1018
            sessionLock.unlock();
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1019
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1020
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1021
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1022
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1023
     * Sets the negotiated maximum fragment length, as specified by the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1024
     * max_fragment_length ClientHello extension in RFC 6066.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1025
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1026
     * @param  negotiatedMaxFragLen
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1027
     *         the negotiated maximum fragment length, or {@code -1} if
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1028
     *         no such length has been negotiated.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1029
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1030
    void setNegotiatedMaxFragSize(
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1031
            int negotiatedMaxFragLen) {
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1032
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1033
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1034
            this.negotiatedMaxFragLen = negotiatedMaxFragLen;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1035
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1036
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1037
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1038
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1039
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1040
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1041
     * Get the negotiated maximum fragment length, as specified by the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1042
     * max_fragment_length ClientHello extension in RFC 6066.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1043
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1044
     * @return the negotiated maximum fragment length, or {@code -1} if
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1045
     *         no such length has been negotiated.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1046
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1047
    int getNegotiatedMaxFragSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1048
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1049
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1050
            return negotiatedMaxFragLen;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1051
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1052
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1053
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1054
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1055
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1056
    void setMaximumPacketSize(int maximumPacketSize) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1057
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1058
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1059
            this.maximumPacketSize = maximumPacketSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1060
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1061
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1062
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1063
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1064
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1065
    int getMaximumPacketSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1066
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1067
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1068
            return maximumPacketSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1069
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1070
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1071
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1074
    /**
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1075
     * Gets an array of supported signature algorithm names that the local
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1076
     * side is willing to verify.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1077
     */
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1078
    @Override
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1079
    public String[] getLocalSupportedSignatureAlgorithms() {
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1080
        return SignatureScheme.getAlgorithmNames(localSupportedSignAlgs);
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1081
    }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1082
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1083
    /**
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1084
     * Gets an array of supported signature schemes that the local side is
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1085
     * willing to verify.
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1086
     */
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1087
    public Collection<SignatureScheme> getLocalSupportedSignatureSchemes() {
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1088
        return localSupportedSignAlgs;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1089
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1090
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1091
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1092
     * Gets an array of supported signature algorithms that the peer is
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1093
     * able to verify.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1094
     */
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1095
    @Override
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1096
    public String[] getPeerSupportedSignatureAlgorithms() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1097
        if (peerSupportedSignAlgs != null) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1098
            return peerSupportedSignAlgs.clone();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1099
        }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1100
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1101
        return new String[0];
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1102
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1103
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1104
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1105
     * Obtains a <code>List</code> containing all {@link SNIServerName}s
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1106
     * of the requested Server Name Indication (SNI) extension.
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1107
     */
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1108
    @Override
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1109
    public List<SNIServerName> getRequestedServerNames() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1110
        return requestedServerNames;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1111
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1112
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    /** Returns a string representation of this SSL session */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1114
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    public String toString() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1116
        return "Session(" + creationTime + "|" + getCipherSuite() + ")";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
 * This "struct" class serves as a Hash Key that combines an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
 * application-specific key and a security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
class SecureKey {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1125
    private static final Object     nullObject = new Object();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1126
    private final Object            appKey;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1127
    private final Object            securityCtx;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    static Object getCurrentSecurityContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        Object context = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            context = sm.getSecurityContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        if (context == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            context = nullObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    SecureKey(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        this.appKey = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        this.securityCtx = getCurrentSecurityContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    Object getAppKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        return appKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    Object getSecurityContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        return securityCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1153
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        return appKey.hashCode() ^ securityCtx.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1158
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        return o instanceof SecureKey && ((SecureKey)o).appKey.equals(appKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                        && ((SecureKey)o).securityCtx.equals(securityCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
}