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