25
25
26
26
package sun .security .ssl ;
27
27
28
+ import static sun .security .ssl .SignatureScheme .CERTIFICATE_SCOPE ;
28
29
import static sun .security .ssl .SignatureScheme .HANDSHAKE_SCOPE ;
29
30
30
31
import java .io .IOException ;
33
34
import java .util .Arrays ;
34
35
import java .util .List ;
35
36
import java .util .Locale ;
37
+ import javax .net .ssl .SSLException ;
36
38
import javax .net .ssl .SSLProtocolException ;
37
39
import sun .security .ssl .SSLExtension .ExtensionConsumer ;
38
40
import sun .security .ssl .SSLExtension .SSLExtensionSpec ;
@@ -276,30 +278,8 @@ public void consume(ConnectionContext context,
276
278
return ;
277
279
}
278
280
279
- // update the context
280
- List <SignatureScheme > sss =
281
- SignatureScheme .getSupportedAlgorithms (
282
- shc .sslConfig ,
283
- shc .algorithmConstraints , shc .negotiatedProtocol ,
284
- spec .signatureSchemes ,
285
- HANDSHAKE_SCOPE );
286
-
287
- if (sss == null || sss .isEmpty ()) {
288
- throw shc .conContext .fatal (Alert .HANDSHAKE_FAILURE ,
289
- "No supported signature algorithm" );
290
- }
291
- shc .peerRequestedSignatureSchemes = sss ;
292
-
293
- // If no "signature_algorithms_cert" extension is present, then
294
- // the "signature_algorithms" extension also applies to
295
- // signatures appearing in certificates.
296
- SignatureSchemesSpec certSpec =
297
- (SignatureSchemesSpec )shc .handshakeExtensions .get (
298
- SSLExtension .CH_SIGNATURE_ALGORITHMS_CERT );
299
- if (certSpec == null ) {
300
- shc .peerRequestedCertSignSchemes = sss ;
301
- shc .handshakeSession .setPeerSupportedSignatureAlgorithms (sss );
302
- }
281
+ updateHandshakeContext (shc , spec .signatureSchemes ,
282
+ SSLExtension .CH_SIGNATURE_ALGORITHMS_CERT );
303
283
304
284
if (!shc .isResumption &&
305
285
shc .negotiatedProtocol .useTLS13PlusSpec ()) {
@@ -507,30 +487,8 @@ public void consume(ConnectionContext context,
507
487
return ;
508
488
}
509
489
510
- // update the context
511
- List <SignatureScheme > sss =
512
- SignatureScheme .getSupportedAlgorithms (
513
- chc .sslConfig ,
514
- chc .algorithmConstraints , chc .negotiatedProtocol ,
515
- spec .signatureSchemes ,
516
- HANDSHAKE_SCOPE );
517
-
518
- if (sss == null || sss .isEmpty ()) {
519
- throw chc .conContext .fatal (Alert .HANDSHAKE_FAILURE ,
520
- "No supported signature algorithm" );
521
- }
522
- chc .peerRequestedSignatureSchemes = sss ;
523
-
524
- // If no "signature_algorithms_cert" extension is present, then
525
- // the "signature_algorithms" extension also applies to
526
- // signatures appearing in certificates.
527
- SignatureSchemesSpec certSpec =
528
- (SignatureSchemesSpec )chc .handshakeExtensions .get (
529
- SSLExtension .CR_SIGNATURE_ALGORITHMS_CERT );
530
- if (certSpec == null ) {
531
- chc .peerRequestedCertSignSchemes = sss ;
532
- chc .handshakeSession .setPeerSupportedSignatureAlgorithms (sss );
533
- }
490
+ updateHandshakeContext (chc , spec .signatureSchemes ,
491
+ SSLExtension .CR_SIGNATURE_ALGORITHMS_CERT );
534
492
}
535
493
}
536
494
@@ -553,4 +511,49 @@ public void absent(ConnectionContext context,
553
511
"received CertificateRequest handshake message" );
554
512
}
555
513
}
514
+
515
+ // Updates given HandshakeContext with peer signature schemes.
516
+ private static void updateHandshakeContext (HandshakeContext hc ,
517
+ int [] signatureSchemes , SSLExtension signatureAlgorithmsCertExt )
518
+ throws SSLException {
519
+ List <SignatureScheme > handshakeSS =
520
+ SignatureScheme .getSupportedAlgorithms (
521
+ hc .sslConfig ,
522
+ hc .algorithmConstraints ,
523
+ hc .negotiatedProtocol ,
524
+ signatureSchemes ,
525
+ HANDSHAKE_SCOPE );
526
+
527
+ if (handshakeSS .isEmpty ()) {
528
+ throw hc .conContext .fatal (Alert .HANDSHAKE_FAILURE ,
529
+ "No supported signature algorithm" );
530
+ }
531
+
532
+ hc .peerRequestedSignatureSchemes = handshakeSS ;
533
+
534
+ // If no "signature_algorithms_cert" extension is present, then
535
+ // the "signature_algorithms" extension also applies to
536
+ // signatures appearing in certificates.
537
+ SignatureSchemesSpec certSpec =
538
+ (SignatureSchemesSpec ) hc .handshakeExtensions .get (
539
+ signatureAlgorithmsCertExt );
540
+
541
+ if (certSpec == null ) {
542
+ List <SignatureScheme > certSS =
543
+ SignatureScheme .getSupportedAlgorithms (
544
+ hc .sslConfig ,
545
+ hc .algorithmConstraints ,
546
+ hc .negotiatedProtocol ,
547
+ signatureSchemes ,
548
+ CERTIFICATE_SCOPE );
549
+
550
+ if (certSS .isEmpty ()) {
551
+ throw hc .conContext .fatal (Alert .HANDSHAKE_FAILURE ,
552
+ "No supported signature algorithm" );
553
+ }
554
+
555
+ hc .peerRequestedCertSignSchemes = certSS ;
556
+ hc .handshakeSession .setPeerSupportedSignatureAlgorithms (certSS );
557
+ }
558
+ }
556
559
}
0 commit comments