Skip to content
Open
Show file tree
Hide file tree
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,6 +25,8 @@

package sun.security.ssl;

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

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
Expand Down Expand Up @@ -96,26 +98,27 @@ public byte[] produce(ConnectionContext context,
}

// Produce the extension.
if (chc.localSupportedSignAlgs == null) {
chc.localSupportedSignAlgs =
SignatureScheme.getSupportedAlgorithms(
chc.sslConfig,
chc.algorithmConstraints, chc.activeProtocols);
if (chc.localSupportedCertSignAlgs == null) {
chc.localSupportedCertSignAlgs =
SignatureScheme.getSupportedAlgorithms(
chc.sslConfig,
chc.algorithmConstraints, chc.activeProtocols,
CERTIFICATE_SCOPE);
}

int vectorLen = SignatureScheme.sizeInRecord() *
chc.localSupportedSignAlgs.size();
chc.localSupportedCertSignAlgs.size();
byte[] extData = new byte[vectorLen + 2];
ByteBuffer m = ByteBuffer.wrap(extData);
Record.putInt16(m, vectorLen);
for (SignatureScheme ss : chc.localSupportedSignAlgs) {
for (SignatureScheme ss : chc.localSupportedCertSignAlgs) {
Record.putInt16(m, ss.id);
}

// Update the context.
chc.handshakeExtensions.put(
SSLExtension.CH_SIGNATURE_ALGORITHMS_CERT,
new SignatureSchemesSpec(chc.localSupportedSignAlgs));
new SignatureSchemesSpec(chc.localSupportedCertSignAlgs));

return extData;
}
Expand Down Expand Up @@ -195,7 +198,9 @@ public void consume(ConnectionContext context,
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints, shc.negotiatedProtocol,
spec.signatureSchemes);
spec.signatureSchemes,
CERTIFICATE_SCOPE);

shc.peerRequestedCertSignSchemes = schemes;
shc.handshakeSession.setPeerSupportedSignatureAlgorithms(schemes);

Expand Down Expand Up @@ -244,24 +249,28 @@ public byte[] produce(ConnectionContext context,
}

// Produce the extension.
List<SignatureScheme> sigAlgs =
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints,
List.of(shc.negotiatedProtocol));
if (shc.localSupportedCertSignAlgs == null) {
shc.localSupportedCertSignAlgs =
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints,
List.of(shc.negotiatedProtocol),
CERTIFICATE_SCOPE);
}

int vectorLen = SignatureScheme.sizeInRecord() * sigAlgs.size();
int vectorLen = SignatureScheme.sizeInRecord()
* shc.localSupportedCertSignAlgs.size();
byte[] extData = new byte[vectorLen + 2];
ByteBuffer m = ByteBuffer.wrap(extData);
Record.putInt16(m, vectorLen);
for (SignatureScheme ss : sigAlgs) {
for (SignatureScheme ss : shc.localSupportedCertSignAlgs) {
Record.putInt16(m, ss.id);
}

// Update the context.
shc.handshakeExtensions.put(
SSLExtension.CR_SIGNATURE_ALGORITHMS_CERT,
new SignatureSchemesSpec(shc.localSupportedSignAlgs));
new SignatureSchemesSpec(shc.localSupportedCertSignAlgs));

return extData;
}
Expand Down Expand Up @@ -340,7 +349,9 @@ public void consume(ConnectionContext context,
SignatureScheme.getSupportedAlgorithms(
chc.sslConfig,
chc.algorithmConstraints, chc.negotiatedProtocol,
spec.signatureSchemes);
spec.signatureSchemes,
CERTIFICATE_SCOPE);

chc.peerRequestedCertSignSchemes = schemes;
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(schemes);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,6 +25,9 @@

package sun.security.ssl;

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

import java.io.IOException;
import java.nio.ByteBuffer;
import java.security.PrivateKey;
Expand Down Expand Up @@ -380,7 +383,6 @@ public void consume(ConnectionContext context,
crm.getAuthorities(), (SSLEngine)chc.conContext.transport);
}


if (clientAlias == null) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
SSLLogger.warning("No available client authentication");
Expand Down Expand Up @@ -607,16 +609,33 @@ private T12CertificateRequestProducer() {
public byte[] produce(ConnectionContext context,
HandshakeMessage message) throws IOException {
// The producing happens in server side only.
ServerHandshakeContext shc = (ServerHandshakeContext)context;
ServerHandshakeContext shc = (ServerHandshakeContext) context;

if (shc.localSupportedSignAlgs == null) {
shc.localSupportedSignAlgs =
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints, shc.activeProtocols);
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints, shc.activeProtocols,
HANDSHAKE_SCOPE);
}

if (shc.localSupportedCertSignAlgs == null) {
shc.localSupportedCertSignAlgs =
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints, shc.activeProtocols,
CERTIFICATE_SCOPE);
}

