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