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