if (shc.localSupportedSignAlgs == null ||
shc.localSupportedSignAlgs.isEmpty()) {
// According to TLSv1.2 RFC, CertificateRequest message must
// contain signature schemes supported for both:
// handshake signatures and certificate signatures.
List<SignatureScheme> certReqSignAlgs =
new ArrayList<>(shc.localSupportedSignAlgs);
certReqSignAlgs.retainAll(shc.localSupportedCertSignAlgs);

if (certReqSignAlgs == null ||
certReqSignAlgs.isEmpty()) {
throw shc.conContext.fatal(Alert.HANDSHAKE_FAILURE,
"No supported signature algorithm");
}
Expand All @@ -625,7 +644,7 @@ public byte[] produce(ConnectionContext context,
shc.sslContext.getX509TrustManager().getAcceptedIssuers();
T12CertificateRequestMessage crm = new T12CertificateRequestMessage(
shc, caCerts, shc.negotiatedCipherSuite.keyExchange,
shc.localSupportedSignAlgs);
certReqSignAlgs);
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
SSLLogger.fine(
"Produced CertificateRequest handshake message", crm);
Expand Down Expand Up @@ -706,19 +725,28 @@ public void consume(ConnectionContext context,
chc.handshakeProducers.put(SSLHandshake.CERTIFICATE.id,
SSLHandshake.CERTIFICATE);

List<SignatureScheme> sss =
List<SignatureScheme> signAlgs =
SignatureScheme.getSupportedAlgorithms(
chc.sslConfig,
chc.algorithmConstraints, chc.negotiatedProtocol,
crm.algorithmIds,
HANDSHAKE_SCOPE);

List<SignatureScheme> signCertAlgs =
SignatureScheme.getSupportedAlgorithms(
chc.sslConfig,
chc.algorithmConstraints, chc.negotiatedProtocol,
crm.algorithmIds);
if (sss == null || sss.isEmpty()) {
crm.algorithmIds,
CERTIFICATE_SCOPE);

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

chc.peerRequestedSignatureSchemes = sss;
chc.peerRequestedCertSignSchemes = sss; // use the same schemes
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(sss);
chc.peerRequestedSignatureSchemes = signAlgs;
chc.peerRequestedCertSignSchemes = signCertAlgs;
chc.handshakeSession.setPeerSupportedSignatureAlgorithms(signCertAlgs);
chc.peerSupportedAuthorities = crm.getAuthorities();

// For TLS 1.2, we need to use a combination of the CR message's
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -82,7 +82,7 @@ abstract class HandshakeContext implements ConnectionContext {
// consolidated parameters
final List<ProtocolVersion> activeProtocols;
final List<CipherSuite> activeCipherSuites;
final AlgorithmConstraints algorithmConstraints;
final SSLAlgorithmConstraints algorithmConstraints;
final ProtocolVersion maximumActiveProtocol;

// output stream
Expand Down Expand Up @@ -135,6 +135,7 @@ abstract class HandshakeContext implements ConnectionContext {

// SignatureScheme
List<SignatureScheme> localSupportedSignAlgs;
List<SignatureScheme> localSupportedCertSignAlgs;
List<SignatureScheme> peerRequestedSignatureSchemes;
List<SignatureScheme> peerRequestedCertSignSchemes;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -43,7 +43,7 @@ final class PostHandshakeContext extends HandshakeContext {
"Post-handshake not supported in " + negotiatedProtocol.name);
}

this.localSupportedSignAlgs = new ArrayList<>(
this.localSupportedCertSignAlgs = new ArrayList<>(
context.conSession.getLocalSupportedSignatureSchemes());

// Add the potential post-handshake consumers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -42,6 +42,7 @@
import sun.security.ssl.SSLExtension.SSLExtensionSpec;
import sun.security.ssl.SSLHandshake.HandshakeMessage;
import static sun.security.ssl.SSLExtension.*;
import static sun.security.ssl.SignatureScheme.CERTIFICATE_SCOPE;

/**
* Pack of the "pre_shared_key" extension.
Expand Down Expand Up @@ -414,15 +415,16 @@ private static boolean canRejoin(ClientHelloMessage clientHello,
result = false;
}

// Make sure that the server handshake context's localSupportedSignAlgs
// field is populated. This is particularly important when
// client authentication was used in an initial session and it is
// now being resumed.
if (shc.localSupportedSignAlgs == null) {
shc.localSupportedSignAlgs =
// Make sure that the server handshake context's
// localSupportedCertSignAlgs field is populated. This is particularly
// important when client authentication was used in an initial session,
// and it is now being resumed.
if (shc.localSupportedCertSignAlgs == null) {
shc.localSupportedCertSignAlgs =
SignatureScheme.getSupportedAlgorithms(
shc.sslConfig,
shc.algorithmConstraints, shc.activeProtocols);
shc.algorithmConstraints, shc.activeProtocols,
CERTIFICATE_SCOPE);
}

// Validate the required client authentication.
Expand All @@ -444,7 +446,7 @@ private static boolean canRejoin(ClientHelloMessage clientHello,
Collection<SignatureScheme> sessionSigAlgs =
s.getLocalSupportedSignatureSchemes();
if (result &&
!shc.localSupportedSignAlgs.containsAll(sessionSigAlgs)) {
!shc.localSupportedCertSignAlgs.containsAll(sessionSigAlgs)) {

if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
SSLLogger.fine("Can't resume. Session uses different " +
Expand Down Expand Up @@ -638,7 +640,7 @@ public byte[] produce(ConnectionContext context,
// Make sure the list of supported signature algorithms matches
Collection<SignatureScheme> sessionSigAlgs =
chc.resumingSession.getLocalSupportedSignatureSchemes();
if (!chc.localSupportedSignAlgs.containsAll(sessionSigAlgs)) {
if (!chc.localSupportedCertSignAlgs.containsAll(sessionSigAlgs)) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
SSLLogger.fine("Existing session uses different " +
"signature algorithms");
Expand Down
Loading