author | xuelei |
Wed, 23 May 2018 11:55:41 -0700 | |
branch | JDK-8145252-TLS13-branch |
changeset 56600 | 58ad02eb44c3 |
parent 56584 | a0f3377c58c7 |
child 56704 | c3ee22c3a0f6 |
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 |
/* |
56542 | 2 |
* Copyright (c) 2015, 2018, 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; |
56542 | 29 |
import java.nio.ByteBuffer; |
30 |
import java.text.MessageFormat; |
|
56584 | 31 |
import java.util.Arrays; |
56542 | 32 |
import java.util.LinkedList; |
33 |
import java.util.List; |
|
34 |
import java.util.Locale; |
|
35 |
import javax.net.ssl.SSLProtocolException; |
|
36 |
import sun.security.ssl.SSLExtension.ExtensionConsumer; |
|
37 |
import sun.security.ssl.SSLExtension.SSLExtensionSpec; |
|
38 |
import sun.security.ssl.SSLHandshake.HandshakeMessage; |
|
39 |
||
40 |
/** |
|
41 |
* Pack of the "signature_algorithms" extensions [RFC 5246]. |
|
42 |
*/ |
|
43 |
final class SignatureAlgorithmsExtension { |
|
44 |
static final HandshakeProducer chNetworkProducer = |
|
45 |
new CHSignatureSchemesProducer(); |
|
46 |
static final ExtensionConsumer chOnLoadConcumer = |
|
47 |
new CHSignatureSchemesConsumer(); |
|
48 |
static final HandshakeAbsence chOnLoadAbsence = |
|
56584 | 49 |
new CHSignatureSchemesOnLoadAbsence(); |
56542 | 50 |
static final HandshakeConsumer chOnTradeConsumer = |
51 |
new CHSignatureSchemesUpdate(); |
|
56584 | 52 |
static final HandshakeAbsence chOnTradeAbsence = |
53 |
new CHSignatureSchemesOnTradeAbsence(); |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
54 |
|
56542 | 55 |
static final HandshakeProducer crNetworkProducer = |
56 |
new CRSignatureSchemesProducer(); |
|
57 |
static final ExtensionConsumer crOnLoadConcumer = |
|
58 |
new CRSignatureSchemesConsumer(); |
|
59 |
static final HandshakeAbsence crOnLoadAbsence = |
|
60 |
new CRSignatureSchemesAbsence(); |
|
61 |
static final HandshakeConsumer crOnTradeConsumer = |
|
62 |
new CRSignatureSchemesUpdate(); |
|
63 |
||
64 |
static final SSLStringize ssStringize = |
|
65 |
new SignatureSchemesStringize(); |
|
66 |
||
67 |
/** |
|
68 |
* The "signature_algorithms" extension. |
|
69 |
*/ |
|
70 |
static final class SignatureSchemesSpec implements SSLExtensionSpec { |
|
71 |
final int[] signatureSchemes; |
|
72 |
||
73 |
SignatureSchemesSpec(List<SignatureScheme> schemes) { |
|
74 |
if (schemes != null) { |
|
75 |
signatureSchemes = new int[schemes.size()]; |
|
76 |
int i = 0; |
|
77 |
for (SignatureScheme scheme : schemes) { |
|
78 |
signatureSchemes[i++] = scheme.id; |
|
79 |
} |
|
80 |
} else { |
|
81 |
this.signatureSchemes = new int[0]; |
|
82 |
} |
|
83 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
84 |
|
56542 | 85 |
SignatureSchemesSpec(ByteBuffer buffer) throws IOException { |
86 |
if (buffer.remaining() < 2) { // 2: the length of the list |
|
87 |
throw new SSLProtocolException( |
|
88 |
"Invalid signature_algorithms: insufficient data"); |
|
89 |
} |
|
90 |
||
91 |
byte[] algs = Record.getBytes16(buffer); |
|
92 |
if (buffer.hasRemaining()) { |
|
93 |
throw new SSLProtocolException( |
|
94 |
"Invalid signature_algorithms: unknown extra data"); |
|
95 |
} |
|
96 |
||
97 |
if (algs == null || algs.length == 0 || (algs.length & 0x01) != 0) { |
|
98 |
throw new SSLProtocolException( |
|
99 |
"Invalid signature_algorithms: incomplete data"); |
|
100 |
} |
|
101 |
||
102 |
int[] schemes = new int[algs.length / 2]; |
|
103 |
for (int i = 0, j = 0; i < algs.length;) { |
|
104 |
byte hash = algs[i++]; |
|
105 |
byte sign = algs[i++]; |
|
106 |
schemes[j++] = ((hash & 0xFF) << 8) | (sign & 0xFF); |
|
107 |
} |
|
108 |
||
109 |
this.signatureSchemes = schemes; |
|
110 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
111 |
|
56542 | 112 |
@Override |
113 |
public String toString() { |
|
114 |
MessageFormat messageFormat = new MessageFormat( |
|
115 |
"\"signature schemes\": '['{0}']'", Locale.ENGLISH); |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
116 |
|
56542 | 117 |
if (signatureSchemes == null || signatureSchemes.length == 0) { |
118 |
Object[] messageFields = { |
|
119 |
"<no supported signature schemes specified>" |
|
120 |
}; |
|
121 |
return messageFormat.format(messageFields); |
|
122 |
} else { |
|
123 |
StringBuilder builder = new StringBuilder(512); |
|
124 |
boolean isFirst = true; |
|
125 |
for (int pv : signatureSchemes) { |
|
126 |
if (isFirst) { |
|
127 |
isFirst = false; |
|
128 |
} else { |
|
129 |
builder.append(", "); |
|
130 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
131 |
|
56542 | 132 |
builder.append(SignatureScheme.nameOf(pv)); |
133 |
} |
|
134 |
||
135 |
Object[] messageFields = { |
|
136 |
builder.toString() |
|
137 |
}; |
|
138 |
||
139 |
return messageFormat.format(messageFields); |
|
140 |
} |
|
141 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
142 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
143 |
|
56542 | 144 |
private static final |
145 |
class SignatureSchemesStringize implements SSLStringize { |
|
146 |
@Override |
|
147 |
public String toString(ByteBuffer buffer) { |
|
148 |
try { |
|
149 |
return (new SignatureSchemesSpec(buffer)).toString(); |
|
150 |
} catch (IOException ioe) { |
|
151 |
// For debug logging only, so please swallow exceptions. |
|
152 |
return ioe.getMessage(); |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
156 |
|
56542 | 157 |
/** |
158 |
* Network data producer of a "signature_algorithms" extension in |
|
159 |
* the ClientHello handshake message. |
|
160 |
*/ |
|
161 |
private static final |
|
162 |
class CHSignatureSchemesProducer implements HandshakeProducer { |
|
163 |
// Prevent instantiation of this class. |
|
164 |
private CHSignatureSchemesProducer() { |
|
165 |
// blank |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
166 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
167 |
|
56542 | 168 |
@Override |
169 |
public byte[] produce(ConnectionContext context, |
|
170 |
HandshakeMessage message) throws IOException { |
|
171 |
// The producing happens in client side only. |
|
172 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
173 |
||
174 |
// Is it a supported and enabled extension? |
|
175 |
if (!chc.sslConfig.isAvailable( |
|
176 |
SSLExtension.CH_SIGNATURE_ALGORITHMS)) { |
|
177 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
178 |
SSLLogger.fine( |
|
179 |
"Ignore unavailable signature_algorithms extension"); |
|
180 |
} |
|
181 |
return null; |
|
182 |
} |
|
183 |
||
184 |
// Produce the extension. |
|
185 |
if (chc.localSupportedSignAlgs == null) { |
|
186 |
chc.localSupportedSignAlgs = |
|
187 |
SignatureScheme.getSupportedAlgorithms( |
|
188 |
chc.algorithmConstraints, chc.activeProtocols); |
|
189 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
190 |
|
56542 | 191 |
int vectorLen = SignatureScheme.sizeInRecord() * |
192 |
chc.localSupportedSignAlgs.size(); |
|
193 |
byte[] extData = new byte[vectorLen + 2]; |
|
194 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
195 |
Record.putInt16(m, vectorLen); |
|
196 |
for (SignatureScheme ss : chc.localSupportedSignAlgs) { |
|
197 |
Record.putInt16(m, ss.id); |
|
198 |
} |
|
199 |
||
200 |
// Update the context. |
|
201 |
chc.handshakeExtensions.put( |
|
202 |
SSLExtension.CH_SIGNATURE_ALGORITHMS, |
|
203 |
new SignatureSchemesSpec(chc.localSupportedSignAlgs)); |
|
204 |
||
205 |
return extData; |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
/** |
|
210 |
* Network data consumer of a "signature_algorithms" extension in |
|
211 |
* the ClientHello handshake message. |
|
212 |
*/ |
|
213 |
private static final |
|
214 |
class CHSignatureSchemesConsumer implements ExtensionConsumer { |
|
215 |
// Prevent instantiation of this class. |
|
216 |
private CHSignatureSchemesConsumer() { |
|
217 |
// blank |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
218 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
219 |
|
56542 | 220 |
@Override |
221 |
public void consume(ConnectionContext context, |
|
222 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
223 |
// The comsuming happens in server side only. |
|
224 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
225 |
||
226 |
// Is it a supported and enabled extension? |
|
227 |
if (!shc.sslConfig.isAvailable( |
|
228 |
SSLExtension.CH_SIGNATURE_ALGORITHMS)) { |
|
229 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) { |
|
230 |
SSLLogger.fine( |
|
231 |
"Ignore unavailable signature_algorithms extension"); |
|
232 |
} |
|
233 |
return; // ignore the extension |
|
234 |
} |
|
235 |
||
236 |
// Parse the extension. |
|
237 |
SignatureSchemesSpec spec; |
|
238 |
try { |
|
239 |
spec = new SignatureSchemesSpec(buffer); |
|
240 |
} catch (IOException ioe) { |
|
241 |
shc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
|
242 |
return; // fatal() always throws, make the compiler happy. |
|
243 |
} |
|
244 |
||
245 |
// Update the context. |
|
246 |
shc.handshakeExtensions.put( |
|
247 |
SSLExtension.CH_SIGNATURE_ALGORITHMS, spec); |
|
248 |
||
249 |
// 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
|
250 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
251 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
252 |
|
56542 | 253 |
/** |
254 |
* After session creation consuming of a "signature_algorithms" |
|
255 |
* extension in the ClientHello handshake message. |
|
256 |
*/ |
|
257 |
private static final class CHSignatureSchemesUpdate |
|
258 |
implements HandshakeConsumer { |
|
259 |
// Prevent instantiation of this class. |
|
260 |
private CHSignatureSchemesUpdate() { |
|
261 |
// blank |
|
262 |
} |
|
263 |
||
264 |
@Override |
|
265 |
public void consume(ConnectionContext context, |
|
266 |
HandshakeMessage message) throws IOException { |
|
267 |
// The comsuming happens in server side only. |
|
268 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
269 |
||
270 |
SignatureSchemesSpec spec = |
|
271 |
(SignatureSchemesSpec)shc.handshakeExtensions.get( |
|
272 |
SSLExtension.CH_SIGNATURE_ALGORITHMS); |
|
273 |
if (spec == null) { |
|
274 |
// Ignore, no "signature_algorithms" extension requested. |
|
275 |
return; |
|
276 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
277 |
|
56542 | 278 |
// update the context |
56600 | 279 |
List<SignatureScheme> sss = |
56542 | 280 |
SignatureScheme.getSupportedAlgorithms( |
281 |
shc.algorithmConstraints, shc.negotiatedProtocol, |
|
282 |
spec.signatureSchemes); |
|
56600 | 283 |
shc.peerRequestedSignatureSchemes = sss; |
56542 | 284 |
|
285 |
// If no "signature_algorithms_cert" extension is present, then |
|
286 |
// the "signature_algorithms" extension also applies to |
|
287 |
// signatures appearing in certificates. |
|
288 |
SignatureSchemesSpec certSpec = |
|
289 |
(SignatureSchemesSpec)shc.handshakeExtensions.get( |
|
290 |
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT); |
|
291 |
if (certSpec == null) { |
|
56600 | 292 |
shc.peerRequestedCertSignSchemes = sss; |
293 |
shc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss); |
|
56542 | 294 |
} |
295 |
||
56600 | 296 |
if (!shc.isResumption && |
297 |
shc.negotiatedProtocol.useTLS13PlusSpec()) { |
|
56542 | 298 |
if (shc.sslConfig.clientAuthType != |
299 |
ClientAuthType.CLIENT_AUTH_NONE) { |
|
300 |
shc.handshakeProducers.putIfAbsent( |
|
301 |
SSLHandshake.CERTIFICATE_REQUEST.id, |
|
302 |
SSLHandshake.CERTIFICATE_REQUEST); |
|
303 |
} |
|
304 |
shc.handshakeProducers.put( |
|
305 |
SSLHandshake.CERTIFICATE.id, |
|
306 |
SSLHandshake.CERTIFICATE); |
|
307 |
shc.handshakeProducers.putIfAbsent( |
|
308 |
SSLHandshake.CERTIFICATE_VERIFY.id, |
|
309 |
SSLHandshake.CERTIFICATE_VERIFY); |
|
310 |
} |
|
311 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
312 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
313 |
|
56542 | 314 |
/** |
315 |
* The absence processing if a "signature_algorithms" extension is |
|
316 |
* not present in the ClientHello handshake message. |
|
317 |
*/ |
|
318 |
private static final |
|
56584 | 319 |
class CHSignatureSchemesOnLoadAbsence implements HandshakeAbsence { |
56542 | 320 |
@Override |
321 |
public void absent(ConnectionContext context, |
|
322 |
HandshakeMessage message) throws IOException { |
|
323 |
// The comsuming happens in server side only. |
|
324 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
325 |
|
56542 | 326 |
// This is a mandatory extension for certificate authentication |
327 |
// in TLS 1.3. |
|
328 |
// |
|
329 |
// We may support the server authentication other than X.509 |
|
330 |
// certificate later. |
|
331 |
if (shc.negotiatedProtocol.useTLS13PlusSpec()) { |
|
332 |
shc.conContext.fatal(Alert.MISSING_EXTENSION, |
|
333 |
"No mandatory signature_algorithms extension in the " + |
|
334 |
"received CertificateRequest handshake message"); |
|
335 |
} |
|
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 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
338 |
|
56542 | 339 |
/** |
56584 | 340 |
* The absence processing if a "signature_algorithms" extension is |
341 |
* not present in the ClientHello handshake message. |
|
342 |
*/ |
|
343 |
private static final |
|
344 |
class CHSignatureSchemesOnTradeAbsence implements HandshakeAbsence { |
|
345 |
@Override |
|
346 |
public void absent(ConnectionContext context, |
|
347 |
HandshakeMessage message) throws IOException { |
|
348 |
// The comsuming happens in server side only. |
|
349 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
350 |
||
351 |
if (shc.negotiatedProtocol.useTLS12PlusSpec()) { |
|
352 |
// Use default hash and signature algorithm: |
|
353 |
// {sha1,rsa} |
|
354 |
// {sha1,dsa} |
|
355 |
// {sha1,ecdsa} |
|
356 |
// Per RFC 5246, If the client supports only the default hash |
|
357 |
// and signature algorithms, it MAY omit the |
|
358 |
// signature_algorithms extension. If the client does not |
|
359 |
// support the default algorithms, or supports other hash |
|
360 |
// and signature algorithms (and it is willing to use them |
|
361 |
// for verifying messages sent by the server, i.e., server |
|
362 |
// certificates and server key exchange), it MUST send the |
|
363 |
// signature_algorithms extension, listing the algorithms it |
|
364 |
// is willing to accept. |
|
365 |
List<SignatureScheme> shemes = Arrays.asList( |
|
366 |
SignatureScheme.RSA_PKCS1_SHA1, |
|
367 |
SignatureScheme.DSA_SHA1, |
|
368 |
SignatureScheme.ECDSA_SHA1 |
|
369 |
); |
|
370 |
||
371 |
shc.peerRequestedSignatureSchemes = shemes; |
|
372 |
if (shc.peerRequestedCertSignSchemes == null || |
|
373 |
shc.peerRequestedCertSignSchemes.isEmpty()) { |
|
374 |
shc.peerRequestedCertSignSchemes = shemes; |
|
375 |
} |
|
376 |
||
377 |
// Use the default peer signature algorithms. |
|
378 |
shc.handshakeSession.setUseDefaultPeerSignAlgs(); |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
||
383 |
/** |
|
56542 | 384 |
* Network data producer of a "signature_algorithms" extension in |
385 |
* the CertificateRequest handshake message. |
|
386 |
*/ |
|
387 |
private static final |
|
388 |
class CRSignatureSchemesProducer implements HandshakeProducer { |
|
389 |
// Prevent instantiation of this class. |
|
390 |
private CRSignatureSchemesProducer() { |
|
391 |
// blank |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
392 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
393 |
|
56542 | 394 |
@Override |
395 |
public byte[] produce(ConnectionContext context, |
|
396 |
HandshakeMessage message) throws IOException { |
|
397 |
// The producing happens in server side only. |
|
398 |
ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
399 |
||
400 |
// Is it a supported and enabled extension? |
|
401 |
// |
|
402 |
// Note that this is a mandatory extension for CertificateRequest |
|
403 |
// handshake message in TLS 1.3. |
|
404 |
if (!shc.sslConfig.isAvailable( |
|
405 |
SSLExtension.CR_SIGNATURE_ALGORITHMS)) { |
|
406 |
shc.conContext.fatal(Alert.MISSING_EXTENSION, |
|
407 |
"No available signature_algorithms extension " + |
|
408 |
"for client certificate authentication"); |
|
409 |
return null; // make the compiler happy |
|
410 |
} |
|
411 |
||
412 |
// Produce the extension. |
|
413 |
if (shc.localSupportedSignAlgs == null) { |
|
414 |
shc.localSupportedSignAlgs = |
|
415 |
SignatureScheme.getSupportedAlgorithms( |
|
416 |
shc.algorithmConstraints, shc.activeProtocols); |
|
417 |
} |
|
418 |
||
419 |
int vectorLen = SignatureScheme.sizeInRecord() * |
|
420 |
shc.localSupportedSignAlgs.size(); |
|
421 |
byte[] extData = new byte[vectorLen + 2]; |
|
422 |
ByteBuffer m = ByteBuffer.wrap(extData); |
|
423 |
Record.putInt16(m, vectorLen); |
|
424 |
for (SignatureScheme ss : shc.localSupportedSignAlgs) { |
|
425 |
Record.putInt16(m, ss.id); |
|
426 |
} |
|
427 |
||
428 |
// Update the context. |
|
429 |
shc.handshakeExtensions.put( |
|
430 |
SSLExtension.CR_SIGNATURE_ALGORITHMS, |
|
431 |
new SignatureSchemesSpec(shc.localSupportedSignAlgs)); |
|
432 |
||
433 |
return extData; |
|
434 |
} |
|
435 |
} |
|
436 |
||
437 |
/** |
|
438 |
* Network data consumer of a "signature_algorithms" extension in |
|
439 |
* the CertificateRequest handshake message. |
|
440 |
*/ |
|
441 |
private static final |
|
442 |
class CRSignatureSchemesConsumer implements ExtensionConsumer { |
|
443 |
// Prevent instantiation of this class. |
|
444 |
private CRSignatureSchemesConsumer() { |
|
445 |
// blank |
|
446 |
} |
|
447 |
@Override |
|
448 |
public void consume(ConnectionContext context, |
|
449 |
HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
450 |
// The comsuming happens in client side only. |
|
451 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
452 |
||
453 |
// Is it a supported and enabled extension? |
|
454 |
// |
|
455 |
// Note that this is a mandatory extension for CertificateRequest |
|
456 |
// handshake message in TLS 1.3. |
|
457 |
if (!chc.sslConfig.isAvailable( |
|
458 |
SSLExtension.CR_SIGNATURE_ALGORITHMS)) { |
|
459 |
chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, |
|
460 |
"No available signature_algorithms extension " + |
|
461 |
"for client certificate authentication"); |
|
462 |
return; // make the compiler happy |
|
463 |
} |
|
464 |
||
465 |
// Parse the extension. |
|
466 |
SignatureSchemesSpec spec; |
|
467 |
try { |
|
468 |
spec = new SignatureSchemesSpec(buffer); |
|
469 |
} catch (IOException ioe) { |
|
470 |
chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe); |
|
471 |
return; // fatal() always throws, make the compiler happy. |
|
472 |
} |
|
473 |
||
474 |
List<SignatureScheme> knownSignatureSchemes = new LinkedList<>(); |
|
475 |
for (int id : spec.signatureSchemes) { |
|
476 |
SignatureScheme ss = SignatureScheme.valueOf(id); |
|
477 |
if (ss != null) { |
|
478 |
knownSignatureSchemes.add(ss); |
|
479 |
} |
|
480 |
} |
|
481 |
||
482 |
// Update the context. |
|
483 |
// chc.peerRequestedSignatureSchemes = knownSignatureSchemes; |
|
484 |
chc.handshakeExtensions.put( |
|
485 |
SSLExtension.CR_SIGNATURE_ALGORITHMS, spec); |
|
486 |
||
487 |
// No impact on session resumption. |
|
488 |
} |
|
489 |
} |
|
490 |
||
491 |
/** |
|
492 |
* After session creation consuming of a "signature_algorithms" |
|
493 |
* extension in the CertificateRequest handshake message. |
|
494 |
*/ |
|
495 |
private static final class CRSignatureSchemesUpdate |
|
496 |
implements HandshakeConsumer { |
|
497 |
// Prevent instantiation of this class. |
|
498 |
private CRSignatureSchemesUpdate() { |
|
499 |
// blank |
|
500 |
} |
|
501 |
||
502 |
@Override |
|
503 |
public void consume(ConnectionContext context, |
|
504 |
HandshakeMessage message) throws IOException { |
|
505 |
// The comsuming happens in client side only. |
|
506 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
507 |
||
508 |
SignatureSchemesSpec spec = |
|
509 |
(SignatureSchemesSpec)chc.handshakeExtensions.get( |
|
510 |
SSLExtension.CR_SIGNATURE_ALGORITHMS); |
|
511 |
if (spec == null) { |
|
512 |
// Ignore, no "signature_algorithms" extension requested. |
|
513 |
return; |
|
514 |
} |
|
515 |
||
516 |
// update the context |
|
56600 | 517 |
List<SignatureScheme> sss = |
56542 | 518 |
SignatureScheme.getSupportedAlgorithms( |
519 |
chc.algorithmConstraints, chc.negotiatedProtocol, |
|
520 |
spec.signatureSchemes); |
|
56600 | 521 |
chc.peerRequestedSignatureSchemes = sss; |
56542 | 522 |
|
523 |
// If no "signature_algorithms_cert" extension is present, then |
|
524 |
// the "signature_algorithms" extension also applies to |
|
525 |
// signatures appearing in certificates. |
|
526 |
SignatureSchemesSpec certSpec = |
|
527 |
(SignatureSchemesSpec)chc.handshakeExtensions.get( |
|
528 |
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT); |
|
529 |
if (certSpec == null) { |
|
56600 | 530 |
chc.peerRequestedCertSignSchemes = sss; |
531 |
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss); |
|
56542 | 532 |
} |
533 |
} |
|
534 |
} |
|
535 |
||
536 |
/** |
|
537 |
* The absence processing if a "signature_algorithms" extension is |
|
538 |
* not present in the CertificateRequest handshake message. |
|
539 |
*/ |
|
540 |
private static final |
|
541 |
class CRSignatureSchemesAbsence implements HandshakeAbsence { |
|
542 |
@Override |
|
543 |
public void absent(ConnectionContext context, |
|
544 |
HandshakeMessage message) throws IOException { |
|
545 |
// The comsuming happens in client side only. |
|
546 |
ClientHandshakeContext chc = (ClientHandshakeContext)context; |
|
547 |
||
548 |
// This is a mandatory extension for CertificateRequest handshake |
|
549 |
// message in TLS 1.3. |
|
550 |
chc.conContext.fatal(Alert.MISSING_EXTENSION, |
|
551 |
"No mandatory signature_algorithms extension in the " + |
|
552 |
"received CertificateRequest handshake message"); |
|
553 |
} |
|
14330
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
554 |
} |
e4cb78065603
8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff
changeset
|
555 |
} |