Skip to content

Commit 34807df

Browse files
artur-oracleseanjmullan
authored andcommitted
8355779: When no "signature_algorithms_cert" extension is present we do not apply certificate scope constraints to algorithms in "signature_algorithms" extension
Reviewed-by: mullan
1 parent 7b31762 commit 34807df

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;
@@ -270,30 +272,8 @@ public void consume(ConnectionContext context,
270272
return;
271273
}
272274

273-
// update the context
274-
List<SignatureScheme> sss =
275-
SignatureScheme.getSupportedAlgorithms(
276-
shc.sslConfig,
277-
shc.algorithmConstraints, shc.negotiatedProtocol,
278-
spec.signatureSchemes,
279-
HANDSHAKE_SCOPE);
280-
281-
if (sss == null || sss.isEmpty()) {
282-
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
283-
"No supported signature algorithm");
284-
}
285-
shc.peerRequestedSignatureSchemes = sss;
286-
287-
// If no "signature_algorithms_cert" extension is present, then
288-
// the "signature_algorithms" extension also applies to
289-
// signatures appearing in certificates.
290-
SignatureSchemesSpec certSpec =
291-
(SignatureSchemesSpec)shc.handshakeExtensions.get(
292-
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
293-
if (certSpec == null) {
294-
shc.peerRequestedCertSignSchemes = sss;
295-
shc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
296-
}
275+
updateHandshakeContext(shc, spec.signatureSchemes,
276+
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
297277

298278
if (!shc.isResumption &&
299279
shc.negotiatedProtocol.useTLS13PlusSpec()) {
@@ -497,30 +477,8 @@ public void consume(ConnectionContext context,
497477
return;
498478
}
499479

500-
// update the context
501-
List<SignatureScheme> sss =
502-
SignatureScheme.getSupportedAlgorithms(
503-
chc.sslConfig,
504-
chc.algorithmConstraints, chc.negotiatedProtocol,
505-
spec.signatureSchemes,
506-
HANDSHAKE_SCOPE);
507-
508-
if (sss == null || sss.isEmpty()) {
509-
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
510-
"No supported signature algorithm");
511-
}
512-
chc.peerRequestedSignatureSchemes = sss;
513-
514-
// If no "signature_algorithms_cert" extension is present, then
515-
// the "signature_algorithms" extension also applies to
516-
// signatures appearing in certificates.
517-
SignatureSchemesSpec certSpec =
518-
(SignatureSchemesSpec)chc.handshakeExtensions.get(
519-
SSLExtension.CR_SIGNATURE_ALGORITHMS_CERT);
520-
if (certSpec == null) {
521-
chc.peerRequestedCertSignSchemes = sss;
522-
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
523-
}
480+
updateHandshakeContext(chc, spec.signatureSchemes,
481+
SSLExtension.CR_SIGNATURE_ALGORITHMS_CERT);
524482
}
525483
}
526484

@@ -543,4 +501,49 @@ public void absent(ConnectionContext context,
543501
"received CertificateRequest handshake message");
544502
}
545503
}
504+
505+
// Updates given HandshakeContext with peer signature schemes.
506+
private static void updateHandshakeContext(HandshakeContext hc,
507+
int[] signatureSchemes, SSLExtension signatureAlgorithmsCertExt)
508+
throws SSLException {
509+
List<SignatureScheme> handshakeSS =
510+
SignatureScheme.getSupportedAlgorithms(
511+
hc.sslConfig,
512+
hc.algorithmConstraints,
513+
hc.negotiatedProtocol,
514+
signatureSchemes,
515+
HANDSHAKE_SCOPE);
516+
517+
if (handshakeSS.isEmpty()) {
518+
throw hc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
519+
"No supported signature algorithm");
520+
}
521+
522+
hc.peerRequestedSignatureSchemes = handshakeSS;
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) hc.handshakeExtensions.get(
529+
signatureAlgorithmsCertExt);
530+
531+
if (certSpec == null) {
532+
List<SignatureScheme> certSS =
533+
SignatureScheme.getSupportedAlgorithms(
534+
hc.sslConfig,
535+
hc.algorithmConstraints,
536+
hc.negotiatedProtocol,
537+
signatureSchemes,
538+
CERTIFICATE_SCOPE);
539+
540+
if (certSS.isEmpty()) {
541+
throw hc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
542+
"No supported signature algorithm");
543+
}
544+
545+
hc.peerRequestedCertSignSchemes = certSS;
546+
hc.handshakeSession.setPeerSupportedSignatureAlgorithms(certSS);
547+
}
548+
}
546549
}

0 commit comments

Comments
 (0)