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