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