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