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