Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package sun.security.ssl;

import static sun.security.ssl.SignatureScheme.CERTIFICATE_SCOPE;
import static sun.security.ssl.SignatureScheme.HANDSHAKE_SCOPE;

import java.io.IOException;
Expand All @@ -33,6 +34,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLProtocolException;
import sun.security.ssl.SSLExtension.ExtensionConsumer;
import sun.security.ssl.SSLExtension.SSLExtensionSpec;
Expand Down Expand Up @@ -276,30 +278,8 @@ public void consume(ConnectionContext context,
return;
}

// update the context
List<SignatureScheme> sss =
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints, shc.negotiatedProtocol,
spec.signatureSchemes,
HANDSHAKE_SCOPE);

if (sss == null || sss.isEmpty()) {
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
"No supported signature algorithm");
}
shc.peerRequestedSignatureSchemes = sss;

// If no "signature_algorithms_cert" extension is present, then
// the "signature_algorithms" extension also applies to
// signatures appearing in certificates.
SignatureSchemesSpec certSpec =
(SignatureSchemesSpec)shc.handshakeExtensions.get(
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);
if (certSpec == null) {
shc.peerRequestedCertSignSchemes = sss;
shc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
}
updateHandshakeContext(shc, spec.signatureSchemes,
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT);

if (!shc.isResumption &&
shc.negotiatedProtocol.useTLS13PlusSpec()) {
Expand Down Expand Up @@ -507,30 +487,8 @@ public void consume(ConnectionContext context,
return;
}

// update the context
List<SignatureScheme> sss =
SignatureScheme.getSupportedAlgorithms(
chc.sslConfig,
chc.algorithmConstraints, chc.negotiatedProtocol,
spec.signatureSchemes,
HANDSHAKE_SCOPE);

if (sss == null || sss.isEmpty()) {
throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
"No supported signature algorithm");
}
chc.peerRequestedSignatureSchemes = sss;

// If no "signature_algorithms_cert" extension is present, then
// the "signature_algorithms" extension also applies to
// signatures appearing in certificates.
SignatureSchemesSpec certSpec =
(SignatureSchemesSpec)chc.handshakeExtensions.get(
SSLExtension.CR_SIGNATURE_ALGORITHMS_CERT);
if (certSpec == null) {
chc.peerRequestedCertSignSchemes = sss;
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
}
updateHandshakeContext(chc, spec.signatureSchemes,
SSLExtension.CR_SIGNATURE_ALGORITHMS_CERT);
}
}

Expand All @@ -553,4 +511,49 @@ public void absent(ConnectionContext context,
"received CertificateRequest handshake message");
}
}

// Updates given HandshakeContext with peer signature schemes.
private static void updateHandshakeContext(HandshakeContext hc,
int[] signatureSchemes, SSLExtension signatureAlgorithmsCertExt)
throws SSLException {
List<SignatureScheme> handshakeSS =
SignatureScheme.getSupportedAlgorithms(
hc.sslConfig,
hc.algorithmConstraints,
hc.negotiatedProtocol,
signatureSchemes,
HANDSHAKE_SCOPE);

if (handshakeSS.isEmpty()) {
throw hc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
"No supported signature algorithm");
}

hc.peerRequestedSignatureSchemes = handshakeSS;

// If no "signature_algorithms_cert" extension is present, then
// the "signature_algorithms" extension also applies to
// signatures appearing in certificates.
SignatureSchemesSpec certSpec =
(SignatureSchemesSpec) hc.handshakeExtensions.get(
signatureAlgorithmsCertExt);

if (certSpec == null) {
List<SignatureScheme> certSS =
SignatureScheme.getSupportedAlgorithms(
hc.sslConfig,
hc.algorithmConstraints,
hc.negotiatedProtocol,
signatureSchemes,
CERTIFICATE_SCOPE);

if (certSS.isEmpty()) {
throw hc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
"No supported signature algorithm");
}

hc.peerRequestedCertSignSchemes = certSS;
hc.handshakeSession.setPeerSupportedSignatureAlgorithms(certSS);
}
}
}