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