author | prappo |
Wed, 30 Jan 2019 00:24:32 +0000 | |
changeset 53563 | a4b7ea85d668 |
parent 53064 | 103ed9569fc8 |
permissions | -rw-r--r-- |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
1 |
/* |
53563 | 2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
4 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
10 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
15 |
* accompanied this code). |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
16 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
20 |
* |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
23 |
* questions. |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
24 |
*/ |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
25 |
|
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
26 |
package sun.security.ssl; |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
27 |
|
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
28 |
import java.io.IOException; |
50768 | 29 |
import java.nio.ByteBuffer; |
30 |
import java.text.MessageFormat; |
|
31 |
import java.util.Arrays; |
|
32 |
import java.util.Locale; |
|
33 |
import javax.net.ssl.SSLProtocolException; |
|
34 |
import sun.security.ssl.ClientHello.ClientHelloMessage; |
|
35 |
import static sun.security.ssl.SSLExtension.CH_RENEGOTIATION_INFO; |
|
36 |
import sun.security.ssl.SSLExtension.ExtensionConsumer; |
|
37 |
import static sun.security.ssl.SSLExtension.SH_RENEGOTIATION_INFO; |
|
38 |
import sun.security.ssl.SSLExtension.SSLExtensionSpec; |
|
39 |
import sun.security.ssl.SSLHandshake.HandshakeMessage; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
40 |
|
50768 | 41 |
/** |
42 |
* Pack of the "renegotiation_info" extensions [RFC 5746]. |
|
43 |
*/ |
|
44 |
final class RenegoInfoExtension { |
|
45 |
static final HandshakeProducer chNetworkProducer = |
|
46 |
new CHRenegotiationInfoProducer(); |
|
47 |
static final ExtensionConsumer chOnLoadConsumer = |
|
48 |
new CHRenegotiationInfoConsumer(); |
|
49 |
static final HandshakeAbsence chOnLoadAbsence = |
|
50 |
new CHRenegotiationInfoAbsence(); |
|
51 |
||
52 |
static final HandshakeProducer shNetworkProducer = |
|
53 |
new SHRenegotiationInfoProducer(); |
|
54 |
static final ExtensionConsumer shOnLoadConsumer = |
|
55 |
new SHRenegotiationInfoConsumer(); |
|
56 |
static final HandshakeAbsence shOnLoadAbsence = |
|
57 |
new SHRenegotiationInfoAbsence(); |
|
58 |
||
59 |
static final SSLStringizer rniStringizer = |
|
60 |
new RenegotiationInfoStringizer(); |
|
61 |
||
62 |
/** |
|
63 |
* The "renegotiation_info" extension. |
|
64 |
*/ |
|
65 |
static final class RenegotiationInfoSpec implements SSLExtensionSpec { |
|
66 |
// A nominal object that does not holding any real renegotiation info. |
|
67 |
static final RenegotiationInfoSpec NOMINAL = |
|
68 |
new RenegotiationInfoSpec(new byte[0]); |
|
69 |
||
70 |
private final byte[] renegotiatedConnection; |
|
71 |
||
72 |
private RenegotiationInfoSpec(byte[] renegotiatedConnection) { |
|
73 |
this.renegotiatedConnection = Arrays.copyOf( |
|
74 |
renegotiatedConnection, renegotiatedConnection.length); |
|
75 |
} |
|
76 |
||
77 |
private RenegotiationInfoSpec(ByteBuffer m) throws IOException { |
|
78 |
// Parse the extension. |
|
79 |
if (!m.hasRemaining() || m.remaining() < 1) { |
|
80 |
throw new SSLProtocolException( |
|
81 |
"Invalid renegotiation_info extension data: " + |
|
82 |
"insufficient data"); |
|
83 |
} |
|
84 |
this.renegotiatedConnection = Record.getBytes8(m); |
|
85 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
86 |
|
50768 | 87 |
@Override |
88 |
public String toString() { |
|
89 |
MessageFormat messageFormat = new MessageFormat( |
|
90 |
"\"renegotiated connection\": '['{0}']'", Locale.ENGLISH); |
|
91 |
if (renegotiatedConnection.length == 0) { |
|
92 |
Object[] messageFields = { |
|
93 |
"<no renegotiated connection>" |
|
94 |
}; |
|
95 |
return messageFormat.format(messageFields); |
|
96 |
} else { |
|
97 |
Object[] messageFields = { |
|
98 |
Utilities.toHexString(renegotiatedConnection) |
|
99 |
}; |
|
100 |
return messageFormat.format(messageFields); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
private static final |
|
106 |
class RenegotiationInfoStringizer implements SSLStringizer { |
|
107 |
@Override |
|
108 |
public String toString(ByteBuffer buffer) { |
|
109 |
try { |
|
110 |
return (new RenegotiationInfoSpec(buffer)).toString(); |
|
111 |
} catch (IOException ioe) { |
|
112 |
// For debug logging only, so please swallow exceptions. |
|
113 |
return ioe.getMessage(); |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* Network data producer of a "renegotiation_info" extension in |
|
120 |
* the ClientHello handshake message. |
|
121 |
*/ |
|
122 |
private static final |
|
123 |
class CHRenegotiationInfoProducer implements HandshakeProducer { |
|
124 |
// Prevent instantiation of this class. |
|
125 |
private CHRenegotiationInfoProducer() { |
|
126 |
// blank |
|
127 |
} |
|
128 |
||
129 |
@Override |
|
130 |
public byte[] produce(ConnectionContext context, |
|
131 |
HandshakeMessage message) throws IOException { |
|
132 |
// The producing happens in client side only. |
|
133 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
134 |
||
135 |
// Is it a supported and enabled extension? |
|
136 |
if (!chc.sslConfig.isAvailable(CH_RENEGOTIATION_INFO)) { |
|
137 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
138 |
SSLLogger.fine( |
|
139 |
"Ignore unavailable renegotiation_info extension"); |
|
140 |
} |
|
141 |
||
142 |
return null; |
|
143 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
144 |
|
50768 | 145 |
if (!chc.conContext.isNegotiated) { |
146 |
if (chc.activeCipherSuites.contains( |
|
147 |
CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) { |
|
53563 | 148 |
// Using the TLS_EMPTY_RENEGOTIATION_INFO_SCSV instead. |
50768 | 149 |
return null; |
150 |
} |
|
151 |
||
152 |
// initial handshaking. |
|
153 |
// |
|
154 |
// If this is the initial handshake for a connection, then the |
|
155 |
// "renegotiated_connection" field is of zero length in both |
|
156 |
// the ClientHello and the ServerHello. [RFC 5746] |
|
157 |
byte[] extData = new byte[] { 0x00 }; |
|
158 |
chc.handshakeExtensions.put( |
|
159 |
CH_RENEGOTIATION_INFO, RenegotiationInfoSpec.NOMINAL); |
|
160 |
||
161 |
return extData; |
|
162 |
} else if (chc.conContext.secureRenegotiation) { |
|
163 |
// secure renegotiation |
|
164 |
// |
|
165 |
// For ClientHello handshake message in renegotiation, this |
|
166 |
// field contains the "client_verify_data". |
|
167 |
byte[] extData = |
|
168 |
new byte[chc.conContext.clientVerifyData.length + 1]; |
|
169 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
170 |
Record.putBytes8(m, chc.conContext.clientVerifyData); |
|
171 |
||
172 |
// The conContext.clientVerifyData will be used for further |
|
173 |
// processing, so it does not matter to save whatever in the |
|
174 |
// RenegotiationInfoSpec object. |
|
175 |
chc.handshakeExtensions.put( |
|
176 |
CH_RENEGOTIATION_INFO, RenegotiationInfoSpec.NOMINAL); |
|
177 |
||
178 |
return extData; |
|
179 |
} else { // not secure renegotiation |
|
180 |
if (HandshakeContext.allowUnsafeRenegotiation) { |
|
181 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
182 |
SSLLogger.warning("Using insecure renegotiation"); |
|
183 |
} |
|
184 |
||
185 |
return null; |
|
186 |
} else { |
|
187 |
// terminate the session. |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
188 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 189 |
"insecure renegotiation is not allowed"); |
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
194 |
|
50768 | 195 |
/** |
196 |
* Network data producer of a "renegotiation_info" extension in |
|
197 |
* the ServerHello handshake message. |
|
198 |
*/ |
|
199 |
private static final |
|
200 |
class CHRenegotiationInfoConsumer implements ExtensionConsumer { |
|
201 |
// Prevent instantiation of this class. |
|
202 |
private CHRenegotiationInfoConsumer() { |
|
203 |
// blank |
|
204 |
} |
|
205 |
||
206 |
@Override |
|
207 |
public void consume(ConnectionContext context, |
|
208 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
209 |
||
210 |
// The consuming happens in server side only. |
|
211 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
212 |
||
213 |
// Is it a supported and enabled extension? |
|
214 |
if (!shc.sslConfig.isAvailable(CH_RENEGOTIATION_INFO)) { |
|
215 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
216 |
SSLLogger.fine("Ignore unavailable extension: " + |
|
217 |
CH_RENEGOTIATION_INFO.name); |
|
218 |
} |
|
219 |
return; // ignore the extension |
|
220 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
221 |
|
50768 | 222 |
// Parse the extension. |
223 |
RenegotiationInfoSpec spec; |
|
224 |
try { |
|
225 |
spec = new RenegotiationInfoSpec(buffer); |
|
226 |
} catch (IOException ioe) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
227 |
throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
228 |
} |
50768 | 229 |
|
230 |
if (!shc.conContext.isNegotiated) { |
|
231 |
// initial handshaking. |
|
232 |
if (spec.renegotiatedConnection.length != 0) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
233 |
throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, |
50768 | 234 |
"Invalid renegotiation_info extension data: not empty"); |
235 |
} |
|
236 |
shc.conContext.secureRenegotiation = true; |
|
237 |
} else { |
|
238 |
if (!shc.conContext.secureRenegotiation) { |
|
239 |
// Unexpected RI extension for insecure renegotiation, |
|
240 |
// abort the handshake with a fatal handshake_failure alert. |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
241 |
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 242 |
"The renegotiation_info is present in a insecure " + |
243 |
"renegotiation"); |
|
244 |
} else { |
|
245 |
// verify the client_verify_data value |
|
246 |
if (!Arrays.equals(shc.conContext.clientVerifyData, |
|
247 |
spec.renegotiatedConnection)) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
248 |
throw shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, |
50768 | 249 |
"Invalid renegotiation_info extension data: " + |
250 |
"incorrect verify data in ClientHello"); |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
||
255 |
// Update the context. |
|
256 |
// |
|
257 |
// The conContext.clientVerifyData will be used for further |
|
258 |
// processing, so it does not matter to save whatever in the |
|
259 |
// RenegotiationInfoSpec object. |
|
260 |
shc.handshakeExtensions.put( |
|
261 |
CH_RENEGOTIATION_INFO, RenegotiationInfoSpec.NOMINAL); |
|
262 |
||
263 |
// No impact on session resumption. |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
264 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
265 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
266 |
|
50768 | 267 |
/** |
268 |
* The absence processing if a "renegotiation_info" extension is |
|
269 |
* not present in the ClientHello handshake message. |
|
270 |
*/ |
|
271 |
private static final |
|
272 |
class CHRenegotiationInfoAbsence implements HandshakeAbsence { |
|
273 |
@Override |
|
274 |
public void absent(ConnectionContext context, |
|
275 |
HandshakeMessage message) throws IOException { |
|
276 |
// The producing happens in server side only. |
|
277 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
278 |
ClientHelloMessage clientHello = (ClientHelloMessage)message; |
|
279 |
||
280 |
if (!shc.conContext.isNegotiated) { |
|
281 |
// initial handshaking. |
|
282 |
for (int id : clientHello.cipherSuiteIds) { |
|
283 |
if (id == |
|
284 |
CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV.id) { |
|
285 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
286 |
SSLLogger.finest( |
|
287 |
"Safe renegotiation, using the SCSV signgling"); |
|
288 |
} |
|
289 |
shc.conContext.secureRenegotiation = true; |
|
290 |
return; |
|
291 |
} |
|
292 |
} |
|
293 |
||
294 |
if (!HandshakeContext.allowLegacyHelloMessages) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
295 |
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 296 |
"Failed to negotiate the use of secure renegotiation"); |
297 |
} // otherwise, allow legacy hello message |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
298 |
|
50768 | 299 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
300 |
SSLLogger.warning("Warning: No renegotiation " + |
|
301 |
"indication in ClientHello, allow legacy ClientHello"); |
|
302 |
} |
|
303 |
||
304 |
shc.conContext.secureRenegotiation = false; |
|
305 |
} else if (shc.conContext.secureRenegotiation) { |
|
306 |
// Require secure renegotiation, terminate the connection. |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
307 |
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 308 |
"Inconsistent secure renegotiation indication"); |
309 |
} else { // renegotiation, not secure |
|
310 |
if (HandshakeContext.allowUnsafeRenegotiation) { |
|
311 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
312 |
SSLLogger.warning("Using insecure renegotiation"); |
|
313 |
} |
|
314 |
} else { |
|
315 |
// Unsafe renegotiation should have been aborted in |
|
316 |
// ealier processes. |
|
317 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
318 |
SSLLogger.fine("Terminate insecure renegotiation"); |
|
319 |
} |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
320 |
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 321 |
"Unsafe renegotiation is not allowed"); |
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
/** |
|
328 |
* Network data producer of a "renegotiation_info" extension in |
|
329 |
* the ServerHello handshake message. |
|
330 |
*/ |
|
331 |
private static final |
|
332 |
class SHRenegotiationInfoProducer implements HandshakeProducer { |
|
333 |
// Prevent instantiation of this class. |
|
334 |
private SHRenegotiationInfoProducer() { |
|
335 |
// blank |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
336 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
337 |
|
50768 | 338 |
@Override |
339 |
public byte[] produce(ConnectionContext context, |
|
340 |
HandshakeMessage message) throws IOException { |
|
341 |
// The producing happens in server side only. |
|
342 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
343 |
||
344 |
// In response to "renegotiation_info" extension request only. |
|
345 |
RenegotiationInfoSpec requestedSpec = (RenegotiationInfoSpec) |
|
346 |
shc.handshakeExtensions.get(CH_RENEGOTIATION_INFO); |
|
347 |
if (requestedSpec == null && !shc.conContext.secureRenegotiation) { |
|
348 |
// Ignore, no renegotiation_info extension or SCSV signgling |
|
349 |
// requested. |
|
350 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
351 |
SSLLogger.finest( |
|
352 |
"Ignore unavailable renegotiation_info extension"); |
|
353 |
} |
|
354 |
return null; // ignore the extension |
|
355 |
} |
|
356 |
||
357 |
if (!shc.conContext.secureRenegotiation) { |
|
358 |
// Ignore, no secure renegotiation is negotiated. |
|
359 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
360 |
SSLLogger.finest( |
|
361 |
"No secure renegotiation has been negotiated"); |
|
362 |
} |
|
363 |
return null; // ignore the extension |
|
364 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
365 |
|
50768 | 366 |
if (!shc.conContext.isNegotiated) { |
367 |
// initial handshaking. |
|
368 |
// |
|
369 |
// If this is the initial handshake for a connection, then the |
|
370 |
// "renegotiated_connection" field is of zero length in both |
|
371 |
// the ClientHello and the ServerHello. [RFC 5746] |
|
372 |
byte[] extData = new byte[] { 0x00 }; |
|
373 |
||
374 |
// The conContext.client/serverVerifyData will be used for |
|
375 |
// further processing, so it does not matter to save whatever |
|
376 |
// in the RenegotiationInfoSpec object. |
|
377 |
shc.handshakeExtensions.put( |
|
378 |
SH_RENEGOTIATION_INFO, RenegotiationInfoSpec.NOMINAL); |
|
379 |
||
380 |
return extData; |
|
381 |
} else { |
|
382 |
// secure renegotiation |
|
383 |
// |
|
384 |
// For secure renegotiation, the server MUST include a |
|
385 |
// "renegotiation_info" extension containing the saved |
|
386 |
// client_verify_data and server_verify_data in the ServerHello. |
|
387 |
int infoLen = shc.conContext.clientVerifyData.length + |
|
388 |
shc.conContext.serverVerifyData.length; |
|
389 |
byte[] extData = new byte[infoLen + 1]; |
|
390 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
391 |
Record.putInt8(m, infoLen); |
|
392 |
m.put(shc.conContext.clientVerifyData); |
|
393 |
m.put(shc.conContext.serverVerifyData); |
|
394 |
||
395 |
// The conContext.client/serverVerifyData will be used for |
|
396 |
// further processing, so it does not matter to save whatever |
|
397 |
// in the RenegotiationInfoSpec object. |
|
398 |
shc.handshakeExtensions.put( |
|
399 |
SH_RENEGOTIATION_INFO, RenegotiationInfoSpec.NOMINAL); |
|
400 |
||
401 |
return extData; |
|
402 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
403 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
404 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
405 |
|
50768 | 406 |
/** |
407 |
* Network data consumer of a "renegotiation_info" extension in |
|
408 |
* the ServerHello handshake message. |
|
409 |
*/ |
|
410 |
private static final |
|
411 |
class SHRenegotiationInfoConsumer implements ExtensionConsumer { |
|
412 |
// Prevent instantiation of this class. |
|
413 |
private SHRenegotiationInfoConsumer() { |
|
414 |
// blank |
|
415 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
416 |
|
50768 | 417 |
@Override |
418 |
public void consume(ConnectionContext context, |
|
419 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
420 |
// The producing happens in client side only. |
|
421 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
422 |
||
423 |
// In response to the client renegotiation_info extension request |
|
424 |
// or SCSV signling, which is mandatory for ClientHello message. |
|
425 |
RenegotiationInfoSpec requestedSpec = (RenegotiationInfoSpec) |
|
426 |
chc.handshakeExtensions.get(CH_RENEGOTIATION_INFO); |
|
427 |
if (requestedSpec == null && |
|
428 |
!chc.activeCipherSuites.contains( |
|
429 |
CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
430 |
throw chc.conContext.fatal(Alert.INTERNAL_ERROR, |
50768 | 431 |
"Missing renegotiation_info and SCSV detected in " + |
432 |
"ClientHello"); |
|
433 |
} |
|
434 |
||
435 |
// Parse the extension. |
|
436 |
RenegotiationInfoSpec spec; |
|
437 |
try { |
|
438 |
spec = new RenegotiationInfoSpec(buffer); |
|
439 |
} catch (IOException ioe) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
440 |
throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
50768 | 441 |
} |
442 |
||
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
443 |
|
50768 | 444 |
if (!chc.conContext.isNegotiated) { // initial handshake |
445 |
// If the extension is present, set the secure_renegotiation |
|
446 |
// flag to TRUE. The client MUST then verify that the |
|
447 |
// length of the "renegotiated_connection" field is zero, |
|
448 |
// and if it is not, MUST abort the handshake (by sending |
|
449 |
// a fatal handshake_failure alert). [RFC 5746] |
|
450 |
if (spec.renegotiatedConnection.length != 0) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
451 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 452 |
"Invalid renegotiation_info in ServerHello: " + |
453 |
"not empty renegotiated_connection"); |
|
454 |
} |
|
455 |
||
456 |
chc.conContext.secureRenegotiation = true; |
|
457 |
} else { // renegotiation |
|
458 |
// The client MUST then verify that the first half of the |
|
459 |
// "renegotiated_connection" field is equal to the saved |
|
460 |
// client_verify_data value, and the second half is equal to the |
|
461 |
// saved server_verify_data value. If they are not, the client |
|
462 |
// MUST abort the handshake. [RFC 5746] |
|
463 |
int infoLen = chc.conContext.clientVerifyData.length + |
|
464 |
chc.conContext.serverVerifyData.length; |
|
465 |
if (spec.renegotiatedConnection.length != infoLen) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
466 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 467 |
"Invalid renegotiation_info in ServerHello: " + |
468 |
"invalid renegotiated_connection length (" + |
|
469 |
spec.renegotiatedConnection.length + ")"); |
|
470 |
} |
|
471 |
||
472 |
byte[] cvd = chc.conContext.clientVerifyData; |
|
473 |
if (!Arrays.equals(spec.renegotiatedConnection, |
|
474 |
0, cvd.length, cvd, 0, cvd.length)) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
475 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 476 |
"Invalid renegotiation_info in ServerHello: " + |
477 |
"unmatched client_verify_data value"); |
|
478 |
} |
|
479 |
byte[] svd = chc.conContext.serverVerifyData; |
|
480 |
if (!Arrays.equals(spec.renegotiatedConnection, |
|
481 |
cvd.length, infoLen, svd, 0, svd.length)) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
482 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 483 |
"Invalid renegotiation_info in ServerHello: " + |
484 |
"unmatched server_verify_data value"); |
|
485 |
} |
|
486 |
} |
|
487 |
||
488 |
// Update the context. |
|
489 |
chc.handshakeExtensions.put( |
|
490 |
SH_RENEGOTIATION_INFO, RenegotiationInfoSpec.NOMINAL); |
|
491 |
||
492 |
// No impact on session resumption. |
|
493 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
494 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
495 |
|
50768 | 496 |
/** |
497 |
* The absence processing if a "renegotiation_info" extension is |
|
498 |
* not present in the ServerHello handshake message. |
|
499 |
*/ |
|
500 |
private static final |
|
501 |
class SHRenegotiationInfoAbsence implements HandshakeAbsence { |
|
502 |
@Override |
|
503 |
public void absent(ConnectionContext context, |
|
504 |
HandshakeMessage message) throws IOException { |
|
505 |
// The producing happens in client side only. |
|
506 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
507 |
|
50768 | 508 |
// In response to the client renegotiation_info extension request |
509 |
// or SCSV signling, which is mandatory for ClientHello message. |
|
510 |
RenegotiationInfoSpec requestedSpec = (RenegotiationInfoSpec) |
|
511 |
chc.handshakeExtensions.get(CH_RENEGOTIATION_INFO); |
|
512 |
if (requestedSpec == null && |
|
513 |
!chc.activeCipherSuites.contains( |
|
514 |
CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
515 |
throw chc.conContext.fatal(Alert.INTERNAL_ERROR, |
50768 | 516 |
"Missing renegotiation_info and SCSV detected in " + |
517 |
"ClientHello"); |
|
518 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
519 |
|
50768 | 520 |
if (!chc.conContext.isNegotiated) { |
521 |
// initial handshaking. |
|
522 |
if (!HandshakeContext.allowLegacyHelloMessages) { |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
523 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 524 |
"Failed to negotiate the use of secure renegotiation"); |
525 |
} // otherwise, allow legacy hello message |
|
526 |
||
527 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
528 |
SSLLogger.warning("Warning: No renegotiation " + |
|
529 |
"indication in ServerHello, allow legacy ServerHello"); |
|
530 |
} |
|
531 |
||
532 |
chc.conContext.secureRenegotiation = false; |
|
533 |
} else if (chc.conContext.secureRenegotiation) { |
|
534 |
// Require secure renegotiation, terminate the connection. |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
535 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 536 |
"Inconsistent secure renegotiation indication"); |
537 |
} else { // renegotiation, not secure |
|
538 |
if (HandshakeContext.allowUnsafeRenegotiation) { |
|
539 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
540 |
SSLLogger.warning("Using insecure renegotiation"); |
|
541 |
} |
|
542 |
} else { |
|
543 |
// Unsafe renegotiation should have been aborted in |
|
544 |
// ealier processes. |
|
545 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
546 |
SSLLogger.fine("Terminate insecure renegotiation"); |
|
547 |
} |
|
53064
103ed9569fc8
8215443: The use of TransportContext.fatal() leads to bad coding style
xuelei
parents:
50768
diff
changeset
|
548 |
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
50768 | 549 |
"Unsafe renegotiation is not allowed"); |
550 |
} |
|
551 |
} |
|
552 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
553 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
554 |
} |