Skip to content

Commit b34a3ee

Browse files
committed
8355779: When no "signature_algorithms_cert" extension is present we do not apply certificate scope constraints to algorithms in "signature_algorithms" extension
Backport-of: 34807df7627b067f750578987c941213a5f8336a
1 parent 03ab6e4 commit b34a3ee

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

src/java.base/share/classes/sun/security/ssl/SignatureAlgorithmsExtension.java

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package sun.security.ssl;
2727

28+
import static sun.security.ssl.SignatureScheme.CERTIFICATE_SCOPE;
2829
import static sun.security.ssl.SignatureScheme.HANDSHAKE_SCOPE;
2930

3031
import java.io.IOException;
@@ -33,6 +34,7 @@
3334
import java.util.Arrays;
3435
import java.util.List;
3536
import java.util.Locale;
37+
import javax.net.ssl.SSLException;
3638
import javax.net.ssl.SSLProtocolException;
3739
import sun.security.ssl.SSLExtension.ExtensionConsumer;
3840
import sun.security.ssl.SSLExtension.SSLExtensionSpec;
@@ -276,30 +278,8 @@ public void consume(ConnectionContext context,
276278
return;
277279
}
278280

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);
303283

304284
if (!shc.isResumption &&
305285
shc.negotiatedProtocol.useTLS13PlusSpec()) {
@@ -507,30 +487,8 @@ public void consume(ConnectionContext context,
507487
return;
508488
}
509489

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);
534492
}
535493
}
536494

@@ -553,4 +511,49 @@ public void absent(ConnectionContext context,
553511
"received CertificateRequest handshake message");
554512
}
555513
}
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+
}
556559
}

0 commit comments

Comments
 (0)