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