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