author | ascarpino |
Wed, 08 Feb 2017 12:08:28 -0800 | |
changeset 43701 | fe8c324ba97c |
parent 42706 | 796cf076d69b |
child 45064 | b1b45177051b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
2 |
* Copyright (c) 1996, 2016, 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.io.*; |
|
30 |
import java.util.*; |
|
31 |
import java.security.*; |
|
30904 | 32 |
import java.nio.ByteBuffer; |
2 | 33 |
import java.security.NoSuchAlgorithmException; |
34 |
import java.security.AccessController; |
|
7043 | 35 |
import java.security.AlgorithmConstraints; |
2 | 36 |
import java.security.AccessControlContext; |
37 |
import java.security.PrivilegedExceptionAction; |
|
38 |
import java.security.PrivilegedActionException; |
|
42706
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
39 |
import java.util.function.BiFunction; |
2 | 40 |
|
41 |
import javax.crypto.*; |
|
42 |
import javax.crypto.spec.*; |
|
43 |
||
44 |
import javax.net.ssl.*; |
|
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
34380
diff
changeset
|
45 |
import sun.security.util.HexDumpEncoder; |
2 | 46 |
|
47 |
import sun.security.internal.spec.*; |
|
48 |
import sun.security.internal.interfaces.TlsMasterSecret; |
|
49 |
||
50 |
import sun.security.ssl.HandshakeMessage.*; |
|
51 |
import sun.security.ssl.CipherSuite.*; |
|
52 |
||
7043 | 53 |
import static sun.security.ssl.CipherSuite.PRF.*; |
16913 | 54 |
import static sun.security.ssl.CipherSuite.CipherType.*; |
7043 | 55 |
|
2 | 56 |
/** |
57 |
* Handshaker ... processes handshake records from an SSL V3.0 |
|
58 |
* data stream, handling all the details of the handshake protocol. |
|
59 |
* |
|
60 |
* Note that the real protocol work is done in two subclasses, the base |
|
61 |
* class just provides the control flow and key generation framework. |
|
62 |
* |
|
63 |
* @author David Brownell |
|
64 |
*/ |
|
65 |
abstract class Handshaker { |
|
66 |
||
5182 | 67 |
// protocol version being established using this Handshaker |
2 | 68 |
ProtocolVersion protocolVersion; |
69 |
||
5182 | 70 |
// the currently active protocol version during a renegotiation |
71 |
ProtocolVersion activeProtocolVersion; |
|
72 |
||
6856 | 73 |
// security parameters for secure renegotiation. |
74 |
boolean secureRenegotiation; |
|
75 |
byte[] clientVerifyData; |
|
76 |
byte[] serverVerifyData; |
|
77 |
||
7039 | 78 |
// Is it an initial negotiation or a renegotiation? |
6856 | 79 |
boolean isInitialHandshake; |
80 |
||
7039 | 81 |
// List of enabled protocols |
82 |
private ProtocolList enabledProtocols; |
|
83 |
||
84 |
// List of enabled CipherSuites |
|
85 |
private CipherSuiteList enabledCipherSuites; |
|
86 |
||
7043 | 87 |
// The endpoint identification protocol |
30904 | 88 |
String identificationProtocol; |
7043 | 89 |
|
90 |
// The cryptographic algorithm constraints |
|
31712 | 91 |
AlgorithmConstraints algorithmConstraints = null; |
7043 | 92 |
|
93 |
// Local supported signature and algorithms |
|
35298 | 94 |
private Collection<SignatureAndHashAlgorithm> localSupportedSignAlgs; |
7043 | 95 |
|
96 |
// Peer supported signature and algorithms |
|
97 |
Collection<SignatureAndHashAlgorithm> peerSupportedSignAlgs; |
|
98 |
||
99 |
/* |
|
7039 | 100 |
* List of active protocols |
101 |
* |
|
102 |
* Active protocols is a subset of enabled protocols, and will |
|
103 |
* contain only those protocols that have vaild cipher suites |
|
104 |
* enabled. |
|
105 |
*/ |
|
106 |
private ProtocolList activeProtocols; |
|
107 |
||
108 |
/* |
|
109 |
* List of active cipher suites |
|
110 |
* |
|
111 |
* Active cipher suites is a subset of enabled cipher suites, and will |
|
112 |
* contain only those cipher suites available for the active protocols. |
|
113 |
*/ |
|
30904 | 114 |
private CipherSuiteList activeCipherSuites; |
2 | 115 |
|
14194
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
116 |
// The server name indication and matchers |
28543 | 117 |
List<SNIServerName> serverNames = Collections.<SNIServerName>emptyList(); |
118 |
Collection<SNIMatcher> sniMatchers = Collections.<SNIMatcher>emptyList(); |
|
14194
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
119 |
|
34380
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
120 |
// List of local ApplicationProtocols |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
121 |
String[] localApl = null; |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
122 |
|
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
123 |
// Negotiated ALPN value |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
124 |
String applicationProtocol = null; |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
125 |
|
42706
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
126 |
// Application protocol callback function (for SSLEngine) |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
127 |
BiFunction<SSLEngine,List<String>,String> |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
128 |
appProtocolSelectorSSLEngine = null; |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
129 |
|
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
130 |
// Application protocol callback function (for SSLSocket) |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
131 |
BiFunction<SSLSocket,List<String>,String> |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
132 |
appProtocolSelectorSSLSocket = null; |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
133 |
|
30904 | 134 |
// The maximum expected network packet size for SSL/TLS/DTLS records. |
135 |
int maximumPacketSize = 0; |
|
136 |
||
2 | 137 |
private boolean isClient; |
7043 | 138 |
private boolean needCertVerify; |
2 | 139 |
|
140 |
SSLSocketImpl conn = null; |
|
141 |
SSLEngineImpl engine = null; |
|
142 |
||
143 |
HandshakeHash handshakeHash; |
|
144 |
HandshakeInStream input; |
|
145 |
HandshakeOutStream output; |
|
146 |
SSLContextImpl sslContext; |
|
147 |
RandomCookie clnt_random, svr_random; |
|
148 |
SSLSessionImpl session; |
|
149 |
||
30904 | 150 |
HandshakeStateManager handshakeState; |
151 |
boolean clientHelloDelivered; |
|
152 |
boolean serverHelloRequested; |
|
153 |
boolean handshakeActivated; |
|
154 |
boolean handshakeFinished; |
|
155 |
||
2 | 156 |
// current CipherSuite. Never null, initially SSL_NULL_WITH_NULL_NULL |
157 |
CipherSuite cipherSuite; |
|
158 |
||
159 |
// current key exchange. Never null, initially K_NULL |
|
160 |
KeyExchange keyExchange; |
|
161 |
||
28543 | 162 |
// True if this session is being resumed (fast handshake) |
2 | 163 |
boolean resumingSession; |
164 |
||
28543 | 165 |
// True if it's OK to start a new SSL session |
2 | 166 |
boolean enableNewSession; |
167 |
||
19823
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
168 |
// Whether local cipher suites preference should be honored during |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
169 |
// handshaking? |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
170 |
// |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
171 |
// Note that in this provider, this option only applies to server side. |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
172 |
// Local cipher suites preference is always honored in client side in |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
173 |
// this provider. |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
174 |
boolean preferLocalCipherSuites = false; |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
175 |
|
2 | 176 |
// Temporary storage for the individual keys. Set by |
177 |
// calculateConnectionKeys() and cleared once the ciphers are |
|
178 |
// activated. |
|
179 |
private SecretKey clntWriteKey, svrWriteKey; |
|
180 |
private IvParameterSpec clntWriteIV, svrWriteIV; |
|
181 |
private SecretKey clntMacSecret, svrMacSecret; |
|
182 |
||
183 |
/* |
|
184 |
* Delegated task subsystem data structures. |
|
185 |
* |
|
186 |
* If thrown is set, we need to propagate this back immediately |
|
187 |
* on entry into processMessage(). |
|
188 |
* |
|
189 |
* Data is protected by the SSLEngine.this lock. |
|
190 |
*/ |
|
191 |
private volatile boolean taskDelegated = false; |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
192 |
private volatile DelegatedTask<?> delegatedTask = null; |
2 | 193 |
private volatile Exception thrown = null; |
194 |
||
195 |
// Could probably use a java.util.concurrent.atomic.AtomicReference |
|
196 |
// here instead of using this lock. Consider changing. |
|
197 |
private Object thrownLock = new Object(); |
|
198 |
||
199 |
/* Class and subclass dynamic debugging support */ |
|
200 |
static final Debug debug = Debug.getInstance("ssl"); |
|
201 |
||
5182 | 202 |
// By default, disable the unsafe legacy session renegotiation |
6856 | 203 |
static final boolean allowUnsafeRenegotiation = Debug.getBooleanProperty( |
5182 | 204 |
"sun.security.ssl.allowUnsafeRenegotiation", false); |
205 |
||
6856 | 206 |
// For maximum interoperability and backward compatibility, RFC 5746 |
207 |
// allows server (or client) to accept ClientHello (or ServerHello) |
|
208 |
// message without the secure renegotiation_info extension or SCSV. |
|
209 |
// |
|
210 |
// For maximum security, RFC 5746 also allows server (or client) to |
|
211 |
// reject such message with a fatal "handshake_failure" alert. |
|
212 |
// |
|
213 |
// By default, allow such legacy hello messages. |
|
214 |
static final boolean allowLegacyHelloMessages = Debug.getBooleanProperty( |
|
215 |
"sun.security.ssl.allowLegacyHelloMessages", true); |
|
216 |
||
18283
f842a42076b9
7188658: Add possibility to disable client initiated renegotiation
xuelei
parents:
16913
diff
changeset
|
217 |
// To prevent the TLS renegotiation issues, by setting system property |
18554
d2f655022d2d
8017049: rename property jdk.tls.rejectClientInitializedRenego
xuelei
parents:
18283
diff
changeset
|
218 |
// "jdk.tls.rejectClientInitiatedRenegotiation" to true, applications in |
d2f655022d2d
8017049: rename property jdk.tls.rejectClientInitializedRenego
xuelei
parents:
18283
diff
changeset
|
219 |
// server side can disable all client initiated SSL renegotiations |
d2f655022d2d
8017049: rename property jdk.tls.rejectClientInitializedRenego
xuelei
parents:
18283
diff
changeset
|
220 |
// regardless of the support of TLS protocols. |
18283
f842a42076b9
7188658: Add possibility to disable client initiated renegotiation
xuelei
parents:
16913
diff
changeset
|
221 |
// |
f842a42076b9
7188658: Add possibility to disable client initiated renegotiation
xuelei
parents:
16913
diff
changeset
|
222 |
// By default, allow client initiated renegotiations. |
f842a42076b9
7188658: Add possibility to disable client initiated renegotiation
xuelei
parents:
16913
diff
changeset
|
223 |
static final boolean rejectClientInitiatedRenego = |
f842a42076b9
7188658: Add possibility to disable client initiated renegotiation
xuelei
parents:
16913
diff
changeset
|
224 |
Debug.getBooleanProperty( |
18554
d2f655022d2d
8017049: rename property jdk.tls.rejectClientInitializedRenego
xuelei
parents:
18283
diff
changeset
|
225 |
"jdk.tls.rejectClientInitiatedRenegotiation", false); |
18283
f842a42076b9
7188658: Add possibility to disable client initiated renegotiation
xuelei
parents:
16913
diff
changeset
|
226 |
|
5182 | 227 |
// need to dispose the object when it is invalidated |
228 |
boolean invalidated; |
|
229 |
||
30904 | 230 |
/* |
231 |
* Is this an instance for Datagram Transport Layer Security (DTLS)? |
|
232 |
*/ |
|
233 |
final boolean isDTLS; |
|
234 |
||
2 | 235 |
Handshaker(SSLSocketImpl c, SSLContextImpl context, |
236 |
ProtocolList enabledProtocols, boolean needCertVerify, |
|
6856 | 237 |
boolean isClient, ProtocolVersion activeProtocolVersion, |
238 |
boolean isInitialHandshake, boolean secureRenegotiation, |
|
239 |
byte[] clientVerifyData, byte[] serverVerifyData) { |
|
2 | 240 |
this.conn = c; |
30904 | 241 |
this.isDTLS = false; |
6856 | 242 |
init(context, enabledProtocols, needCertVerify, isClient, |
243 |
activeProtocolVersion, isInitialHandshake, secureRenegotiation, |
|
244 |
clientVerifyData, serverVerifyData); |
|
2 | 245 |
} |
246 |
||
247 |
Handshaker(SSLEngineImpl engine, SSLContextImpl context, |
|
248 |
ProtocolList enabledProtocols, boolean needCertVerify, |
|
6856 | 249 |
boolean isClient, ProtocolVersion activeProtocolVersion, |
250 |
boolean isInitialHandshake, boolean secureRenegotiation, |
|
30904 | 251 |
byte[] clientVerifyData, byte[] serverVerifyData, |
252 |
boolean isDTLS) { |
|
2 | 253 |
this.engine = engine; |
30904 | 254 |
this.isDTLS = isDTLS; |
6856 | 255 |
init(context, enabledProtocols, needCertVerify, isClient, |
256 |
activeProtocolVersion, isInitialHandshake, secureRenegotiation, |
|
257 |
clientVerifyData, serverVerifyData); |
|
2 | 258 |
} |
259 |
||
260 |
private void init(SSLContextImpl context, ProtocolList enabledProtocols, |
|
6856 | 261 |
boolean needCertVerify, boolean isClient, |
262 |
ProtocolVersion activeProtocolVersion, |
|
263 |
boolean isInitialHandshake, boolean secureRenegotiation, |
|
264 |
byte[] clientVerifyData, byte[] serverVerifyData) { |
|
265 |
||
266 |
if (debug != null && Debug.isOn("handshake")) { |
|
267 |
System.out.println( |
|
268 |
"Allow unsafe renegotiation: " + allowUnsafeRenegotiation + |
|
269 |
"\nAllow legacy hello messages: " + allowLegacyHelloMessages + |
|
270 |
"\nIs initial handshake: " + isInitialHandshake + |
|
271 |
"\nIs secure renegotiation: " + secureRenegotiation); |
|
272 |
} |
|
2 | 273 |
|
274 |
this.sslContext = context; |
|
275 |
this.isClient = isClient; |
|
7043 | 276 |
this.needCertVerify = needCertVerify; |
6856 | 277 |
this.activeProtocolVersion = activeProtocolVersion; |
278 |
this.isInitialHandshake = isInitialHandshake; |
|
279 |
this.secureRenegotiation = secureRenegotiation; |
|
280 |
this.clientVerifyData = clientVerifyData; |
|
281 |
this.serverVerifyData = serverVerifyData; |
|
30904 | 282 |
this.enableNewSession = true; |
283 |
this.invalidated = false; |
|
284 |
this.handshakeState = new HandshakeStateManager(isDTLS); |
|
285 |
this.clientHelloDelivered = false; |
|
286 |
this.serverHelloRequested = false; |
|
287 |
this.handshakeActivated = false; |
|
288 |
this.handshakeFinished = false; |
|
2 | 289 |
|
290 |
setCipherSuite(CipherSuite.C_NULL); |
|
291 |
setEnabledProtocols(enabledProtocols); |
|
292 |
||
293 |
if (conn != null) { |
|
7043 | 294 |
algorithmConstraints = new SSLAlgorithmConstraints(conn, true); |
2 | 295 |
} else { // engine != null |
7043 | 296 |
algorithmConstraints = new SSLAlgorithmConstraints(engine, true); |
2 | 297 |
} |
298 |
} |
|
299 |
||
300 |
/* |
|
301 |
* Reroutes calls to the SSLSocket or SSLEngine (*SE). |
|
302 |
* |
|
303 |
* We could have also done it by extra classes |
|
304 |
* and letting them override, but this seemed much |
|
305 |
* less involved. |
|
306 |
*/ |
|
307 |
void fatalSE(byte b, String diagnostic) throws IOException { |
|
308 |
fatalSE(b, diagnostic, null); |
|
309 |
} |
|
310 |
||
311 |
void fatalSE(byte b, Throwable cause) throws IOException { |
|
312 |
fatalSE(b, null, cause); |
|
313 |
} |
|
314 |
||
315 |
void fatalSE(byte b, String diagnostic, Throwable cause) |
|
316 |
throws IOException { |
|
317 |
if (conn != null) { |
|
318 |
conn.fatal(b, diagnostic, cause); |
|
319 |
} else { |
|
320 |
engine.fatal(b, diagnostic, cause); |
|
321 |
} |
|
322 |
} |
|
323 |
||
324 |
void warningSE(byte b) { |
|
325 |
if (conn != null) { |
|
326 |
conn.warning(b); |
|
327 |
} else { |
|
328 |
engine.warning(b); |
|
329 |
} |
|
330 |
} |
|
331 |
||
14194
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
332 |
// ONLY used by ClientHandshaker to setup the peer host in SSLSession. |
2 | 333 |
String getHostSE() { |
334 |
if (conn != null) { |
|
335 |
return conn.getHost(); |
|
336 |
} else { |
|
337 |
return engine.getPeerHost(); |
|
338 |
} |
|
339 |
} |
|
340 |
||
14194
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
341 |
// ONLY used by ServerHandshaker to setup the peer host in SSLSession. |
2 | 342 |
String getHostAddressSE() { |
343 |
if (conn != null) { |
|
344 |
return conn.getInetAddress().getHostAddress(); |
|
345 |
} else { |
|
346 |
/* |
|
347 |
* This is for caching only, doesn't matter that's is really |
|
348 |
* a hostname. The main thing is that it doesn't do |
|
349 |
* a reverse DNS lookup, potentially slowing things down. |
|
350 |
*/ |
|
351 |
return engine.getPeerHost(); |
|
352 |
} |
|
353 |
} |
|
354 |
||
355 |
int getPortSE() { |
|
356 |
if (conn != null) { |
|
357 |
return conn.getPort(); |
|
358 |
} else { |
|
359 |
return engine.getPeerPort(); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
int getLocalPortSE() { |
|
364 |
if (conn != null) { |
|
365 |
return conn.getLocalPort(); |
|
366 |
} else { |
|
367 |
return -1; |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
AccessControlContext getAccSE() { |
|
372 |
if (conn != null) { |
|
373 |
return conn.getAcc(); |
|
374 |
} else { |
|
375 |
return engine.getAcc(); |
|
376 |
} |
|
377 |
} |
|
378 |
||
27068 | 379 |
String getEndpointIdentificationAlgorithmSE() { |
380 |
SSLParameters paras; |
|
381 |
if (conn != null) { |
|
382 |
paras = conn.getSSLParameters(); |
|
383 |
} else { |
|
384 |
paras = engine.getSSLParameters(); |
|
385 |
} |
|
386 |
||
387 |
return paras.getEndpointIdentificationAlgorithm(); |
|
388 |
} |
|
389 |
||
2 | 390 |
private void setVersionSE(ProtocolVersion protocolVersion) { |
391 |
if (conn != null) { |
|
392 |
conn.setVersion(protocolVersion); |
|
393 |
} else { |
|
394 |
engine.setVersion(protocolVersion); |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
/** |
|
399 |
* Set the active protocol version and propagate it to the SSLSocket |
|
400 |
* and our handshake streams. Called from ClientHandshaker |
|
401 |
* and ServerHandshaker with the negotiated protocol version. |
|
402 |
*/ |
|
403 |
void setVersion(ProtocolVersion protocolVersion) { |
|
404 |
this.protocolVersion = protocolVersion; |
|
405 |
setVersionSE(protocolVersion); |
|
406 |
} |
|
407 |
||
408 |
/** |
|
409 |
* Set the enabled protocols. Called from the constructor or |
|
7039 | 410 |
* SSLSocketImpl/SSLEngineImpl.setEnabledProtocols() (if the |
411 |
* handshake is not yet in progress). |
|
2 | 412 |
*/ |
413 |
void setEnabledProtocols(ProtocolList enabledProtocols) { |
|
7039 | 414 |
activeCipherSuites = null; |
415 |
activeProtocols = null; |
|
416 |
||
2 | 417 |
this.enabledProtocols = enabledProtocols; |
7039 | 418 |
} |
419 |
||
420 |
/** |
|
421 |
* Set the enabled cipher suites. Called from |
|
422 |
* SSLSocketImpl/SSLEngineImpl.setEnabledCipherSuites() (if the |
|
423 |
* handshake is not yet in progress). |
|
424 |
*/ |
|
425 |
void setEnabledCipherSuites(CipherSuiteList enabledCipherSuites) { |
|
426 |
activeCipherSuites = null; |
|
427 |
activeProtocols = null; |
|
428 |
this.enabledCipherSuites = enabledCipherSuites; |
|
429 |
} |
|
430 |
||
7043 | 431 |
/** |
432 |
* Set the algorithm constraints. Called from the constructor or |
|
433 |
* SSLSocketImpl/SSLEngineImpl.setAlgorithmConstraints() (if the |
|
434 |
* handshake is not yet in progress). |
|
435 |
*/ |
|
436 |
void setAlgorithmConstraints(AlgorithmConstraints algorithmConstraints) { |
|
437 |
activeCipherSuites = null; |
|
438 |
activeProtocols = null; |
|
439 |
||
440 |
this.algorithmConstraints = |
|
441 |
new SSLAlgorithmConstraints(algorithmConstraints); |
|
442 |
this.localSupportedSignAlgs = null; |
|
443 |
} |
|
444 |
||
445 |
Collection<SignatureAndHashAlgorithm> getLocalSupportedSignAlgs() { |
|
446 |
if (localSupportedSignAlgs == null) { |
|
447 |
localSupportedSignAlgs = |
|
448 |
SignatureAndHashAlgorithm.getSupportedAlgorithms( |
|
449 |
algorithmConstraints); |
|
450 |
} |
|
451 |
||
452 |
return localSupportedSignAlgs; |
|
453 |
} |
|
454 |
||
455 |
void setPeerSupportedSignAlgs( |
|
456 |
Collection<SignatureAndHashAlgorithm> algorithms) { |
|
457 |
peerSupportedSignAlgs = |
|
458 |
new ArrayList<SignatureAndHashAlgorithm>(algorithms); |
|
459 |
} |
|
460 |
||
461 |
Collection<SignatureAndHashAlgorithm> getPeerSupportedSignAlgs() { |
|
462 |
return peerSupportedSignAlgs; |
|
463 |
} |
|
464 |
||
465 |
||
466 |
/** |
|
467 |
* Set the identification protocol. Called from the constructor or |
|
468 |
* SSLSocketImpl/SSLEngineImpl.setIdentificationProtocol() (if the |
|
469 |
* handshake is not yet in progress). |
|
470 |
*/ |
|
471 |
void setIdentificationProtocol(String protocol) { |
|
472 |
this.identificationProtocol = protocol; |
|
473 |
} |
|
7039 | 474 |
|
475 |
/** |
|
14194
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
476 |
* Sets the server name indication of the handshake. |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
477 |
*/ |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
478 |
void setSNIServerNames(List<SNIServerName> serverNames) { |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
479 |
// The serverNames parameter is unmodifiable. |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
480 |
this.serverNames = serverNames; |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
481 |
} |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
482 |
|
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
483 |
/** |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
484 |
* Sets the server name matchers of the handshaking. |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
485 |
*/ |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
486 |
void setSNIMatchers(Collection<SNIMatcher> sniMatchers) { |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
487 |
// The sniMatchers parameter is unmodifiable. |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
488 |
this.sniMatchers = sniMatchers; |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
489 |
} |
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
490 |
|
971f46db533d
7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents:
10336
diff
changeset
|
491 |
/** |
30904 | 492 |
* Sets the maximum packet size of the handshaking. |
493 |
*/ |
|
494 |
void setMaximumPacketSize(int maximumPacketSize) { |
|
495 |
this.maximumPacketSize = maximumPacketSize; |
|
496 |
} |
|
497 |
||
498 |
/** |
|
34380
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
499 |
* Sets the Application Protocol list. |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
500 |
*/ |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
501 |
void setApplicationProtocols(String[] apl) { |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
502 |
this.localApl = apl; |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
503 |
} |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
504 |
|
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
505 |
/** |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
506 |
* Gets the "negotiated" ALPN value. |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
507 |
*/ |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
508 |
String getHandshakeApplicationProtocol() { |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
509 |
return applicationProtocol; |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
510 |
} |
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
511 |
|
2b2609379881
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents:
32649
diff
changeset
|
512 |
/** |
42706
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
513 |
* Sets the Application Protocol selector function for SSLEngine. |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
514 |
*/ |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
515 |
void setApplicationProtocolSelectorSSLEngine( |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
516 |
BiFunction<SSLEngine,List<String>,String> selector) { |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
517 |
this.appProtocolSelectorSSLEngine = selector; |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
518 |
} |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
519 |
|
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
520 |
/** |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
521 |
* Sets the Application Protocol selector function for SSLSocket. |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
522 |
*/ |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
523 |
void setApplicationProtocolSelectorSSLSocket( |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
524 |
BiFunction<SSLSocket,List<String>,String> selector) { |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
525 |
this.appProtocolSelectorSSLSocket = selector; |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
526 |
} |
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
527 |
|
796cf076d69b
8170282: Enable ALPN parameters to be supplied during the TLS handshake
vinnie
parents:
39563
diff
changeset
|
528 |
/** |
19823
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
529 |
* Sets the cipher suites preference. |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
530 |
*/ |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
531 |
void setUseCipherSuitesOrder(boolean on) { |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
532 |
this.preferLocalCipherSuites = on; |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
533 |
} |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
534 |
|
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
535 |
/** |
7039 | 536 |
* Prior to handshaking, activate the handshake and initialize the version, |
537 |
* input stream and output stream. |
|
538 |
*/ |
|
539 |
void activate(ProtocolVersion helloVersion) throws IOException { |
|
540 |
if (activeProtocols == null) { |
|
541 |
activeProtocols = getActiveProtocols(); |
|
542 |
} |
|
543 |
||
544 |
if (activeProtocols.collection().isEmpty() || |
|
545 |
activeProtocols.max.v == ProtocolVersion.NONE.v) { |
|
28555 | 546 |
throw new SSLHandshakeException( |
547 |
"No appropriate protocol (protocol is disabled or " + |
|
548 |
"cipher suites are inappropriate)"); |
|
7039 | 549 |
} |
550 |
||
551 |
if (activeCipherSuites == null) { |
|
552 |
activeCipherSuites = getActiveCipherSuites(); |
|
553 |
} |
|
554 |
||
555 |
if (activeCipherSuites.collection().isEmpty()) { |
|
556 |
throw new SSLHandshakeException("No appropriate cipher suite"); |
|
557 |
} |
|
2 | 558 |
|
559 |
// temporary protocol version until the actual protocol version |
|
560 |
// is negotiated in the Hello exchange. This affects the record |
|
7039 | 561 |
// version we sent with the ClientHello. |
562 |
if (!isInitialHandshake) { |
|
563 |
protocolVersion = activeProtocolVersion; |
|
564 |
} else { |
|
565 |
protocolVersion = activeProtocols.max; |
|
566 |
} |
|
2 | 567 |
|
7039 | 568 |
if (helloVersion == null || helloVersion.v == ProtocolVersion.NONE.v) { |
569 |
helloVersion = activeProtocols.helloVersion; |
|
570 |
} |
|
2 | 571 |
|
7043 | 572 |
// We accumulate digests of the handshake messages so that |
573 |
// we can read/write CertificateVerify and Finished messages, |
|
574 |
// getting assurance against some particular active attacks. |
|
14675
17224d0282f1
8004019: Removes unused method HandshakeHash.setCertificateVerifyAlg()
xuelei
parents:
14664
diff
changeset
|
575 |
handshakeHash = new HandshakeHash(needCertVerify); |
7043 | 576 |
|
577 |
// Generate handshake input/output stream. |
|
2 | 578 |
if (conn != null) { |
30904 | 579 |
input = new HandshakeInStream(); |
580 |
output = new HandshakeOutStream(conn.outputRecord); |
|
581 |
||
582 |
conn.inputRecord.setHandshakeHash(handshakeHash); |
|
583 |
conn.inputRecord.setHelloVersion(helloVersion); |
|
584 |
||
585 |
conn.outputRecord.setHandshakeHash(handshakeHash); |
|
586 |
conn.outputRecord.setHelloVersion(helloVersion); |
|
587 |
conn.outputRecord.setVersion(protocolVersion); |
|
588 |
} else if (engine != null) { |
|
589 |
input = new HandshakeInStream(); |
|
590 |
output = new HandshakeOutStream(engine.outputRecord); |
|
591 |
||
7043 | 592 |
engine.inputRecord.setHandshakeHash(handshakeHash); |
7039 | 593 |
engine.inputRecord.setHelloVersion(helloVersion); |
30904 | 594 |
|
595 |
engine.outputRecord.setHandshakeHash(handshakeHash); |
|
2 | 596 |
engine.outputRecord.setHelloVersion(helloVersion); |
30904 | 597 |
engine.outputRecord.setVersion(protocolVersion); |
2 | 598 |
} |
599 |
||
30904 | 600 |
handshakeActivated = true; |
2 | 601 |
} |
602 |
||
603 |
/** |
|
604 |
* Set cipherSuite and keyExchange to the given CipherSuite. |
|
605 |
* Does not perform any verification that this is a valid selection, |
|
606 |
* this must be done before calling this method. |
|
607 |
*/ |
|
608 |
void setCipherSuite(CipherSuite s) { |
|
609 |
this.cipherSuite = s; |
|
610 |
this.keyExchange = s.keyExchange; |
|
611 |
} |
|
612 |
||
613 |
/** |
|
19823
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
614 |
* Check if the given ciphersuite is enabled and available within the |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
615 |
* current active cipher suites. |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
616 |
* |
2 | 617 |
* Does not check if the required server certificates are available. |
618 |
*/ |
|
6856 | 619 |
boolean isNegotiable(CipherSuite s) { |
7039 | 620 |
if (activeCipherSuites == null) { |
621 |
activeCipherSuites = getActiveCipherSuites(); |
|
622 |
} |
|
623 |
||
19823
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
624 |
return isNegotiable(activeCipherSuites, s); |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
625 |
} |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
626 |
|
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
627 |
/** |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
628 |
* Check if the given ciphersuite is enabled and available within the |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
629 |
* proposed cipher suite list. |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
630 |
* |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
631 |
* Does not check if the required server certificates are available. |
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
632 |
*/ |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
31712
diff
changeset
|
633 |
static final boolean isNegotiable(CipherSuiteList proposed, CipherSuite s) { |
19823
f0fd09e20528
7188657: There should be a way to reorder the JSSE ciphers
xuelei
parents:
18554
diff
changeset
|
634 |
return proposed.contains(s) && s.isNegotiable(); |
7039 | 635 |
} |
636 |
||
637 |
/** |
|
638 |
* Check if the given protocol version is enabled and available. |
|
639 |
*/ |
|
640 |
boolean isNegotiable(ProtocolVersion protocolVersion) { |
|
641 |
if (activeProtocols == null) { |
|
642 |
activeProtocols = getActiveProtocols(); |
|
643 |
} |
|
644 |
||
645 |
return activeProtocols.contains(protocolVersion); |
|
646 |
} |
|
647 |
||
648 |
/** |
|
649 |
* Select a protocol version from the list. Called from |
|
650 |
* ServerHandshaker to negotiate protocol version. |
|
651 |
* |
|
652 |
* Return the lower of the protocol version suggested in the |
|
653 |
* clien hello and the highest supported by the server. |
|
654 |
*/ |
|
655 |
ProtocolVersion selectProtocolVersion(ProtocolVersion protocolVersion) { |
|
656 |
if (activeProtocols == null) { |
|
657 |
activeProtocols = getActiveProtocols(); |
|
658 |
} |
|
659 |
||
660 |
return activeProtocols.selectProtocolVersion(protocolVersion); |
|
2 | 661 |
} |
662 |
||
663 |
/** |
|
7039 | 664 |
* Get the active cipher suites. |
665 |
* |
|
666 |
* In TLS 1.1, many weak or vulnerable cipher suites were obsoleted, |
|
667 |
* such as TLS_RSA_EXPORT_WITH_RC4_40_MD5. The implementation MUST NOT |
|
668 |
* negotiate these cipher suites in TLS 1.1 or later mode. |
|
669 |
* |
|
670 |
* Therefore, when the active protocols only include TLS 1.1 or later, |
|
671 |
* the client cannot request to negotiate those obsoleted cipher |
|
7043 | 672 |
* suites. That is, the obsoleted suites should not be included in the |
7039 | 673 |
* client hello. So we need to create a subset of the enabled cipher |
674 |
* suites, the active cipher suites, which does not contain obsoleted |
|
675 |
* cipher suites of the minimum active protocol. |
|
676 |
* |
|
677 |
* Return empty list instead of null if no active cipher suites. |
|
678 |
*/ |
|
679 |
CipherSuiteList getActiveCipherSuites() { |
|
680 |
if (activeCipherSuites == null) { |
|
681 |
if (activeProtocols == null) { |
|
682 |
activeProtocols = getActiveProtocols(); |
|
683 |
} |
|
684 |
||
7990 | 685 |
ArrayList<CipherSuite> suites = new ArrayList<>(); |
7039 | 686 |
if (!(activeProtocols.collection().isEmpty()) && |
687 |
activeProtocols.min.v != ProtocolVersion.NONE.v) { |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
688 |
boolean checkedCurves = false; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
689 |
boolean hasCurves = false; |
7039 | 690 |
for (CipherSuite suite : enabledCipherSuites.collection()) { |
30904 | 691 |
if (!activeProtocols.min.obsoletes(suite) && |
692 |
activeProtocols.max.supports(suite)) { |
|
7043 | 693 |
if (algorithmConstraints.permits( |
694 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
695 |
suite.name, null)) { |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
696 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
697 |
boolean available = true; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
698 |
if (suite.keyExchange.isEC) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
699 |
if (!checkedCurves) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
700 |
hasCurves = EllipticCurvesExtension |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
701 |
.hasActiveCurves(algorithmConstraints); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
702 |
checkedCurves = true; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
703 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
704 |
if (!hasCurves && debug != null && |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
705 |
Debug.isOn("verbose")) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
706 |
System.out.println( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
707 |
"No available elliptic curves"); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
708 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
709 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
710 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
711 |
available = hasCurves; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
712 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
713 |
if (!available && debug != null && |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
714 |
Debug.isOn("verbose")) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
715 |
System.out.println( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
716 |
"No active elliptic curves, ignore " + |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
717 |
suite); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
718 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
719 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
720 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
721 |
if (available) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
722 |
suites.add(suite); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
723 |
} |
7043 | 724 |
} |
725 |
} else if (debug != null && Debug.isOn("verbose")) { |
|
30904 | 726 |
if (activeProtocols.min.obsoletes(suite)) { |
7043 | 727 |
System.out.println( |
728 |
"Ignoring obsoleted cipher suite: " + suite); |
|
729 |
} else { |
|
730 |
System.out.println( |
|
731 |
"Ignoring unsupported cipher suite: " + suite); |
|
732 |
} |
|
7039 | 733 |
} |
734 |
} |
|
735 |
} |
|
736 |
activeCipherSuites = new CipherSuiteList(suites); |
|
737 |
} |
|
738 |
||
739 |
return activeCipherSuites; |
|
740 |
} |
|
741 |
||
742 |
/* |
|
743 |
* Get the active protocol versions. |
|
744 |
* |
|
745 |
* In TLS 1.1, many weak or vulnerable cipher suites were obsoleted, |
|
746 |
* such as TLS_RSA_EXPORT_WITH_RC4_40_MD5. The implementation MUST NOT |
|
747 |
* negotiate these cipher suites in TLS 1.1 or later mode. |
|
748 |
* |
|
749 |
* For example, if "TLS_RSA_EXPORT_WITH_RC4_40_MD5" is the |
|
750 |
* only enabled cipher suite, the client cannot request TLS 1.1 or |
|
751 |
* later, even though TLS 1.1 or later is enabled. We need to create a |
|
752 |
* subset of the enabled protocols, called the active protocols, which |
|
753 |
* contains protocols appropriate to the list of enabled Ciphersuites. |
|
754 |
* |
|
755 |
* Return empty list instead of null if no active protocol versions. |
|
756 |
*/ |
|
757 |
ProtocolList getActiveProtocols() { |
|
758 |
if (activeProtocols == null) { |
|
25801
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
759 |
boolean enabledSSL20Hello = false; |
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
760 |
boolean checkedCurves = false; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
761 |
boolean hasCurves = false; |
7990 | 762 |
ArrayList<ProtocolVersion> protocols = new ArrayList<>(4); |
7039 | 763 |
for (ProtocolVersion protocol : enabledProtocols.collection()) { |
25801
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
764 |
// Need not to check the SSL20Hello protocol. |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
765 |
if (protocol.v == ProtocolVersion.SSL20Hello.v) { |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
766 |
enabledSSL20Hello = true; |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
767 |
continue; |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
768 |
} |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
769 |
|
28555 | 770 |
if (!algorithmConstraints.permits( |
771 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
772 |
protocol.name, null)) { |
|
773 |
if (debug != null && Debug.isOn("verbose")) { |
|
774 |
System.out.println( |
|
775 |
"Ignoring disabled protocol: " + protocol); |
|
776 |
} |
|
777 |
||
778 |
continue; |
|
779 |
} |
|
780 |
||
7039 | 781 |
boolean found = false; |
782 |
for (CipherSuite suite : enabledCipherSuites.collection()) { |
|
30904 | 783 |
if (suite.isAvailable() && (!protocol.obsoletes(suite)) && |
784 |
protocol.supports(suite)) { |
|
7043 | 785 |
if (algorithmConstraints.permits( |
786 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
|
787 |
suite.name, null)) { |
|
39563
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
788 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
789 |
boolean available = true; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
790 |
if (suite.keyExchange.isEC) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
791 |
if (!checkedCurves) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
792 |
hasCurves = EllipticCurvesExtension |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
793 |
.hasActiveCurves(algorithmConstraints); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
794 |
checkedCurves = true; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
795 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
796 |
if (!hasCurves && debug != null && |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
797 |
Debug.isOn("verbose")) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
798 |
System.out.println( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
799 |
"No activated elliptic curves"); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
800 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
801 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
802 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
803 |
available = hasCurves; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
804 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
805 |
if (!available && debug != null && |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
806 |
Debug.isOn("verbose")) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
807 |
System.out.println( |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
808 |
"No active elliptic curves, ignore " + |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
809 |
suite + " for " + protocol); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
810 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
811 |
} |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
812 |
|
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
813 |
if (available) { |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
814 |
protocols.add(protocol); |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
815 |
found = true; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
816 |
break; |
1449ed425710
8148516: Improve the default strength of EC in JDK
xuelei
parents:
35298
diff
changeset
|
817 |
} |
7043 | 818 |
} else if (debug != null && Debug.isOn("verbose")) { |
819 |
System.out.println( |
|
820 |
"Ignoring disabled cipher suite: " + suite + |
|
821 |
" for " + protocol); |
|
822 |
} |
|
823 |
} else if (debug != null && Debug.isOn("verbose")) { |
|
824 |
System.out.println( |
|
825 |
"Ignoring unsupported cipher suite: " + suite + |
|
826 |
" for " + protocol); |
|
7039 | 827 |
} |
828 |
} |
|
829 |
if (!found && (debug != null) && Debug.isOn("handshake")) { |
|
830 |
System.out.println( |
|
831 |
"No available cipher suite for " + protocol); |
|
832 |
} |
|
833 |
} |
|
25801
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
834 |
|
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
835 |
if (!protocols.isEmpty() && enabledSSL20Hello) { |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
836 |
protocols.add(ProtocolVersion.SSL20Hello); |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
837 |
} |
da76619a8c19
8052406: SSLv2Hello protocol may be filter out unexpectedly
xuelei
parents:
22336
diff
changeset
|
838 |
|
7039 | 839 |
activeProtocols = new ProtocolList(protocols); |
840 |
} |
|
841 |
||
842 |
return activeProtocols; |
|
843 |
} |
|
844 |
||
845 |
/** |
|
846 |
* As long as handshaking has not activated, we can |
|
2 | 847 |
* change whether session creations are allowed. |
848 |
* |
|
849 |
* Callers should do their own checking if handshaking |
|
7039 | 850 |
* has activated. |
2 | 851 |
*/ |
852 |
void setEnableSessionCreation(boolean newSessions) { |
|
853 |
enableNewSession = newSessions; |
|
854 |
} |
|
855 |
||
856 |
/** |
|
857 |
* Create a new read cipher and return it to caller. |
|
858 |
*/ |
|
859 |
CipherBox newReadCipher() throws NoSuchAlgorithmException { |
|
860 |
BulkCipher cipher = cipherSuite.cipher; |
|
861 |
CipherBox box; |
|
862 |
if (isClient) { |
|
863 |
box = cipher.newCipher(protocolVersion, svrWriteKey, svrWriteIV, |
|
7039 | 864 |
sslContext.getSecureRandom(), false); |
2 | 865 |
svrWriteKey = null; |
866 |
svrWriteIV = null; |
|
867 |
} else { |
|
868 |
box = cipher.newCipher(protocolVersion, clntWriteKey, clntWriteIV, |
|
7039 | 869 |
sslContext.getSecureRandom(), false); |
2 | 870 |
clntWriteKey = null; |
871 |
clntWriteIV = null; |
|
872 |
} |
|
873 |
return box; |
|
874 |
} |
|
875 |
||
876 |
/** |
|
877 |
* Create a new write cipher and return it to caller. |
|
878 |
*/ |
|
879 |
CipherBox newWriteCipher() throws NoSuchAlgorithmException { |
|
880 |
BulkCipher cipher = cipherSuite.cipher; |
|
881 |
CipherBox box; |
|
882 |
if (isClient) { |
|
883 |
box = cipher.newCipher(protocolVersion, clntWriteKey, clntWriteIV, |
|
7039 | 884 |
sslContext.getSecureRandom(), true); |
2 | 885 |
clntWriteKey = null; |
886 |
clntWriteIV = null; |
|
887 |
} else { |
|
888 |
box = cipher.newCipher(protocolVersion, svrWriteKey, svrWriteIV, |
|
7039 | 889 |
sslContext.getSecureRandom(), true); |
2 | 890 |
svrWriteKey = null; |
891 |
svrWriteIV = null; |
|
892 |
} |
|
893 |
return box; |
|
894 |
} |
|
895 |
||
896 |
/** |
|
897 |
* Create a new read MAC and return it to caller. |
|
898 |
*/ |
|
16913 | 899 |
Authenticator newReadAuthenticator() |
900 |
throws NoSuchAlgorithmException, InvalidKeyException { |
|
901 |
||
902 |
Authenticator authenticator = null; |
|
903 |
if (cipherSuite.cipher.cipherType == AEAD_CIPHER) { |
|
904 |
authenticator = new Authenticator(protocolVersion); |
|
2 | 905 |
} else { |
16913 | 906 |
MacAlg macAlg = cipherSuite.macAlg; |
907 |
if (isClient) { |
|
908 |
authenticator = macAlg.newMac(protocolVersion, svrMacSecret); |
|
909 |
svrMacSecret = null; |
|
910 |
} else { |
|
911 |
authenticator = macAlg.newMac(protocolVersion, clntMacSecret); |
|
912 |
clntMacSecret = null; |
|
913 |
} |
|
2 | 914 |
} |
16913 | 915 |
|
916 |
return authenticator; |
|
2 | 917 |
} |
918 |
||
919 |
/** |
|
920 |
* Create a new write MAC and return it to caller. |
|
921 |
*/ |
|
16913 | 922 |
Authenticator newWriteAuthenticator() |
923 |
throws NoSuchAlgorithmException, InvalidKeyException { |
|
924 |
||
925 |
Authenticator authenticator = null; |
|
926 |
if (cipherSuite.cipher.cipherType == AEAD_CIPHER) { |
|
927 |
authenticator = new Authenticator(protocolVersion); |
|
2 | 928 |
} else { |
16913 | 929 |
MacAlg macAlg = cipherSuite.macAlg; |
930 |
if (isClient) { |
|
931 |
authenticator = macAlg.newMac(protocolVersion, clntMacSecret); |
|
932 |
clntMacSecret = null; |
|
933 |
} else { |
|
934 |
authenticator = macAlg.newMac(protocolVersion, svrMacSecret); |
|
935 |
svrMacSecret = null; |
|
936 |
} |
|
2 | 937 |
} |
16913 | 938 |
|
939 |
return authenticator; |
|
2 | 940 |
} |
941 |
||
942 |
/* |
|
943 |
* Returns true iff the handshake sequence is done, so that |
|
944 |
* this freshly created session can become the current one. |
|
945 |
*/ |
|
946 |
boolean isDone() { |
|
30904 | 947 |
return started() && handshakeState.isEmpty() && handshakeFinished; |
2 | 948 |
} |
949 |
||
950 |
||
951 |
/* |
|
952 |
* Returns the session which was created through this |
|
953 |
* handshake sequence ... should be called after isDone() |
|
954 |
* returns true. |
|
955 |
*/ |
|
956 |
SSLSessionImpl getSession() { |
|
957 |
return session; |
|
958 |
} |
|
959 |
||
960 |
/* |
|
7043 | 961 |
* Set the handshake session |
962 |
*/ |
|
963 |
void setHandshakeSessionSE(SSLSessionImpl handshakeSession) { |
|
964 |
if (conn != null) { |
|
965 |
conn.setHandshakeSession(handshakeSession); |
|
966 |
} else { |
|
967 |
engine.setHandshakeSession(handshakeSession); |
|
968 |
} |
|
969 |
} |
|
970 |
||
30904 | 971 |
void expectingFinishFlightSE() { |
972 |
if (conn != null) { |
|
973 |
conn.expectingFinishFlight(); |
|
974 |
} else { |
|
975 |
engine.expectingFinishFlight(); |
|
976 |
} |
|
977 |
} |
|
978 |
||
7043 | 979 |
/* |
6856 | 980 |
* Returns true if renegotiation is in use for this connection. |
981 |
*/ |
|
982 |
boolean isSecureRenegotiation() { |
|
983 |
return secureRenegotiation; |
|
984 |
} |
|
985 |
||
986 |
/* |
|
987 |
* Returns the verify_data from the Finished message sent by the client. |
|
988 |
*/ |
|
989 |
byte[] getClientVerifyData() { |
|
990 |
return clientVerifyData; |
|
991 |
} |
|
992 |
||
993 |
/* |
|
994 |
* Returns the verify_data from the Finished message sent by the server. |
|
995 |
*/ |
|
996 |
byte[] getServerVerifyData() { |
|
997 |
return serverVerifyData; |
|
998 |
} |
|
999 |
||
1000 |
/* |
|
2 | 1001 |
* This routine is fed SSL handshake records when they become available, |
1002 |
* and processes messages found therein. |
|
1003 |
*/ |
|
30904 | 1004 |
void processRecord(ByteBuffer record, |
1005 |
boolean expectingFinished) throws IOException { |
|
2 | 1006 |
|
1007 |
checkThrown(); |
|
1008 |
||
1009 |
/* |
|
1010 |
* Store the incoming handshake data, then see if we can |
|
1011 |
* now process any completed handshake messages |
|
1012 |
*/ |
|
30904 | 1013 |
input.incomingRecord(record); |
2 | 1014 |
|
1015 |
/* |
|
1016 |
* We don't need to create a separate delegatable task |
|
1017 |
* for finished messages. |
|
1018 |
*/ |
|
1019 |
if ((conn != null) || expectingFinished) { |
|
1020 |
processLoop(); |
|
1021 |
} else { |
|
1022 |
delegateTask(new PrivilegedExceptionAction<Void>() { |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
14229
diff
changeset
|
1023 |
@Override |
2 | 1024 |
public Void run() throws Exception { |
1025 |
processLoop(); |
|
1026 |
return null; |
|
1027 |
} |
|
1028 |
}); |
|
1029 |
} |
|
1030 |
} |
|
1031 |
||
1032 |
/* |
|
1033 |
* On input, we hash messages one at a time since servers may need |
|
1034 |
* to access an intermediate hash to validate a CertificateVerify |
|
1035 |
* message. |
|
1036 |
* |
|
1037 |
* Note that many handshake messages can come in one record (and often |
|
1038 |
* do, to reduce network resource utilization), and one message can also |
|
1039 |
* require multiple records (e.g. very large Certificate messages). |
|
1040 |
*/ |
|
1041 |
void processLoop() throws IOException { |
|
1042 |
||
5182 | 1043 |
// need to read off 4 bytes at least to get the handshake |
1044 |
// message type and length. |
|
1045 |
while (input.available() >= 4) { |
|
2 | 1046 |
byte messageType; |
1047 |
int messageLen; |
|
1048 |
||
1049 |
/* |
|
1050 |
* See if we can read the handshake message header, and |
|
1051 |
* then the entire handshake message. If not, wait till |
|
1052 |
* we can read and process an entire message. |
|
1053 |
*/ |
|
1054 |
input.mark(4); |
|
1055 |
||
1056 |
messageType = (byte)input.getInt8(); |
|
1057 |
messageLen = input.getInt24(); |
|
1058 |
||
1059 |
if (input.available() < messageLen) { |
|
1060 |
input.reset(); |
|
1061 |
return; |
|
1062 |
} |
|
1063 |
||
30904 | 1064 |
// Set the flags in the message receiving side. |
1065 |
if (messageType == HandshakeMessage.ht_client_hello) { |
|
1066 |
clientHelloDelivered = true; |
|
1067 |
} else if (messageType == HandshakeMessage.ht_hello_request) { |
|
1068 |
serverHelloRequested = true; |
|
1069 |
} |
|
1070 |
||
2 | 1071 |
/* |
21278 | 1072 |
* Process the message. We require |
2 | 1073 |
* that processMessage() consumes the entire message. In |
1074 |
* lieu of explicit error checks (how?!) we assume that the |
|
1075 |
* data will look like garbage on encoding/processing errors, |
|
1076 |
* and that other protocol code will detect such errors. |
|
1077 |
* |
|
1078 |
* Note that digesting is normally deferred till after the |
|
1079 |
* message has been processed, though to process at least the |
|
1080 |
* client's Finished message (i.e. send the server's) we need |
|
1081 |
* to acccelerate that digesting. |
|
1082 |
* |
|
1083 |
* Also, note that hello request messages are never hashed; |
|
1084 |
* that includes the hello request header, too. |
|
1085 |
*/ |
|
30904 | 1086 |
processMessage(messageType, messageLen); |
1087 |
||
1088 |
// Reload if this message has been reserved. |
|
1089 |
// |
|
1090 |
// Note: in the implementation, only certificate_verify and |
|
1091 |
// finished messages are reserved. |
|
1092 |
if ((messageType == HandshakeMessage.ht_finished) || |
|
1093 |
(messageType == HandshakeMessage.ht_certificate_verify)) { |
|
1094 |
||
1095 |
handshakeHash.reload(); |
|
2 | 1096 |
} |
1097 |
} |
|
1098 |
} |
|
1099 |
||
1100 |
||
1101 |
/** |
|
7039 | 1102 |
* Returns true iff the handshaker has been activated. |
1103 |
* |
|
1104 |
* In activated state, the handshaker may not send any messages out. |
|
1105 |
*/ |
|
1106 |
boolean activated() { |
|
30904 | 1107 |
return handshakeActivated; |
7039 | 1108 |
} |
1109 |
||
1110 |
/** |
|
2 | 1111 |
* Returns true iff the handshaker has sent any messages. |
1112 |
*/ |
|
1113 |
boolean started() { |
|
30904 | 1114 |
return (serverHelloRequested || clientHelloDelivered); |
2 | 1115 |
} |
1116 |
||
1117 |
/* |
|
1118 |
* Used to kickstart the negotiation ... either writing a |
|
1119 |
* ClientHello or a HelloRequest as appropriate, whichever |
|
1120 |
* the subclass returns. NOP if handshaking's already started. |
|
1121 |
*/ |
|
1122 |
void kickstart() throws IOException { |
|
30904 | 1123 |
if ((isClient && clientHelloDelivered) || |
1124 |
(!isClient && serverHelloRequested)) { |
|
2 | 1125 |
return; |
1126 |
} |
|
7039 | 1127 |
|
2 | 1128 |
HandshakeMessage m = getKickstartMessage(); |
30904 | 1129 |
handshakeState.update(m, resumingSession); |
2 | 1130 |
|
1131 |
if (debug != null && Debug.isOn("handshake")) { |
|
1132 |
m.print(System.out); |
|
1133 |
} |
|
1134 |
m.write(output); |
|
1135 |
output.flush(); |
|
1136 |
||
30904 | 1137 |
// Set the flags in the message delivering side. |
1138 |
int handshakeType = m.messageType(); |
|
1139 |
if (handshakeType == HandshakeMessage.ht_hello_request) { |
|
1140 |
serverHelloRequested = true; |
|
1141 |
} else { // HandshakeMessage.ht_client_hello |
|
1142 |
clientHelloDelivered = true; |
|
1143 |
} |
|
2 | 1144 |
} |
1145 |
||
1146 |
/** |
|
1147 |
* Both client and server modes can start handshaking; but the |
|
1148 |
* message they send to do so is different. |
|
1149 |
*/ |
|
1150 |
abstract HandshakeMessage getKickstartMessage() throws SSLException; |
|
1151 |
||
1152 |
/* |
|
1153 |
* Client and Server side protocols are each driven though this |
|
1154 |
* call, which processes a single message and drives the appropriate |
|
1155 |
* side of the protocol state machine (depending on the subclass). |
|
1156 |
*/ |
|
1157 |
abstract void processMessage(byte messageType, int messageLen) |
|
1158 |
throws IOException; |
|
1159 |
||
1160 |
/* |
|
1161 |
* Most alerts in the protocol relate to handshaking problems. |
|
1162 |
* Alerts are detected as the connection reads data. |
|
1163 |
*/ |
|
1164 |
abstract void handshakeAlert(byte description) throws SSLProtocolException; |
|
1165 |
||
1166 |
/* |
|
1167 |
* Sends a change cipher spec message and updates the write side |
|
1168 |
* cipher state so that future messages use the just-negotiated spec. |
|
1169 |
*/ |
|
1170 |
void sendChangeCipherSpec(Finished mesg, boolean lastMessage) |
|
1171 |
throws IOException { |
|
1172 |
||
1173 |
output.flush(); // i.e. handshake data |
|
1174 |
||
1175 |
/* |
|
1176 |
* The write cipher state is protected by the connection write lock |
|
1177 |
* so we must grab it while making the change. We also |
|
1178 |
* make sure no writes occur between sending the ChangeCipherSpec |
|
1179 |
* message, installing the new cipher state, and sending the |
|
1180 |
* Finished message. |
|
1181 |
* |
|
1182 |
* We already hold SSLEngine/SSLSocket "this" by virtue |
|
1183 |
* of this being called from the readRecord code. |
|
1184 |
*/ |
|
1185 |
if (conn != null) { |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
2
diff
changeset
|
1186 |
conn.writeLock.lock(); |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
2
diff
changeset
|
1187 |
try { |
30904 | 1188 |
handshakeState.changeCipherSpec(false, isClient); |
2 | 1189 |
conn.changeWriteCiphers(); |
1190 |
if (debug != null && Debug.isOn("handshake")) { |
|
1191 |
mesg.print(System.out); |
|
1192 |
} |
|
30904 | 1193 |
|
1194 |
handshakeState.update(mesg, resumingSession); |
|
2 | 1195 |
mesg.write(output); |
1196 |
output.flush(); |
|
100
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
2
diff
changeset
|
1197 |
} finally { |
01ef29ca378f
6447412: Issue with socket.close() for ssl sockets when poweroff on other system
xuelei
parents:
2
diff
changeset
|
1198 |
conn.writeLock.unlock(); |
2 | 1199 |
} |
1200 |
} else { |
|
1201 |
synchronized (engine.writeLock) { |
|
30904 | 1202 |
handshakeState.changeCipherSpec(false, isClient); |
2 | 1203 |
engine.changeWriteCiphers(); |
1204 |
if (debug != null && Debug.isOn("handshake")) { |
|
1205 |
mesg.print(System.out); |
|
1206 |
} |
|
30904 | 1207 |
|
1208 |
handshakeState.update(mesg, resumingSession); |
|
2 | 1209 |
mesg.write(output); |
1210 |
output.flush(); |
|
1211 |
} |
|
1212 |
} |
|
30904 | 1213 |
|
1214 |
if (lastMessage) { |
|
1215 |
handshakeFinished = true; |
|
1216 |
} |
|
1217 |
} |
|
1218 |
||
1219 |
void receiveChangeCipherSpec() throws IOException { |
|
1220 |
handshakeState.changeCipherSpec(true, isClient); |
|
2 | 1221 |
} |
1222 |
||
1223 |
/* |
|
1224 |
* Single access point to key calculation logic. Given the |
|
1225 |
* pre-master secret and the nonces from client and server, |
|
1226 |
* produce all the keying material to be used. |
|
1227 |
*/ |
|
1228 |
void calculateKeys(SecretKey preMasterSecret, ProtocolVersion version) { |
|
1229 |
SecretKey master = calculateMasterSecret(preMasterSecret, version); |
|
1230 |
session.setMasterSecret(master); |
|
1231 |
calculateConnectionKeys(master); |
|
1232 |
} |
|
1233 |
||
1234 |
/* |
|
1235 |
* Calculate the master secret from its various components. This is |
|
1236 |
* used for key exchange by all cipher suites. |
|
1237 |
* |
|
1238 |
* The master secret is the catenation of three MD5 hashes, each |
|
1239 |
* consisting of the pre-master secret and a SHA1 hash. Those three |
|
1240 |
* SHA1 hashes are of (different) constant strings, the pre-master |
|
1241 |
* secret, and the nonces provided by the client and the server. |
|
1242 |
*/ |
|
1243 |
private SecretKey calculateMasterSecret(SecretKey preMasterSecret, |
|
1244 |
ProtocolVersion requestedVersion) { |
|
7039 | 1245 |
|
2 | 1246 |
if (debug != null && Debug.isOn("keygen")) { |
1247 |
HexDumpEncoder dump = new HexDumpEncoder(); |
|
1248 |
||
1249 |
System.out.println("SESSION KEYGEN:"); |
|
1250 |
||
1251 |
System.out.println("PreMaster Secret:"); |
|
1252 |
printHex(dump, preMasterSecret.getEncoded()); |
|
1253 |
||
1254 |
// Nonces are dumped with connection keygen, no |
|
1255 |
// benefit to doing it twice |
|
1256 |
} |
|
1257 |
||
7043 | 1258 |
// What algs/params do we need to use? |
1259 |
String masterAlg; |
|
1260 |
PRF prf; |
|
1261 |
||
30904 | 1262 |
byte majorVersion = protocolVersion.major; |
1263 |
byte minorVersion = protocolVersion.minor; |
|
1264 |
if (protocolVersion.isDTLSProtocol()) { |
|
1265 |
// Use TLS version number for DTLS key calculation |
|
1266 |
if (protocolVersion.v == ProtocolVersion.DTLS10.v) { |
|
1267 |
majorVersion = ProtocolVersion.TLS11.major; |
|
1268 |
minorVersion = ProtocolVersion.TLS11.minor; |
|
1269 |
||
1270 |
masterAlg = "SunTlsMasterSecret"; |
|
1271 |
prf = P_NONE; |
|
1272 |
} else { // DTLS 1.2 |
|
1273 |
majorVersion = ProtocolVersion.TLS12.major; |
|
1274 |
minorVersion = ProtocolVersion.TLS12.minor; |
|
1275 |
||
1276 |
masterAlg = "SunTls12MasterSecret"; |
|
1277 |
prf = cipherSuite.prfAlg; |
|
1278 |
} |
|
7043 | 1279 |
} else { |
30904 | 1280 |
if (protocolVersion.v >= ProtocolVersion.TLS12.v) { |
1281 |
masterAlg = "SunTls12MasterSecret"; |
|
1282 |
prf = cipherSuite.prfAlg; |
|
1283 |
} else { |
|
1284 |
masterAlg = "SunTlsMasterSecret"; |
|
1285 |
prf = P_NONE; |
|
1286 |
} |
|
7043 | 1287 |
} |
1288 |
||
1289 |
String prfHashAlg = prf.getPRFHashAlg(); |
|
1290 |
int prfHashLength = prf.getPRFHashLength(); |
|
1291 |
int prfBlockSize = prf.getPRFBlockSize(); |
|
1292 |
||
27804
4659e70271c4
8066617: Suppress deprecation warnings in java.base module
darcy
parents:
27068
diff
changeset
|
1293 |
@SuppressWarnings("deprecation") |
7043 | 1294 |
TlsMasterSecretParameterSpec spec = new TlsMasterSecretParameterSpec( |
30904 | 1295 |
preMasterSecret, (majorVersion & 0xFF), (minorVersion & 0xFF), |
7043 | 1296 |
clnt_random.random_bytes, svr_random.random_bytes, |
1297 |
prfHashAlg, prfHashLength, prfBlockSize); |
|
1298 |
||
2 | 1299 |
try { |
7043 | 1300 |
KeyGenerator kg = JsseJce.getKeyGenerator(masterAlg); |
2 | 1301 |
kg.init(spec); |
22309 | 1302 |
return kg.generateKey(); |
1303 |
} catch (InvalidAlgorithmParameterException | |
|
1304 |
NoSuchAlgorithmException iae) { |
|
1305 |
// unlikely to happen, otherwise, must be a provider exception |
|
1306 |
// |
|
2 | 1307 |
// For RSA premaster secrets, do not signal a protocol error |
1308 |
// due to the Bleichenbacher attack. See comments further down. |
|
1309 |
if (debug != null && Debug.isOn("handshake")) { |
|
1310 |
System.out.println("RSA master secret generation error:"); |
|
22309 | 1311 |
iae.printStackTrace(System.out); |
7039 | 1312 |
} |
22309 | 1313 |
throw new ProviderException(iae); |
2 | 1314 |
|
7039 | 1315 |
} |
2 | 1316 |
} |
1317 |
||
1318 |
/* |
|
1319 |
* Calculate the keys needed for this connection, once the session's |
|
1320 |
* master secret has been calculated. Uses the master key and nonces; |
|
1321 |
* the amount of keying material generated is a function of the cipher |
|
1322 |
* suite that's been negotiated. |
|
1323 |
* |
|
1324 |
* This gets called both on the "full handshake" (where we exchanged |
|
1325 |
* a premaster secret and started a new session) as well as on the |
|
1326 |
* "fast handshake" (where we just resumed a pre-existing session). |
|
1327 |
*/ |
|
27804
4659e70271c4
8066617: Suppress deprecation warnings in java.base module
darcy
parents:
27068
diff
changeset
|
1328 |
@SuppressWarnings("deprecation") |
2 | 1329 |
void calculateConnectionKeys(SecretKey masterKey) { |
1330 |
/* |
|
1331 |
* For both the read and write sides of the protocol, we use the |
|
1332 |
* master to generate MAC secrets and cipher keying material. Block |
|
1333 |
* ciphers need initialization vectors, which we also generate. |
|
1334 |
* |
|
1335 |
* First we figure out how much keying material is needed. |
|
1336 |
*/ |
|
1337 |
int hashSize = cipherSuite.macAlg.size; |
|
1338 |
boolean is_exportable = cipherSuite.exportable; |
|
1339 |
BulkCipher cipher = cipherSuite.cipher; |
|
1340 |
int expandedKeySize = is_exportable ? cipher.expandedKeySize : 0; |
|
1341 |
||
7043 | 1342 |
// Which algs/params do we need to use? |
1343 |
String keyMaterialAlg; |
|
1344 |
PRF prf; |
|
1345 |
||
30904 | 1346 |
byte majorVersion = protocolVersion.major; |
1347 |
byte minorVersion = protocolVersion.minor; |
|
1348 |
if (protocolVersion.isDTLSProtocol()) { |
|
1349 |
// Use TLS version number for DTLS key calculation |
|
1350 |
if (protocolVersion.v == ProtocolVersion.DTLS10.v) { |
|
1351 |
majorVersion = ProtocolVersion.TLS11.major; |
|
1352 |
minorVersion = ProtocolVersion.TLS11.minor; |
|
1353 |
||
1354 |
keyMaterialAlg = "SunTlsKeyMaterial"; |
|
1355 |
prf = P_NONE; |
|
1356 |
} else { // DTLS 1.2+ |
|
1357 |
majorVersion = ProtocolVersion.TLS12.major; |
|
1358 |
minorVersion = ProtocolVersion.TLS12.minor; |
|
1359 |
||
1360 |
keyMaterialAlg = "SunTls12KeyMaterial"; |
|
1361 |
prf = cipherSuite.prfAlg; |
|
1362 |
} |
|
7043 | 1363 |
} else { |
30904 | 1364 |
if (protocolVersion.v >= ProtocolVersion.TLS12.v) { |
1365 |
keyMaterialAlg = "SunTls12KeyMaterial"; |
|
1366 |
prf = cipherSuite.prfAlg; |
|
1367 |
} else { |
|
1368 |
keyMaterialAlg = "SunTlsKeyMaterial"; |
|
1369 |
prf = P_NONE; |
|
1370 |
} |
|
7043 | 1371 |
} |
1372 |
||
1373 |
String prfHashAlg = prf.getPRFHashAlg(); |
|
1374 |
int prfHashLength = prf.getPRFHashLength(); |
|
1375 |
int prfBlockSize = prf.getPRFBlockSize(); |
|
1376 |
||
30904 | 1377 |
// TLS v1.1+ and DTLS use an explicit IV in CBC cipher suites to |
16913 | 1378 |
// protect against the CBC attacks. AEAD/GCM cipher suites in TLS |
1379 |
// v1.2 or later use a fixed IV as the implicit part of the partially |
|
1380 |
// implicit nonce technique described in RFC 5116. |
|
1381 |
int ivSize = cipher.ivSize; |
|
1382 |
if (cipher.cipherType == AEAD_CIPHER) { |
|
1383 |
ivSize = cipher.fixedIvSize; |
|
30904 | 1384 |
} else if ((cipher.cipherType == BLOCK_CIPHER) && |
1385 |
protocolVersion.useTLS11PlusSpec()) { |
|
16913 | 1386 |
ivSize = 0; |
1387 |
} |
|
1388 |
||
7043 | 1389 |
TlsKeyMaterialParameterSpec spec = new TlsKeyMaterialParameterSpec( |
30904 | 1390 |
masterKey, (majorVersion & 0xFF), (minorVersion & 0xFF), |
1391 |
clnt_random.random_bytes, svr_random.random_bytes, |
|
1392 |
cipher.algorithm, cipher.keySize, expandedKeySize, |
|
1393 |
ivSize, hashSize, |
|
1394 |
prfHashAlg, prfHashLength, prfBlockSize); |
|
2 | 1395 |
|
1396 |
try { |
|
7043 | 1397 |
KeyGenerator kg = JsseJce.getKeyGenerator(keyMaterialAlg); |
2 | 1398 |
kg.init(spec); |
1399 |
TlsKeyMaterialSpec keySpec = (TlsKeyMaterialSpec)kg.generateKey(); |
|
1400 |
||
16913 | 1401 |
// Return null if cipher keys are not supposed to be generated. |
2 | 1402 |
clntWriteKey = keySpec.getClientCipherKey(); |
1403 |
svrWriteKey = keySpec.getServerCipherKey(); |
|
1404 |
||
7039 | 1405 |
// Return null if IVs are not supposed to be generated. |
2 | 1406 |
clntWriteIV = keySpec.getClientIv(); |
1407 |
svrWriteIV = keySpec.getServerIv(); |
|
1408 |
||
16913 | 1409 |
// Return null if MAC keys are not supposed to be generated. |
2 | 1410 |
clntMacSecret = keySpec.getClientMacKey(); |
1411 |
svrMacSecret = keySpec.getServerMacKey(); |
|
1412 |
} catch (GeneralSecurityException e) { |
|
1413 |
throw new ProviderException(e); |
|
1414 |
} |
|
1415 |
||
1416 |
// |
|
1417 |
// Dump the connection keys as they're generated. |
|
1418 |
// |
|
1419 |
if (debug != null && Debug.isOn("keygen")) { |
|
1420 |
synchronized (System.out) { |
|
1421 |
HexDumpEncoder dump = new HexDumpEncoder(); |
|
1422 |
||
1423 |
System.out.println("CONNECTION KEYGEN:"); |
|
1424 |
||
1425 |
// Inputs: |
|
1426 |
System.out.println("Client Nonce:"); |
|
1427 |
printHex(dump, clnt_random.random_bytes); |
|
1428 |
System.out.println("Server Nonce:"); |
|
1429 |
printHex(dump, svr_random.random_bytes); |
|
1430 |
System.out.println("Master Secret:"); |
|
1431 |
printHex(dump, masterKey.getEncoded()); |
|
1432 |
||
1433 |
// Outputs: |
|
16913 | 1434 |
if (clntMacSecret != null) { |
1435 |
System.out.println("Client MAC write Secret:"); |
|
1436 |
printHex(dump, clntMacSecret.getEncoded()); |
|
1437 |
System.out.println("Server MAC write Secret:"); |
|
1438 |
printHex(dump, svrMacSecret.getEncoded()); |
|
1439 |
} else { |
|
1440 |
System.out.println("... no MAC keys used for this cipher"); |
|
1441 |
} |
|
2 | 1442 |
|
1443 |
if (clntWriteKey != null) { |
|
1444 |
System.out.println("Client write key:"); |
|
1445 |
printHex(dump, clntWriteKey.getEncoded()); |
|
1446 |
System.out.println("Server write key:"); |
|
1447 |
printHex(dump, svrWriteKey.getEncoded()); |
|
1448 |
} else { |
|
1449 |
System.out.println("... no encryption keys used"); |
|
1450 |
} |
|
1451 |
||
1452 |
if (clntWriteIV != null) { |
|
1453 |
System.out.println("Client write IV:"); |
|
1454 |
printHex(dump, clntWriteIV.getIV()); |
|
1455 |
System.out.println("Server write IV:"); |
|
1456 |
printHex(dump, svrWriteIV.getIV()); |
|
1457 |
} else { |
|
30904 | 1458 |
if (protocolVersion.useTLS11PlusSpec()) { |
7039 | 1459 |
System.out.println( |
1460 |
"... no IV derived for this protocol"); |
|
1461 |
} else { |
|
1462 |
System.out.println("... no IV used for this cipher"); |
|
1463 |
} |
|
2 | 1464 |
} |
1465 |
System.out.flush(); |
|
1466 |
} |
|
1467 |
} |
|
1468 |
} |
|
1469 |
||
1470 |
private static void printHex(HexDumpEncoder dump, byte[] bytes) { |
|
1471 |
if (bytes == null) { |
|
1472 |
System.out.println("(key bytes not available)"); |
|
1473 |
} else { |
|
1474 |
try { |
|
1475 |
dump.encodeBuffer(bytes, System.out); |
|
1476 |
} catch (IOException e) { |
|
1477 |
// just for debugging, ignore this |
|
1478 |
} |
|
1479 |
} |
|
1480 |
} |
|
1481 |
||
1482 |
/* |
|
1483 |
* Implement a simple task delegator. |
|
1484 |
* |
|
1485 |
* We are currently implementing this as a single delegator, may |
|
1486 |
* try for parallel tasks later. Client Authentication could |
|
1487 |
* benefit from this, where ClientKeyExchange/CertificateVerify |
|
1488 |
* could be carried out in parallel. |
|
1489 |
*/ |
|
1490 |
class DelegatedTask<E> implements Runnable { |
|
1491 |
||
1492 |
private PrivilegedExceptionAction<E> pea; |
|
1493 |
||
1494 |
DelegatedTask(PrivilegedExceptionAction<E> pea) { |
|
1495 |
this.pea = pea; |
|
1496 |
} |
|
1497 |
||
1498 |
public void run() { |
|
1499 |
synchronized (engine) { |
|
1500 |
try { |
|
1501 |
AccessController.doPrivileged(pea, engine.getAcc()); |
|
1502 |
} catch (PrivilegedActionException pae) { |
|
1503 |
thrown = pae.getException(); |
|
1504 |
} catch (RuntimeException rte) { |
|
1505 |
thrown = rte; |
|
1506 |
} |
|
1507 |
delegatedTask = null; |
|
1508 |
taskDelegated = false; |
|
1509 |
} |
|
1510 |
} |
|
1511 |
} |
|
1512 |
||
1513 |
private <T> void delegateTask(PrivilegedExceptionAction<T> pea) { |
|
1514 |
delegatedTask = new DelegatedTask<T>(pea); |
|
1515 |
taskDelegated = false; |
|
1516 |
thrown = null; |
|
1517 |
} |
|
1518 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1519 |
DelegatedTask<?> getTask() { |
2 | 1520 |
if (!taskDelegated) { |
1521 |
taskDelegated = true; |
|
1522 |
return delegatedTask; |
|
1523 |
} else { |
|
1524 |
return null; |
|
1525 |
} |
|
1526 |
} |
|
1527 |
||
1528 |
/* |
|
1529 |
* See if there are any tasks which need to be delegated |
|
1530 |
* |
|
1531 |
* Locked by SSLEngine.this. |
|
1532 |
*/ |
|
1533 |
boolean taskOutstanding() { |
|
1534 |
return (delegatedTask != null); |
|
1535 |
} |
|
1536 |
||
1537 |
/* |
|
1538 |
* The previous caller failed for some reason, report back the |
|
1539 |
* Exception. We won't worry about Error's. |
|
1540 |
* |
|
1541 |
* Locked by SSLEngine.this. |
|
1542 |
*/ |
|
1543 |
void checkThrown() throws SSLException { |
|
1544 |
synchronized (thrownLock) { |
|
1545 |
if (thrown != null) { |
|
1546 |
||
1547 |
String msg = thrown.getMessage(); |
|
1548 |
||
1549 |
if (msg == null) { |
|
1550 |
msg = "Delegated task threw Exception/Error"; |
|
1551 |
} |
|
1552 |
||
1553 |
/* |
|
1554 |
* See what the underlying type of exception is. We should |
|
1555 |
* throw the same thing. Chain thrown to the new exception. |
|
1556 |
*/ |
|
1557 |
Exception e = thrown; |
|
1558 |
thrown = null; |
|
1559 |
||
1560 |
if (e instanceof RuntimeException) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1561 |
throw new RuntimeException(msg, e); |
2 | 1562 |
} else if (e instanceof SSLHandshakeException) { |
1563 |
throw (SSLHandshakeException) |
|
1564 |
new SSLHandshakeException(msg).initCause(e); |
|
1565 |
} else if (e instanceof SSLKeyException) { |
|
1566 |
throw (SSLKeyException) |
|
1567 |
new SSLKeyException(msg).initCause(e); |
|
1568 |
} else if (e instanceof SSLPeerUnverifiedException) { |
|
1569 |
throw (SSLPeerUnverifiedException) |
|
1570 |
new SSLPeerUnverifiedException(msg).initCause(e); |
|
1571 |
} else if (e instanceof SSLProtocolException) { |
|
1572 |
throw (SSLProtocolException) |
|
1573 |
new SSLProtocolException(msg).initCause(e); |
|
1574 |
} else { |
|
1575 |
/* |
|
1576 |
* If it's SSLException or any other Exception, |
|
1577 |
* we'll wrap it in an SSLException. |
|
1578 |
*/ |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1579 |
throw new SSLException(msg, e); |
2 | 1580 |
} |
1581 |
} |
|
1582 |
} |
|
1583 |
} |
|
1584 |
} |