24 */ |
24 */ |
25 |
25 |
26 package sun.security.ssl; |
26 package sun.security.ssl; |
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
29 import java.util.ArrayList; |
29 import java.nio.ByteBuffer; |
30 import java.util.Collection; |
30 import java.text.MessageFormat; |
31 |
31 import java.util.Arrays; |
|
32 import java.util.LinkedList; |
|
33 import java.util.List; |
|
34 import java.util.Locale; |
32 import javax.net.ssl.SSLProtocolException; |
35 import javax.net.ssl.SSLProtocolException; |
33 |
36 import sun.security.ssl.SSLExtension.ExtensionConsumer; |
34 /* |
37 import sun.security.ssl.SSLExtension.SSLExtensionSpec; |
35 * [RFC5246] The client uses the "signature_algorithms" extension to |
38 import sun.security.ssl.SSLHandshake.HandshakeMessage; |
36 * indicate to the server which signature/hash algorithm pairs may be |
39 |
37 * used in digital signatures. The "extension_data" field of this |
40 /** |
38 * extension contains a "supported_signature_algorithms" value. |
41 * Pack of the "signature_algorithms" extensions [RFC 5246]. |
39 * |
|
40 * enum { |
|
41 * none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5), |
|
42 * sha512(6), (255) |
|
43 * } HashAlgorithm; |
|
44 * |
|
45 * enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) } |
|
46 * SignatureAlgorithm; |
|
47 * |
|
48 * struct { |
|
49 * HashAlgorithm hash; |
|
50 * SignatureAlgorithm signature; |
|
51 * } SignatureAndHashAlgorithm; |
|
52 * |
|
53 * SignatureAndHashAlgorithm |
|
54 * supported_signature_algorithms<2..2^16-2>; |
|
55 */ |
42 */ |
56 final class SignatureAlgorithmsExtension extends HelloExtension { |
43 final class SignatureAlgorithmsExtension { |
57 |
44 static final HandshakeProducer chNetworkProducer = |
58 private Collection<SignatureAndHashAlgorithm> algorithms; |
45 new CHSignatureSchemesProducer(); |
59 private int algorithmsLen; // length of supported_signature_algorithms |
46 static final ExtensionConsumer chOnLoadConsumer = |
60 |
47 new CHSignatureSchemesConsumer(); |
61 SignatureAlgorithmsExtension( |
48 static final HandshakeAbsence chOnLoadAbsence = |
62 Collection<SignatureAndHashAlgorithm> signAlgs) { |
49 new CHSignatureSchemesOnLoadAbsence(); |
63 |
50 static final HandshakeConsumer chOnTradeConsumer = |
64 super(ExtensionType.EXT_SIGNATURE_ALGORITHMS); |
51 new CHSignatureSchemesUpdate(); |
65 |
52 static final HandshakeAbsence chOnTradeAbsence = |
66 algorithms = new ArrayList<SignatureAndHashAlgorithm>(signAlgs); |
53 new CHSignatureSchemesOnTradeAbsence(); |
67 algorithmsLen = |
54 |
68 SignatureAndHashAlgorithm.sizeInRecord() * algorithms.size(); |
55 static final HandshakeProducer crNetworkProducer = |
69 } |
56 new CRSignatureSchemesProducer(); |
70 |
57 static final ExtensionConsumer crOnLoadConsumer = |
71 SignatureAlgorithmsExtension(HandshakeInStream s, int len) |
58 new CRSignatureSchemesConsumer(); |
72 throws IOException { |
59 static final HandshakeAbsence crOnLoadAbsence = |
73 super(ExtensionType.EXT_SIGNATURE_ALGORITHMS); |
60 new CRSignatureSchemesAbsence(); |
74 |
61 static final HandshakeConsumer crOnTradeConsumer = |
75 algorithmsLen = s.getInt16(); |
62 new CRSignatureSchemesUpdate(); |
76 if (algorithmsLen == 0 || algorithmsLen + 2 != len) { |
63 |
77 throw new SSLProtocolException("Invalid " + type + " extension"); |
64 static final SSLStringizer ssStringizer = |
78 } |
65 new SignatureSchemesStringizer(); |
79 |
66 |
80 algorithms = new ArrayList<SignatureAndHashAlgorithm>(); |
67 /** |
81 int remains = algorithmsLen; |
68 * The "signature_algorithms" extension. |
82 int sequence = 0; |
69 */ |
83 while (remains > 1) { // needs at least two bytes |
70 static final class SignatureSchemesSpec implements SSLExtensionSpec { |
84 int hash = s.getInt8(); // hash algorithm |
71 final int[] signatureSchemes; |
85 int signature = s.getInt8(); // signature algorithm |
72 |
86 |
73 SignatureSchemesSpec(List<SignatureScheme> schemes) { |
87 SignatureAndHashAlgorithm algorithm = |
74 if (schemes != null) { |
88 SignatureAndHashAlgorithm.valueOf(hash, signature, ++sequence); |
75 signatureSchemes = new int[schemes.size()]; |
89 algorithms.add(algorithm); |
76 int i = 0; |
90 remains -= 2; // one byte for hash, one byte for signature |
77 for (SignatureScheme scheme : schemes) { |
91 } |
78 signatureSchemes[i++] = scheme.id; |
92 |
79 } |
93 if (remains != 0) { |
|
94 throw new SSLProtocolException("Invalid server_name extension"); |
|
95 } |
|
96 } |
|
97 |
|
98 Collection<SignatureAndHashAlgorithm> getSignAlgorithms() { |
|
99 return algorithms; |
|
100 } |
|
101 |
|
102 @Override |
|
103 int length() { |
|
104 return 6 + algorithmsLen; |
|
105 } |
|
106 |
|
107 @Override |
|
108 void send(HandshakeOutStream s) throws IOException { |
|
109 s.putInt16(type.id); |
|
110 s.putInt16(algorithmsLen + 2); |
|
111 s.putInt16(algorithmsLen); |
|
112 |
|
113 for (SignatureAndHashAlgorithm algorithm : algorithms) { |
|
114 s.putInt8(algorithm.getHashValue()); // HashAlgorithm |
|
115 s.putInt8(algorithm.getSignatureValue()); // SignatureAlgorithm |
|
116 } |
|
117 } |
|
118 |
|
119 @Override |
|
120 public String toString() { |
|
121 StringBuilder sb = new StringBuilder(); |
|
122 boolean opened = false; |
|
123 for (SignatureAndHashAlgorithm signAlg : algorithms) { |
|
124 if (opened) { |
|
125 sb.append(", " + signAlg.getAlgorithmName()); |
|
126 } else { |
80 } else { |
127 sb.append(signAlg.getAlgorithmName()); |
81 this.signatureSchemes = new int[0]; |
128 opened = true; |
82 } |
129 } |
83 } |
130 } |
84 |
131 |
85 SignatureSchemesSpec(ByteBuffer buffer) throws IOException { |
132 return "Extension " + type + ", signature_algorithms: " + sb; |
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 } |
|
111 |
|
112 @Override |
|
113 public String toString() { |
|
114 MessageFormat messageFormat = new MessageFormat( |
|
115 "\"signature schemes\": '['{0}']'", Locale.ENGLISH); |
|
116 |
|
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 } |
|
131 |
|
132 builder.append(SignatureScheme.nameOf(pv)); |
|
133 } |
|
134 |
|
135 Object[] messageFields = { |
|
136 builder.toString() |
|
137 }; |
|
138 |
|
139 return messageFormat.format(messageFields); |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 private static final |
|
145 class SignatureSchemesStringizer implements SSLStringizer { |
|
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 } |
|
156 |
|
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 |
|
166 } |
|
167 |
|
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 } |
|
190 |
|
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 |
|
218 } |
|
219 |
|
220 @Override |
|
221 public void consume(ConnectionContext context, |
|
222 HandshakeMessage message, ByteBuffer buffer) throws IOException { |
|
223 // The consuming 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. |
|
250 } |
|
251 } |
|
252 |
|
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 consuming 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 } |
|
277 |
|
278 // update the context |
|
279 List<SignatureScheme> sss = |
|
280 SignatureScheme.getSupportedAlgorithms( |
|
281 shc.algorithmConstraints, shc.negotiatedProtocol, |
|
282 spec.signatureSchemes); |
|
283 shc.peerRequestedSignatureSchemes = sss; |
|
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) { |
|
292 shc.peerRequestedCertSignSchemes = sss; |
|
293 shc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss); |
|
294 } |
|
295 |
|
296 if (!shc.isResumption && |
|
297 shc.negotiatedProtocol.useTLS13PlusSpec()) { |
|
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 } |
|
312 } |
|
313 |
|
314 /** |
|
315 * The absence processing if a "signature_algorithms" extension is |
|
316 * not present in the ClientHello handshake message. |
|
317 */ |
|
318 private static final |
|
319 class CHSignatureSchemesOnLoadAbsence implements HandshakeAbsence { |
|
320 @Override |
|
321 public void absent(ConnectionContext context, |
|
322 HandshakeMessage message) throws IOException { |
|
323 // The consuming happens in server side only. |
|
324 ServerHandshakeContext shc = (ServerHandshakeContext)context; |
|
325 |
|
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 } |
|
336 } |
|
337 } |
|
338 |
|
339 /** |
|
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 consuming 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 /** |
|
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 |
|
392 } |
|
393 |
|
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 consuming 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 consuming 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 |
|
517 List<SignatureScheme> sss = |
|
518 SignatureScheme.getSupportedAlgorithms( |
|
519 chc.algorithmConstraints, chc.negotiatedProtocol, |
|
520 spec.signatureSchemes); |
|
521 chc.peerRequestedSignatureSchemes = sss; |
|
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) { |
|
530 chc.peerRequestedCertSignSchemes = sss; |
|
531 chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss); |
|
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 consuming 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 } |
133 } |
554 } |
134 } |
555 } |
135 |
|