src/java.base/share/classes/sun/security/ssl/SSLSessionImpl.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57485 af4b0fc25bc4
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54099
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 52890
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
    27
import sun.security.x509.X509CertImpl;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
    28
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
    29
import java.io.IOException;
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
    30
import java.lang.reflect.Array;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    31
import java.math.BigInteger;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    32
import java.net.InetAddress;
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
    33
import java.nio.ByteBuffer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PrivateKey;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    36
import java.security.cert.CertificateEncodingException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.cert.X509Certificate;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    38
import java.util.ArrayList;
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
    39
import java.util.Arrays;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    40
import java.util.Queue;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    41
import java.util.Collection;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    42
import java.util.Collections;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    43
import java.util.Enumeration;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    44
import java.util.List;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    45
import java.util.concurrent.ConcurrentHashMap;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    46
import java.util.concurrent.ConcurrentLinkedQueue;
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
    47
import java.util.concurrent.locks.ReentrantLock;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.crypto.SecretKey;
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
    49
import javax.crypto.spec.SecretKeySpec;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    50
import javax.net.ssl.ExtendedSSLSession;
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
    51
import javax.net.ssl.SNIHostName;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    52
import javax.net.ssl.SNIServerName;
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
    53
import javax.net.ssl.SSLException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.net.ssl.SSLPeerUnverifiedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.net.ssl.SSLPermission;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    56
import javax.net.ssl.SSLSessionBindingEvent;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    57
import javax.net.ssl.SSLSessionBindingListener;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    58
import javax.net.ssl.SSLSessionContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Implements the SSL session interface, and exposes the session context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * which is maintained by SSL servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <P> Servers have the ability to manage the sessions associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * their authentication context(s).  They can do this by enumerating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * IDs of the sessions which are cached, examining those sessions, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * perhaps invalidating a given session so that it can't be used again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * If servers do not explicitly manage the cache, sessions will linger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * until memory is low enough that the runtime environment purges cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * entries automatically to reclaim space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <P><em> The only reason this class is not package-private is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * there's no other public way to get at the server session context which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * is associated with any given authentication context. </em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    78
final class SSLSessionImpl extends ExtendedSSLSession {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * we only really need a single null session
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static final SSLSessionImpl         nullSession = new SSLSessionImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * The state of a single session, as described in section 7.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * of the SSLv3 spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private final ProtocolVersion       protocolVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private final SessionId             sessionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private X509Certificate[]   peerCerts;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
    92
    private CipherSuite         cipherSuite;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private SecretKey           masterSecret;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
    94
    final boolean               useExtendedMasterSecret;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Information not part of the SSLv3 protocol spec, but used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * to support session management policies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   100
    private final long          creationTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private long                lastUsedTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private final String        host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private final int           port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private SSLSessionContextImpl       context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private boolean             invalidated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private X509Certificate[]   localCerts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private PrivateKey          localPrivateKey;
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
   108
    private final Collection<SignatureScheme>     localSupportedSignAlgs;
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   109
    private Collection<SignatureScheme> peerSupportedSignAlgs; //for certificate
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   110
    private boolean             useDefaultPeerSignAlgs = false;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   111
    private List<byte[]>        statusResponses;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   112
    private SecretKey           resumptionMasterSecret;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   113
    private SecretKey           preSharedKey;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   114
    private byte[]              pskIdentity;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   115
    private final long          ticketCreationTime = System.currentTimeMillis();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   116
    private int                 ticketAgeAdd;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
   117
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   118
    private int                 negotiatedMaxFragLen = -1;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
   119
    private int                 maximumPacketSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   121
    private final Queue<SSLSessionImpl> childSessions =
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   122
                                        new ConcurrentLinkedQueue<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
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
     * Use of session caches is globally enabled/disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private static boolean      defaultRejoinable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   137
    // server name indication
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   138
    final SNIServerName         serverNameIndication;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   139
    private final List<SNIServerName>    requestedServerNames;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   140
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   141
    // Counter used to create unique nonces in NewSessionTicket
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   142
    private BigInteger ticketNonceCounter = BigInteger.ONE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   144
    // The endpoint identification algorithm used to check certificates
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   145
    // in this session.
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   146
    private final String        identificationProtocol;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   147
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   148
    private final ReentrantLock sessionLock = new ReentrantLock();
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   149
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Create a new non-rejoinable session, using the default (null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * cipher spec.  This constructor returns a session which could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * be used either by a client or by a server, as a connection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * first opened and before handshaking begins.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private SSLSessionImpl() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   157
        this.protocolVersion = ProtocolVersion.NONE;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   158
        this.cipherSuite = CipherSuite.C_NULL;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   159
        this.sessionId = new SessionId(false, null);
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   160
        this.host = null;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   161
        this.port = -1;
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
   162
        this.localSupportedSignAlgs = Collections.emptySet();
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   163
        this.serverNameIndication = null;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   164
        this.requestedServerNames = Collections.<SNIServerName>emptyList();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   165
        this.useExtendedMasterSecret = false;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   166
        this.creationTime = System.currentTimeMillis();
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   167
        this.identificationProtocol = null;
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   168
        this.boundValues = new ConcurrentHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Create a new session, using a given cipher spec.  This will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * be rejoinable if session caching is enabled; the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * is intended mostly for use by serves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   176
    SSLSessionImpl(HandshakeContext hc, CipherSuite cipherSuite) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   177
        this(hc, cipherSuite,
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   178
            new SessionId(defaultRejoinable, hc.sslContext.getSecureRandom()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Record a new session, using a given cipher spec and session ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   184
    SSLSessionImpl(HandshakeContext hc, CipherSuite cipherSuite, SessionId id) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   185
        this(hc, cipherSuite, id, System.currentTimeMillis());
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   186
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   187
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   188
    /*
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   189
     * Record a new session, using a given cipher spec, session ID,
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   190
     * and creation time.
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   191
     * Note: For the unmodifiable collections and lists we are creating new
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   192
     * collections as inputs to avoid potential deep nesting of
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   193
     * unmodifiable collections that can cause StackOverflowErrors
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   194
     * (see JDK-6323374).
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   195
     */
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   196
    SSLSessionImpl(HandshakeContext hc,
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   197
            CipherSuite cipherSuite, SessionId id, long creationTime) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   198
        this.protocolVersion = hc.negotiatedProtocol;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this.cipherSuite = cipherSuite;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   200
        this.sessionId = id;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   201
        this.host = hc.conContext.transport.getPeerHost();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   202
        this.port = hc.conContext.transport.getPeerPort();
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
   203
        this.localSupportedSignAlgs = hc.localSupportedSignAlgs == null ?
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
   204
                Collections.emptySet() :
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   205
                Collections.unmodifiableCollection(
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   206
                        new ArrayList<>(hc.localSupportedSignAlgs));
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   207
        this.serverNameIndication = hc.negotiatedServerName;
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   208
        this.requestedServerNames = Collections.unmodifiableList(
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   209
                new ArrayList<>(hc.getRequestedServerNames()));
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   210
        if (hc.sslConfig.isClientMode) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   211
            this.useExtendedMasterSecret =
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   212
                (hc.handshakeExtensions.get(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   213
                        SSLExtension.CH_EXTENDED_MASTER_SECRET) != null) &&
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   214
                (hc.handshakeExtensions.get(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   215
                        SSLExtension.SH_EXTENDED_MASTER_SECRET) != null);
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   216
        } else {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   217
            this.useExtendedMasterSecret =
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   218
                (hc.handshakeExtensions.get(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   219
                        SSLExtension.CH_EXTENDED_MASTER_SECRET) != null) &&
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   220
                (!hc.negotiatedProtocol.useTLS13PlusSpec());
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   221
        }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   222
        this.creationTime = creationTime;
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   223
        this.identificationProtocol = hc.sslConfig.identificationProtocol;
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   224
        this.boundValues = new ConcurrentHashMap<>();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   225
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   226
        if (SSLLogger.isOn && SSLLogger.isOn("session")) {
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   227
             SSLLogger.finest("Session initialized:  " + this);
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   228
        }
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   229
    }
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   230
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   231
    SSLSessionImpl(SSLSessionImpl baseSession, SessionId newId) {
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   232
        this.protocolVersion = baseSession.getProtocolVersion();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   233
        this.cipherSuite = baseSession.cipherSuite;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   234
        this.sessionId = newId;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   235
        this.host = baseSession.getPeerHost();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   236
        this.port = baseSession.getPeerPort();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   237
        this.localSupportedSignAlgs =
52890
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   238
                baseSession.localSupportedSignAlgs == null ?
b0e751c70385 8214129: SSL session resumption/SNI with TLS1.2 causes StackOverflowError
jnimeh
parents: 52643
diff changeset
   239
                Collections.emptySet() : baseSession.localSupportedSignAlgs;
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   240
        this.peerSupportedSignAlgs =
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   241
                baseSession.peerSupportedSignAlgs == null ?
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   242
                Collections.emptySet() : baseSession.peerSupportedSignAlgs;
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   243
        this.serverNameIndication = baseSession.serverNameIndication;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   244
        this.requestedServerNames = baseSession.getRequestedServerNames();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   245
        this.masterSecret = baseSession.getMasterSecret();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   246
        this.useExtendedMasterSecret = baseSession.useExtendedMasterSecret;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   247
        this.creationTime = baseSession.getCreationTime();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   248
        this.lastUsedTime = System.currentTimeMillis();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   249
        this.identificationProtocol = baseSession.getIdentificationProtocol();
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   250
        this.localCerts = baseSession.localCerts;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   251
        this.peerCerts = baseSession.peerCerts;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   252
        this.statusResponses = baseSession.statusResponses;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   253
        this.resumptionMasterSecret = baseSession.resumptionMasterSecret;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   254
        this.context = baseSession.context;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   255
        this.negotiatedMaxFragLen = baseSession.negotiatedMaxFragLen;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   256
        this.maximumPacketSize = baseSession.maximumPacketSize;
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
   257
        this.boundValues = baseSession.boundValues;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   259
        if (SSLLogger.isOn && SSLLogger.isOn("session")) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   260
             SSLLogger.finest("Session initialized:  " + this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   264
    /**
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   265
     * < 2 bytes > protocolVersion
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   266
     * < 2 bytes > cipherSuite
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   267
     * < 1 byte > localSupportedSignAlgs entries
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   268
     *   < 2 bytes per entries > localSupportedSignAlgs
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   269
     * < 1 bytes > peerSupportedSignAlgs entries
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   270
     *   < 2 bytes per entries > peerSupportedSignAlgs
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   271
     * < 2 bytes > preSharedKey length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   272
     * < length in bytes > preSharedKey
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   273
     * < 1 byte > pskIdentity length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   274
     * < length in bytes > pskIdentity
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   275
     * < 1 byte > masterSecret length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   276
     *   < 1 byte > masterSecret algorithm length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   277
     *   < length in bytes > masterSecret algorithm
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   278
     *   < 2 bytes > masterSecretKey length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   279
     *   < length in bytes> masterSecretKey
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   280
     * < 1 byte > useExtendedMasterSecret
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   281
     * < 1 byte > identificationProtocol length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   282
     * < length in bytes > identificationProtocol
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   283
     * < 1 byte > serverNameIndication length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   284
     * < length in bytes > serverNameIndication
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   285
     * < 1 byte > Number of requestedServerNames entries
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   286
     *   < 1 byte > ServerName length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   287
     *   < length in bytes > ServerName
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   288
     * < 4 bytes > creationTime
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   289
     * < 2 byte > status response length
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   290
     *   < 2 byte > status response entry length
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   291
     *   < length in byte > status response entry
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   292
     * < 1 byte > Length of peer host
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   293
     *   < length in bytes > peer host
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   294
     * < 2 bytes> peer port
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   295
     * < 1 byte > Number of peerCerts entries
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   296
     *   < 4 byte > peerCert length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   297
     *   < length in bytes > peerCert
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   298
     * < 1 byte > localCerts type (Cert, PSK, Anonymous)
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   299
     *   Certificate
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   300
     *     < 1 byte > Number of Certificate entries
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   301
     *       < 4 byte> Certificate length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   302
     *       < length in bytes> Certificate
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   303
     *   PSK
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   304
     *     < 1 byte > Number of PSK entries
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   305
     *       < 1 bytes > PSK algorithm length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   306
     *       < length in bytes > PSK algorithm string
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   307
     *       < 4 bytes > PSK key length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   308
     *       < length in bytes> PSK key
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   309
     *       < 4 bytes > PSK identity length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   310
     *       < length in bytes> PSK identity
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   311
     *   Anonymous
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   312
     *     < 1 byte >
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   313
     * < 4 bytes > maximumPacketSize
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   314
     * < 4 bytes > negotiatedMaxFragSize
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   315
    */
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   316
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   317
    SSLSessionImpl(HandshakeContext hc, ByteBuffer buf) throws IOException {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   318
        int i = 0;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   319
        byte[] b;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   320
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   321
        boundValues = new ConcurrentHashMap<>();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   322
        this.protocolVersion =
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   323
                ProtocolVersion.valueOf(Short.toUnsignedInt(buf.getShort()));
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   324
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   325
        if (protocolVersion.useTLS13PlusSpec()) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   326
            this.sessionId = new SessionId(false, null);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   327
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   328
            // The CH session id may reset this if it's provided
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   329
            this.sessionId = new SessionId(true,
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   330
                    hc.sslContext.getSecureRandom());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   331
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   332
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   333
        this.cipherSuite =
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   334
                CipherSuite.valueOf(Short.toUnsignedInt(buf.getShort()));
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   335
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   336
        // Local Supported signature algorithms
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   337
        ArrayList<SignatureScheme> list = new ArrayList<>();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   338
        i = Byte.toUnsignedInt(buf.get());
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   339
        while (i-- > 0) {
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   340
            list.add(SignatureScheme.valueOf(
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   341
                    Short.toUnsignedInt(buf.getShort())));
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   342
        }
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   343
        this.localSupportedSignAlgs = Collections.unmodifiableCollection(list);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   344
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   345
        // Peer Supported signature algorithms
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   346
        i = Byte.toUnsignedInt(buf.get());
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   347
        list.clear();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   348
        while (i-- > 0) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   349
            list.add(SignatureScheme.valueOf(
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   350
                    Short.toUnsignedInt(buf.getShort())));
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   351
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   352
        this.peerSupportedSignAlgs = Collections.unmodifiableCollection(list);
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   353
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   354
        // PSK
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   355
        i = Short.toUnsignedInt(buf.getShort());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   356
        if (i > 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   357
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   358
            // Get algorithm string
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   359
            buf.get(b, 0, i);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   360
            // Encoded length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   361
            i = Short.toUnsignedInt(buf.getShort());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   362
            // Encoded SecretKey
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   363
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   364
            buf.get(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   365
            this.preSharedKey = new SecretKeySpec(b, "TlsMasterSecret");
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   366
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   367
            this.preSharedKey = null;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   368
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   369
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   370
        // PSK identity
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   371
        i = buf.get();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   372
        if (i > 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   373
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   374
            buf.get(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   375
            this.pskIdentity = b;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   376
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   377
            this.pskIdentity = null;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   378
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   379
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   380
        // Master secret length of secret key algorithm  (one byte)
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   381
        i = buf.get();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   382
        if (i > 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   383
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   384
            // Get algorithm string
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   385
            buf.get(b, 0, i);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   386
            // Encoded length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   387
            i = Short.toUnsignedInt(buf.getShort());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   388
            // Encoded SecretKey
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   389
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   390
            buf.get(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   391
            this.masterSecret = new SecretKeySpec(b, "TlsMasterSecret");
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   392
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   393
            this.masterSecret = null;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   394
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   395
        // Use extended master secret
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   396
        this.useExtendedMasterSecret = (buf.get() != 0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   397
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   398
        // Identification Protocol
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   399
        i = buf.get();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   400
        if (i == 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   401
            identificationProtocol = null;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   402
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   403
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   404
            identificationProtocol =
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   405
                    buf.get(b, 0, i).asCharBuffer().toString();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   406
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   407
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   408
        // SNI
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   409
        i = buf.get();  // length
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   410
        if (i == 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   411
            serverNameIndication = null;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   412
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   413
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   414
            buf.get(b, 0, b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   415
            serverNameIndication = new SNIHostName(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   416
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   417
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   418
        // List of SNIServerName
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   419
        int len = Short.toUnsignedInt(buf.getShort());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   420
        if (len == 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   421
            this.requestedServerNames = Collections.<SNIServerName>emptyList();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   422
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   423
            requestedServerNames = new ArrayList<>();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   424
            while (len > 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   425
                int l = buf.get();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   426
                b = new byte[l];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   427
                buf.get(b, 0, l);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   428
                requestedServerNames.add(new SNIHostName(new String(b)));
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   429
                len--;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   430
            }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   431
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   432
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   433
        maximumPacketSize = buf.getInt();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   434
        negotiatedMaxFragLen = buf.getInt();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   435
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   436
        // Get creation time
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   437
        this.creationTime = buf.getLong();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   438
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   439
        // Get Buffer sizes
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   440
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   441
        // Status Response
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   442
        len = Short.toUnsignedInt(buf.getShort());
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   443
        if (len == 0) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   444
            statusResponses = Collections.emptyList();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   445
        } else {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   446
            statusResponses = new ArrayList<>();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   447
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   448
        while (len-- > 0) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   449
            b = new byte[Short.toUnsignedInt(buf.getShort())];
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   450
            buf.get(b);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   451
            statusResponses.add(b);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   452
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   453
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   454
        // Get Peer host & port
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   455
        i = Byte.toUnsignedInt(buf.get());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   456
        if (i == 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   457
            this.host = new String();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   458
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   459
            b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   460
            this.host = buf.get(b).toString();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   461
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   462
        this.port = Short.toUnsignedInt(buf.getShort());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   463
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   464
        // Peer certs
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   465
        i = buf.get();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   466
        if (i == 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   467
            this.peerCerts = null;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   468
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   469
            this.peerCerts = new X509Certificate[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   470
            int j = 0;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   471
            while (i > j) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   472
                b = new byte[buf.getInt()];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   473
                buf.get(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   474
                try {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   475
                    this.peerCerts[j] = new X509CertImpl(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   476
                } catch (Exception e) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   477
                    throw new IOException(e);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   478
                }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   479
                j++;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   480
            }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   481
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   482
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   483
        // Get local certs of PSK
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   484
        switch (buf.get()) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   485
            case 0:
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   486
                break;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   487
            case 1:
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   488
                // number of certs
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   489
                len = buf.get();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   490
                this.localCerts = new X509Certificate[len];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   491
                i = 0;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   492
                while (len > i) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   493
                    b = new byte[buf.getInt()];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   494
                    buf.get(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   495
                    try {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   496
                        this.localCerts[i] = new X509CertImpl(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   497
                    } catch (Exception e) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   498
                        throw new IOException(e);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   499
                    }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   500
                    i++;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   501
                }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   502
                break;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   503
            case 2:
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   504
                // pre-shared key
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   505
                // Length of pre-shared key algorithm  (one byte)
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   506
                i = buf.get();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   507
                b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   508
                String alg = buf.get(b, 0, i).asCharBuffer().toString();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   509
                // Get length of encoding
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   510
                i = Short.toUnsignedInt(buf.getShort());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   511
                // Get encoding
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   512
                b = new byte[i];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   513
                buf.get(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   514
                this.preSharedKey = new SecretKeySpec(b, alg);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   515
                // Get identity len
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   516
                this.pskIdentity = new byte[buf.get()];
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   517
                buf.get(pskIdentity);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   518
                break;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   519
            default:
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   520
                throw new SSLException("Failed local certs of session.");
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   521
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   522
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   523
        context = (SSLSessionContextImpl)
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   524
                hc.sslContext.engineGetServerSessionContext();
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   525
        this.lastUsedTime = System.currentTimeMillis();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   526
    }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   527
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   528
    // Some situations we cannot provide a stateless ticket, but after it
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   529
    // has been negotiated
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   530
    boolean isStatelessable(HandshakeContext hc) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   531
        if (!hc.statelessResumption) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   532
            return false;
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   533
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   534
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   535
        // If there is no getMasterSecret with TLS1.2 or under, do not resume.
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   536
        if (!protocolVersion.useTLS13PlusSpec() &&
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   537
                getMasterSecret().getEncoded() == null) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   538
            if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   539
                SSLLogger.finest("No MasterSecret, cannot make stateless" +
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   540
                        " ticket");
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   541
            }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   542
            return false;
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   543
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   544
        if (boundValues != null && boundValues.size() > 0) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   545
            if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   546
                SSLLogger.finest("There are boundValues, cannot make" +
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   547
                        " stateless ticket");
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   548
            }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   549
            return false;
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   550
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   551
        return true;
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   552
    }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   553
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   554
    /**
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   555
     * Write out a SSLSessionImpl in a byte array for a stateless session ticket
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   556
     */
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   557
    byte[] write() throws Exception {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   558
        byte[] b;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   559
        HandshakeOutStream hos = new HandshakeOutStream(null);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   560
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   561
        hos.putInt16(protocolVersion.id);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   562
        hos.putInt16(cipherSuite.id);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   563
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   564
        // Local Supported signature algorithms
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   565
        hos.putInt8(localSupportedSignAlgs.size());
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   566
        for (SignatureScheme s : localSupportedSignAlgs) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   567
            hos.putInt16(s.id);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   568
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   569
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   570
        // Peer Supported signature algorithms
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   571
        hos.putInt8(peerSupportedSignAlgs.size());
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   572
        for (SignatureScheme s : peerSupportedSignAlgs) {
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   573
            hos.putInt16(s.id);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   574
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   575
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   576
        // PSK
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   577
        if (preSharedKey == null ||
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   578
                preSharedKey.getAlgorithm() == null) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   579
            hos.putInt16(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   580
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   581
            hos.putInt16(preSharedKey.getAlgorithm().length());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   582
            if (preSharedKey.getAlgorithm().length() != 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   583
                hos.write(preSharedKey.getAlgorithm().getBytes());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   584
            }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   585
            b = preSharedKey.getEncoded();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   586
            hos.putInt16(b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   587
            hos.write(b, 0, b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   588
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   589
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   590
        // PSK Identity
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   591
        if (pskIdentity == null) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   592
            hos.putInt8(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   593
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   594
            hos.putInt8(pskIdentity.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   595
            hos.write(pskIdentity, 0, pskIdentity.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   596
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   597
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   598
        // Master Secret
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   599
        if (getMasterSecret() == null ||
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   600
                getMasterSecret().getAlgorithm() == null) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   601
            hos.putInt8(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   602
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   603
            hos.putInt8(getMasterSecret().getAlgorithm().length());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   604
            if (getMasterSecret().getAlgorithm().length() != 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   605
                hos.write(getMasterSecret().getAlgorithm().getBytes());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   606
            }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   607
            b = getMasterSecret().getEncoded();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   608
            hos.putInt16(b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   609
            hos.write(b, 0, b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   610
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   611
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   612
        hos.putInt8(useExtendedMasterSecret ? 1 : 0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   613
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   614
        // Identification Protocol
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   615
        if (identificationProtocol == null) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   616
            hos.putInt8(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   617
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   618
            hos.putInt8(identificationProtocol.length());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   619
            hos.write(identificationProtocol.getBytes(), 0,
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   620
                    identificationProtocol.length());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   621
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   622
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   623
        // SNI
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   624
        if (serverNameIndication == null) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   625
            hos.putInt8(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   626
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   627
            b = serverNameIndication.getEncoded();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   628
            hos.putInt8(b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   629
            hos.write(b, 0, b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   630
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   631
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   632
        // List of SNIServerName
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   633
        hos.putInt16(requestedServerNames.size());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   634
        if (requestedServerNames.size() > 0) {
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   635
            for (SNIServerName host : requestedServerNames) {
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   636
                b = host.getEncoded();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   637
                hos.putInt8(b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   638
                hos.write(b, 0, b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   639
            }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   640
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   641
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   642
        // Buffer sizes
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   643
        hos.putInt32(maximumPacketSize);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   644
        hos.putInt32(negotiatedMaxFragLen);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   645
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   646
        // creation time
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   647
        ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   648
        hos.writeBytes(buffer.putLong(creationTime).array());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   649
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   650
        // Status Responses
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   651
        List<byte[]> list = getStatusResponses();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   652
        int l = list.size();
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   653
        hos.putInt16(l);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   654
        for (byte[] e : list) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   655
            hos.putInt16(e.length);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   656
            hos.write(e);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   657
        }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   658
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   659
        // peer Host & Port
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   660
        if (host == null || host.length() == 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   661
            hos.putInt8(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   662
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   663
            hos.putInt8(host.length());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   664
            hos.writeBytes(host.getBytes());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   665
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   666
        hos.putInt16(port);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   667
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   668
        // Peer cert
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   669
        if (peerCerts == null || peerCerts.length == 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   670
            hos.putInt8(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   671
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   672
            hos.putInt8(peerCerts.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   673
            for (X509Certificate c : peerCerts) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   674
                b = c.getEncoded();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   675
                hos.putInt32(b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   676
                hos.writeBytes(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   677
            }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   678
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   679
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   680
        // Client identity
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   681
        if (localCerts != null && localCerts.length > 0) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   682
            // certificate based
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   683
            hos.putInt8(1);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   684
            hos.putInt8(localCerts.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   685
            for (X509Certificate c : localCerts) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   686
                b = c.getEncoded();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   687
                hos.putInt32(b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   688
                hos.writeBytes(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   689
            }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   690
        } else if (preSharedKey != null) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   691
            // pre-shared key
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   692
            hos.putInt8(2);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   693
            hos.putInt8(preSharedKey.getAlgorithm().length());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   694
            hos.write(preSharedKey.getAlgorithm().getBytes());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   695
            b = preSharedKey.getEncoded();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   696
            hos.putInt32(b.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   697
            hos.writeBytes(b);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   698
            hos.putInt32(pskIdentity.length);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   699
            hos.writeBytes(pskIdentity);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   700
        } else {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   701
            // anonymous
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   702
            hos.putInt8(0);
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   703
        }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   704
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   705
        return hos.toByteArray();
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   706
    }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   707
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    void setMasterSecret(SecretKey secret) {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   709
        masterSecret = secret;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   710
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   711
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   712
    void setResumptionMasterSecret(SecretKey secret) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   713
        resumptionMasterSecret = secret;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   714
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   715
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   716
    void setPreSharedKey(SecretKey key) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   717
        preSharedKey = key;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   718
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   719
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   720
    void addChild(SSLSessionImpl session) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   721
        childSessions.add(session);
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   722
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   723
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   724
    void setTicketAgeAdd(int ticketAgeAdd) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   725
        this.ticketAgeAdd = ticketAgeAdd;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   726
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   727
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   728
    void setPskIdentity(byte[] pskIdentity) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   729
        this.pskIdentity = pskIdentity;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   730
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   731
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   732
    BigInteger incrTicketNonceCounter() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   733
        BigInteger result = ticketNonceCounter;
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   734
        ticketNonceCounter = ticketNonceCounter.add(BigInteger.ONE);
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   735
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   738
    boolean isPSKable() {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   739
        return (ticketNonceCounter.compareTo(BigInteger.ZERO) > 0);
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   740
    }
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   741
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * Returns the master secret ... treat with extreme caution!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    SecretKey getMasterSecret() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        return masterSecret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   749
    SecretKey getResumptionMasterSecret() {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   750
        return resumptionMasterSecret;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   751
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   752
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   753
    SecretKey getPreSharedKey() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   754
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   755
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   756
            return preSharedKey;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   757
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   758
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   759
        }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   760
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   761
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   762
    SecretKey consumePreSharedKey() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   763
        sessionLock.lock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   764
        try {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   765
            return preSharedKey;
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   766
        } finally {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   767
            preSharedKey = null;
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   768
            sessionLock.unlock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   769
        }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   770
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   771
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   772
    int getTicketAgeAdd() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   773
        return ticketAgeAdd;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   774
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   775
52170
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   776
    String getIdentificationProtocol() {
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   777
        return this.identificationProtocol;
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   778
    }
2990f1e1c325 8208209: Improve TLS connection stability again
apetcher
parents: 51134
diff changeset
   779
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   780
    /* PSK identities created from new_session_ticket messages should only
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   781
     * be used once. This method will return the identity and then clear it
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   782
     * so it cannot be used again.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   783
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   784
    byte[] consumePskIdentity() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   785
        sessionLock.lock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   786
        try {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   787
            return pskIdentity;
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   788
        } finally {
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   789
            pskIdentity = null;
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   790
            sessionLock.unlock();
54253
01d8eae542ff 8218889: Improperly use of the Optional API
xuelei
parents: 54099
diff changeset
   791
        }
48225
718669e6b375 8148421: Transport Layer Security (TLS) Session Hash and Extended Master Secret Extension
xuelei
parents: 47216
diff changeset
   792
    }
718669e6b375 8148421: Transport Layer Security (TLS) Session Hash and Extended Master Secret Extension
xuelei
parents: 47216
diff changeset
   793
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   794
    byte[] getPskIdentity() {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   795
        return pskIdentity;
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   796
    }
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   797
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    void setPeerCertificates(X509Certificate[] peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            peerCerts = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    void setLocalCertificates(X509Certificate[] local) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        localCerts = local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    void setLocalPrivateKey(PrivateKey privateKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        localPrivateKey = privateKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   812
    void setPeerSupportedSignatureAlgorithms(
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   813
            Collection<SignatureScheme> signatureSchemes) {
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   814
        peerSupportedSignAlgs = signatureSchemes;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   815
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   816
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   817
    // TLS 1.2 only
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   818
    //
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   819
    // Per RFC 5246, If the client supports only the default hash
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   820
    // and signature algorithms, it MAY omit the
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   821
    // signature_algorithms extension.  If the client does not
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   822
    // support the default algorithms, or supports other hash
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   823
    // and signature algorithms (and it is willing to use them
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   824
    // for verifying messages sent by the server, i.e., server
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   825
    // certificates and server key exchange), it MUST send the
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   826
    // signature_algorithms extension, listing the algorithms it
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   827
    // is willing to accept.
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   828
    private static final ArrayList<SignatureScheme> defaultPeerSupportedSignAlgs =
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   829
            new ArrayList<>(Arrays.asList(SignatureScheme.RSA_PKCS1_SHA1,
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   830
                    SignatureScheme.DSA_SHA1,
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   831
                    SignatureScheme.ECDSA_SHA1));
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   832
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   833
    void setUseDefaultPeerSignAlgs() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   834
        useDefaultPeerSignAlgs = true;
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   835
        peerSupportedSignAlgs = defaultPeerSupportedSignAlgs;
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   836
    }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   837
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   838
    // Returns the connection session.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   839
    SSLSessionImpl finish() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   840
        if (useDefaultPeerSignAlgs) {
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
   841
            peerSupportedSignAlgs = Collections.emptySet();
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   842
        }
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   843
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   844
        return this;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
   845
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
   846
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    /**
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   848
     * Provide status response data obtained during the SSL handshake.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   849
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   850
     * @param responses a {@link List} of responses in binary form.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   851
     */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   852
    void setStatusResponses(List<byte[]> responses) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   853
        if (responses != null && !responses.isEmpty()) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   854
            statusResponses = responses;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   855
        } else {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   856
            statusResponses = Collections.emptyList();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   857
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   858
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   859
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
   860
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * Returns true iff this session may be resumed ... sessions are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * usually resumable.  Security policies may suggest otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * for example sessions that haven't been used for a while (say,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * a working day) won't be resumable, and sessions might have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * maximum lifetime in any case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    boolean isRejoinable() {
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   868
        // TLS 1.3 can have no session id
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   869
        if (protocolVersion.useTLS13PlusSpec()) {
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   870
            return (!invalidated && isLocalAuthenticationValid());
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   871
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        return sessionId != null && sessionId.length() != 0 &&
55336
c2398053ee90 8211018: Session Resumption without Server-Side State
ascarpino
parents: 54443
diff changeset
   873
                !invalidated && isLocalAuthenticationValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   876
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   877
    public boolean isValid() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   878
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   879
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   880
            return isRejoinable();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   881
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   882
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
   883
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * Check if the authentication used when establishing this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * is still valid. Returns true if no authentication was used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     */
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   890
    private boolean isLocalAuthenticationValid() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        if (localPrivateKey != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                // if the private key is no longer valid, getAlgorithm()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                // should throw an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                // (e.g. Smartcard has been removed from the reader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                localPrivateKey.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   902
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * Returns the ID for this session.  The ID is fixed for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * duration of the session; neither it, nor its value, changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   910
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    public byte[] getId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        return sessionId.getId();
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
     * For server sessions, this returns the set of sessions which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * are currently valid in this process.  For client sessions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * this returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   920
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    public SSLSessionContext getSessionContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
         * An interim security policy until we can do something
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
         * more specific in 1.2. Only allow trusted code (code which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
         * can set system properties) to get an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
         * SSLSessionContext. This is to limit the ability of code to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         * look up specific sessions or enumerate over them. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
         * code can only get session objects from successful SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
         * connections which implies that they must have had permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
         * to make the network connection in the first place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        SecurityManager sm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if ((sm = System.getSecurityManager()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            sm.checkPermission(new SSLPermission("getSSLSessionContext"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        return context;
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
    SessionId getSessionId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        return sessionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * Returns the cipher spec in use on this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    CipherSuite getSuite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        return cipherSuite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    /**
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   954
     * Resets the cipher spec in use on this session
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   955
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   956
    void setSuite(CipherSuite suite) {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   957
       cipherSuite = suite;
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   958
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   959
        if (SSLLogger.isOn && SSLLogger.isOn("session")) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
   960
             SSLLogger.finest("Negotiating session:  " + this);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   961
       }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   962
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   963
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   964
    /**
27068
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   965
     * Return true if the session is currently re-established with a
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   966
     * session-resumption abbreviated initial handshake.
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   967
     */
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   968
    boolean isSessionResumption() {
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   969
        return isSessionResumption;
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   970
    }
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   971
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   972
    /**
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   973
     * Resets whether the session is re-established with a session-resumption
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   974
     * abbreviated initial handshake.
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   975
     */
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   976
    void setAsSessionResumption(boolean flag) {
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   977
        isSessionResumption = flag;
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   978
    }
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   979
5fe2d67f5f68 8037066: Secure transport layer
xuelei
parents: 25859
diff changeset
   980
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * Returns the name of the cipher suite in use on this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   983
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    public String getCipherSuite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        return getSuite().name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    ProtocolVersion getProtocolVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        return protocolVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * Returns the standard name of the protocol in use on this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
   995
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    public String getProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        return getProtocolVersion().name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * Returns the hashcode for this session
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1003
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        return sessionId.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * Returns true if sessions have same ids, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1011
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        if (obj == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        if (obj instanceof SSLSessionImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            SSLSessionImpl sess = (SSLSessionImpl) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            return (sessionId != null) && (sessionId.equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                        sess.getSessionId()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * Return the cert chain presented by the peer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * java.security.cert format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * Note: This method can be used only when using certificate-based
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1032
     * cipher suites; using it with non-certificate-based cipher suites
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1033
     * will throw an SSLPeerUnverifiedException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *  first in the chain, and with the "root" CA last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1038
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    public java.security.cert.Certificate[] getPeerCertificates()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        // clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        // change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        // less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        // Certs are immutable objects, therefore we don't clone them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        // But do need to clone the array, so that nothing is inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        // into peerCerts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        return (java.security.cert.Certificate[])peerCerts.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * Return the cert chain presented to the peer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * java.security.cert format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * Note: This method is useful only when using certificate-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * cipher suites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     *  first in the chain, and with the "root" CA last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1064
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    public java.security.cert.Certificate[] getLocalCertificates() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        // clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        // change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        // less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        return (localCerts == null ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            (java.security.cert.Certificate[])localCerts.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * Return the cert chain presented by the peer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * javax.security.cert format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * Note: This method can be used only when using certificate-based
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1078
     * cipher suites; using it with non-certificate-based cipher suites
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1079
     * will throw an SSLPeerUnverifiedException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *  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
  1083
     *
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 27068
diff changeset
  1084
     * @deprecated This method returns the deprecated
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 27068
diff changeset
  1085
     *  {@code javax.security.cert.X509Certificate} type.
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 27068
diff changeset
  1086
     *  Use {@code getPeerCertificates()} instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1088
    @Override
54099
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 52890
diff changeset
  1089
    @SuppressWarnings("removal")
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 52890
diff changeset
  1090
    @Deprecated(since="9", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    public javax.security.cert.X509Certificate[] getPeerCertificateChain()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        // clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        // change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        // less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        javax.security.cert.X509Certificate[] certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        certs = new javax.security.cert.X509Certificate[peerCerts.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        for (int i = 0; i < peerCerts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            byte[] der = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                der = peerCerts[i].getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                certs[i] = javax.security.cert.X509Certificate.getInstance(der);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            } catch (CertificateEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                throw new SSLPeerUnverifiedException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            } catch (javax.security.cert.CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                throw new SSLPeerUnverifiedException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        return certs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * Return the cert chain presented by the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * Note: This method can be used only when using certificate-based
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1121
     * cipher suites; using it with non-certificate-based cipher suites
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1122
     * will throw an SSLPeerUnverifiedException.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * @return array of peer X.509 certs, with the peer's own cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     *  first in the chain, and with the "root" CA last.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    public X509Certificate[] getCertificateChain()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            throws SSLPeerUnverifiedException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
         * clone to preserve integrity of session ... caller can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
         * change record of peer identity even by accident, much
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
         * less do it intentionally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        if (peerCerts != null) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1135
            return peerCerts.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    /**
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1142
     * Return a List of status responses presented by the peer.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1143
     * Note: This method can be used only when using certificate-based
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1144
     * server authentication; otherwise an empty {@code List} will be returned.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1145
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1146
     * @return an unmodifiable {@code List} of byte arrays, each consisting
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1147
     * of a DER-encoded OCSP response (see RFC 6960).  If no responses have
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1148
     * been presented by the server or non-certificate based server
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1149
     * authentication is used then an empty {@code List} is returned.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1150
     */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1151
    @Override
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1152
    public List<byte[]> getStatusResponses() {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1153
        if (statusResponses == null || statusResponses.isEmpty()) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1154
            return Collections.emptyList();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1155
        } else {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1156
            // Clone both the list and the contents
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1157
            List<byte[]> responses = new ArrayList<>(statusResponses.size());
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1158
            for (byte[] respBytes : statusResponses) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1159
                responses.add(respBytes.clone());
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1160
            }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1161
            return Collections.unmodifiableList(responses);
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1162
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1163
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1164
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30905
diff changeset
  1165
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * Returns the identity of the peer which was established as part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * defining the session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * @return the peer's principal. Returns an X500Principal of the
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1170
     * end-entity certificate for X509-based cipher suites.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @throws SSLPeerUnverifiedException if the peer's identity has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *          been verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1175
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    public Principal getPeerPrincipal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                throws SSLPeerUnverifiedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        if (peerCerts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            throw new SSLPeerUnverifiedException("peer not authenticated");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        }
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
  1182
        return peerCerts[0].getSubjectX500Principal();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * Returns the principal that was sent to the peer during handshaking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * @return the principal sent to the peer. Returns an X500Principal
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1189
     * of the end-entity certificate for X509-based cipher suites.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1190
     * If no principal was sent, then null is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1192
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    public Principal getLocalPrincipal() {
50987
e4a92c455d1c 8206355: SSLSessionImpl.getLocalPrincipal() throws NPE
ssahoo
parents: 50768
diff changeset
  1194
        return ((localCerts == null || localCerts.length == 0) ? null :
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1195
                localCerts[0].getSubjectX500Principal());
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1196
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1198
    /*
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1199
     * Return the time the ticket for this session was created.
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1200
     */
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1201
    public long getTicketCreationTime() {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1202
        return ticketCreationTime;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * Returns the time this session was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1208
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    public long getCreationTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        return creationTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * Returns the last time this session was used to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * a connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1217
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    public long getLastAccessedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        return (lastUsedTime != 0) ? lastUsedTime : creationTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    void setLastAccessedTime(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        lastUsedTime = time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * Returns the network address of the session's peer.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * implementation does not insist that connections between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * different ports on the same host must necessarily belong
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * to different sessions, though that is of course allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    public InetAddress getPeerAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            return InetAddress.getByName(host);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        } catch (java.net.UnknownHostException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1241
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    public String getPeerHost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        return host;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * Need to provide the port info for caching sessions based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * host and port. Accessed by SSLSessionContextImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1250
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    public int getPeerPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        return port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    void setContext(SSLSessionContextImpl ctx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            context = ctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * Invalidate a session.  Active connections may still exist, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * no connections will be able to rejoin this session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1265
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1266
    public void invalidate() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1267
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1268
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1269
            //
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1270
            // Can't invalidate the NULL session -- this would be
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1271
            // attempted when we get a handshaking error on a brand
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1272
            // new connection, with no "real" session yet.
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1273
            //
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1274
            if (this == nullSession) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1275
                return;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1276
            }
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1277
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1278
            if (context != null) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1279
                context.remove(sessionId);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1280
                context = null;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1281
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1282
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1283
            if (invalidated) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1284
                return;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1285
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1286
            invalidated = true;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1287
            if (SSLLogger.isOn && SSLLogger.isOn("session")) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1288
                 SSLLogger.finest("Invalidated session:  " + this);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1289
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1290
            for (SSLSessionImpl child : childSessions) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1291
                child.invalidate();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1292
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1293
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1294
            sessionLock.unlock();
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1295
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * Table of application-specific session data indexed by an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * key and the calling security context. This is important since
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * sessions can be shared across different protection domains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     */
52512
1838347a803b 8212885: TLS 1.3 resumed session does not retain peer certificate chain
jnimeh
parents: 52170
diff changeset
  1303
    private final ConcurrentHashMap<SecureKey, Object> boundValues;
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1304
    boolean updateNST;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * Assigns a session value.  Session change events are given if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * appropriate, to any original value as well as the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1310
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    public void putValue(String key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        if ((key == null) || (value == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            throw new IllegalArgumentException("arguments can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        SecureKey secureKey = new SecureKey(key);
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1317
        Object oldValue = boundValues.put(secureKey, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        if (oldValue instanceof SSLSessionBindingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            SSLSessionBindingEvent e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            e = new SSLSessionBindingEvent(this, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            ((SSLSessionBindingListener)oldValue).valueUnbound(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        if (value instanceof SSLSessionBindingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            SSLSessionBindingEvent e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            e = new SSLSessionBindingEvent(this, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            ((SSLSessionBindingListener)value).valueBound(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        }
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1331
        if (protocolVersion.useTLS13PlusSpec()) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1332
            updateNST = true;
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1333
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * Returns the specified session value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1339
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    public Object getValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            throw new IllegalArgumentException("argument can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        SecureKey secureKey = new SecureKey(key);
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1346
        return boundValues.get(secureKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * Removes the specified session value, delivering a session changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * event as appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1354
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    public void removeValue(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            throw new IllegalArgumentException("argument can not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        SecureKey secureKey = new SecureKey(key);
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1361
        Object value = boundValues.remove(secureKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        if (value instanceof SSLSessionBindingListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            SSLSessionBindingEvent e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            e = new SSLSessionBindingEvent(this, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            ((SSLSessionBindingListener)value).valueUnbound(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        }
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1369
        if (protocolVersion.useTLS13PlusSpec()) {
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1370
            updateNST = true;
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1371
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * Lists the names of the session values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1378
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    public String[] getValueNames() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1380
        ArrayList<Object> v = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        Object securityCtx = SecureKey.getCurrentSecurityContext();
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1382
        for (Enumeration<SecureKey> e = boundValues.keys();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1383
                e.hasMoreElements(); ) {
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1384
            SecureKey key = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            if (securityCtx.equals(key.getSecurityContext())) {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1386
                v.add(key.getAppKey());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1390
        return v.toArray(new String[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * Use large packet sizes now or follow RFC 2246 packet sizes (2^14)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * until changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * In the TLS specification (section 6.2.1, RFC2246), it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * recommended that the plaintext has more than 2^14 bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * However, some TLS implementations violate the specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * This is a workaround for interoperability with these stacks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * Application could accept large fragments up to 2^15 bytes by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * setting the system property jsse.SSLEngine.acceptLargeFragments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * to "true".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    private boolean acceptLargeFragments =
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1407
            Utilities.getBooleanProperty(
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1408
                    "jsse.SSLEngine.acceptLargeFragments", false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * Expand the buffer size of both SSL/TLS network packet and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1414
    protected void expandBufferSizes() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1415
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1416
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1417
            acceptLargeFragments = true;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1418
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1419
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1420
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * Gets the current size of the largest SSL/TLS packet that is expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * when using this session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1427
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1428
    public int getPacketBufferSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1429
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1430
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1431
            // Use the bigger packet size calculated from maximumPacketSize
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1432
            // and negotiatedMaxFragLen.
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1433
            int packetSize = 0;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1434
            if (negotiatedMaxFragLen > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1435
                packetSize = cipherSuite.calculatePacketSize(
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1436
                        negotiatedMaxFragLen, protocolVersion,
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1437
                        protocolVersion.isDTLS);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1438
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1439
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1440
            if (maximumPacketSize > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1441
                return (maximumPacketSize > packetSize) ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1442
                        maximumPacketSize : packetSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1443
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1444
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1445
            if (packetSize != 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1446
               return packetSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1447
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1448
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1449
            if (protocolVersion.isDTLS) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1450
                return DTLSRecord.maxRecordSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1451
            } else {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1452
                return acceptLargeFragments ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1453
                        SSLRecord.maxLargeRecordSize : SSLRecord.maxRecordSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1454
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1455
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1456
            sessionLock.unlock();
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1457
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * Gets the current size of the largest application data that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * expected when using this session.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1464
    @Override
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1465
    public int getApplicationBufferSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1466
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1467
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1468
            // Use the bigger fragment size calculated from maximumPacketSize
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1469
            // and negotiatedMaxFragLen.
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1470
            int fragmentSize = 0;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1471
            if (maximumPacketSize > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1472
                fragmentSize = cipherSuite.calculateFragSize(
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1473
                        maximumPacketSize, protocolVersion,
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1474
                        protocolVersion.isDTLS);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1475
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1476
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1477
            if (negotiatedMaxFragLen > 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1478
                return (negotiatedMaxFragLen > fragmentSize) ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1479
                        negotiatedMaxFragLen : fragmentSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1480
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1481
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1482
            if (fragmentSize != 0) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1483
                return fragmentSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1484
            }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1485
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1486
            if (protocolVersion.isDTLS) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1487
                return Record.maxDataSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1488
            } else {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1489
                int maxPacketSize = acceptLargeFragments ?
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1490
                            SSLRecord.maxLargeRecordSize : SSLRecord.maxRecordSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1491
                return (maxPacketSize - SSLRecord.headerSize);
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1492
            }
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1493
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1494
            sessionLock.unlock();
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1495
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1496
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1497
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1498
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1499
     * Sets the negotiated maximum fragment length, as specified by the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1500
     * max_fragment_length ClientHello extension in RFC 6066.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1501
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1502
     * @param  negotiatedMaxFragLen
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1503
     *         the negotiated maximum fragment length, or {@code -1} if
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1504
     *         no such length has been negotiated.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1505
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1506
    void setNegotiatedMaxFragSize(
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1507
            int negotiatedMaxFragLen) {
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1508
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1509
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1510
            this.negotiatedMaxFragLen = negotiatedMaxFragLen;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1511
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1512
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1513
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1514
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1515
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1516
    /**
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1517
     * Get the negotiated maximum fragment length, as specified by the
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1518
     * max_fragment_length ClientHello extension in RFC 6066.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1519
     *
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1520
     * @return the negotiated maximum fragment length, or {@code -1} if
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1521
     *         no such length has been negotiated.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1522
     */
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1523
    int getNegotiatedMaxFragSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1524
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1525
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1526
            return negotiatedMaxFragLen;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1527
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1528
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1529
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1530
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1531
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1532
    void setMaximumPacketSize(int maximumPacketSize) {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1533
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1534
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1535
            this.maximumPacketSize = maximumPacketSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1536
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1537
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1538
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1539
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 29377
diff changeset
  1540
54443
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1541
    int getMaximumPacketSize() {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1542
        sessionLock.lock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1543
        try {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1544
            return maximumPacketSize;
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1545
        } finally {
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1546
            sessionLock.unlock();
dfba4e321ab3 8221882: Use fiber-friendly java.util.concurrent.locks in JSSE
xuelei
parents: 54253
diff changeset
  1547
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1550
    /**
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1551
     * Gets an array of supported signature algorithm names that the local
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1552
     * side is willing to verify.
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1553
     */
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1554
    @Override
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1555
    public String[] getLocalSupportedSignatureAlgorithms() {
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1556
        return SignatureScheme.getAlgorithmNames(localSupportedSignAlgs);
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1557
    }
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1558
51134
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1559
    /**
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1560
     * Gets an array of supported signature schemes that the local side is
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1561
     * willing to verify.
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1562
     */
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1563
    public Collection<SignatureScheme> getLocalSupportedSignatureSchemes() {
a0de9a3a6766 8206929: Check session context for TLS 1.3 session resumption
apetcher
parents: 50987
diff changeset
  1564
        return localSupportedSignAlgs;
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1565
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1566
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1567
    /**
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1568
     * Gets an array of supported signature algorithms that the peer is
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1569
     * able to verify.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1570
     */
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1571
    @Override
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1572
    public String[] getPeerSupportedSignatureAlgorithms() {
57485
af4b0fc25bc4 8226338: Updates to Stateless Resumption
ascarpino
parents: 55336
diff changeset
  1573
        return SignatureScheme.getAlgorithmNames(peerSupportedSignAlgs);
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1574
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1575
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1576
    /**
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1577
     * 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
  1578
     * 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
  1579
     */
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1580
    @Override
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1581
    public List<SNIServerName> getRequestedServerNames() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1582
        return requestedServerNames;
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1583
    }
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 9035
diff changeset
  1584
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    /** 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
  1586
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    public String toString() {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1588
        return "Session(" + creationTime + "|" + getCipherSuite() + ")";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
 * This "struct" class serves as a Hash Key that combines an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
 * application-specific key and a security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
class SecureKey {
50768
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1597
    private static final Object     nullObject = new Object();
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1598
    private final Object            appKey;
68fa3d4026ea 8196584: TLS 1.3 Implementation
xuelei
parents: 48225
diff changeset
  1599
    private final Object            securityCtx;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    static Object getCurrentSecurityContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
        Object context = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            context = sm.getSecurityContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        if (context == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            context = nullObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    SecureKey(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
        this.appKey = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        this.securityCtx = getCurrentSecurityContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    Object getAppKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        return appKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    Object getSecurityContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        return securityCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1625
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        return appKey.hashCode() ^ securityCtx.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 14194
diff changeset
  1630
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        return o instanceof SecureKey && ((SecureKey)o).appKey.equals(appKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                        && ((SecureKey)o).securityCtx.equals(securityCtx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
}