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