Skip to content

Commit 8676524

Browse files
committed
8340321: Disable SHA-1 in TLS/DTLS 1.2 handshake signatures
Backport-of: dfa79c373097d17a347b7c17103c57e12f59dc67
1 parent 2a2bc2c commit 8676524

File tree

5 files changed

+249
-3
lines changed

5 files changed

+249
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ enum SignatureScheme {
133133
"DSA",
134134
ProtocolVersion.PROTOCOLS_TO_12),
135135
ECDSA_SHA1 (0x0203, "ecdsa_sha1", "SHA1withECDSA",
136-
"EC",
137-
ProtocolVersion.PROTOCOLS_TO_13),
136+
"EC", null, null, -1,
137+
ProtocolVersion.PROTOCOLS_TO_13,
138+
ProtocolVersion.PROTOCOLS_TO_12),
138139
RSA_PKCS1_SHA1 (0x0201, "rsa_pkcs1_sha1", "SHA1withRSA",
139140
"RSA", null, null, 511,
140141
ProtocolVersion.PROTOCOLS_TO_13,

src/java.base/share/conf/security/java.security

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, \
761761
# rsa_pkcs1_sha1, secp224r1, TLS_RSA_*
762762
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, DTLSv1.0, RC4, DES, \
763763
MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
764-
ECDH, TLS_RSA_*
764+
ECDH, TLS_RSA_*, rsa_pkcs1_sha1 usage HandshakeSignature, \
765+
ecdsa_sha1 usage HandshakeSignature, dsa_sha1 usage HandshakeSignature
765766

766767
#
767768
# Legacy algorithms for Secure Socket Layer/Transport Layer Security (SSL/TLS)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8340321
27+
* @summary Disable SHA-1 in TLS/DTLS 1.2 signatures.
28+
* This test only covers DTLS 1.2.
29+
* @library /javax/net/ssl/templates
30+
* /test/lib
31+
* @run main/othervm DisableSHA1inHandshakeSignatureDTLS12
32+
*/
33+
34+
public class DisableSHA1inHandshakeSignatureDTLS12 extends
35+
DisableSHA1inHandshakeSignatureTLS12 {
36+
37+
protected DisableSHA1inHandshakeSignatureDTLS12() throws Exception {
38+
super();
39+
}
40+
41+
public static void main(String[] args) throws Exception {
42+
new DisableSHA1inHandshakeSignatureDTLS12().run();
43+
}
44+
45+
@Override
46+
protected String getProtocol() {
47+
return "DTLSv1.2";
48+
}
49+
50+
// No CertificateRequest in DTLS server flight.
51+
@Override
52+
protected void checkCertificateRequest() {
53+
}
54+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8340321
27+
* @summary Disable SHA-1 in TLS/DTLS 1.2 signatures.
28+
* This test only covers TLS 1.2.
29+
* @library /javax/net/ssl/templates
30+
* /test/lib
31+
* @run main/othervm DisableSHA1inHandshakeSignatureTLS12
32+
*/
33+
34+
import static jdk.test.lib.Asserts.assertFalse;
35+
import static jdk.test.lib.Asserts.assertTrue;
36+
37+
import java.util.List;
38+
39+
public class DisableSHA1inHandshakeSignatureTLS12 extends
40+
AbstractCheckSignatureSchemes {
41+
42+
protected DisableSHA1inHandshakeSignatureTLS12() throws Exception {
43+
super();
44+
}
45+
46+
public static void main(String[] args) throws Exception {
47+
new DisableSHA1inHandshakeSignatureTLS12().run();
48+
}
49+
50+
@Override
51+
protected String getProtocol() {
52+
return "TLSv1.2";
53+
}
54+
55+
// Run things in TLS handshake order.
56+
protected void run() throws Exception {
57+
58+
// Produce client_hello
59+
clientEngine.wrap(clientOut, cTOs);
60+
cTOs.flip();
61+
62+
checkClientHello();
63+
64+
// Consume client_hello.
65+
serverEngine.unwrap(cTOs, serverIn);
66+
runDelegatedTasks(serverEngine);
67+
68+
// Produce server_hello.
69+
serverEngine.wrap(serverOut, sTOc);
70+
sTOc.flip();
71+
72+
checkCertificateRequest();
73+
}
74+
75+
// Returns SHA-1 signature schemes supported for TLSv1.2 handshake
76+
protected List<String> getDisabledSignatureSchemes() {
77+
return List.of(
78+
"ecdsa_sha1",
79+
"rsa_pkcs1_sha1",
80+
"dsa_sha1"
81+
);
82+
}
83+
84+
protected void checkClientHello() throws Exception {
85+
// Get signature_algorithms extension signature schemes.
86+
List<String> sigAlgsSS = getSigSchemesCliHello(
87+
extractHandshakeMsg(cTOs, TLS_HS_CLI_HELLO),
88+
SIG_ALGS_EXT);
89+
90+
// Should not be present in signature_algorithms extension.
91+
getDisabledSignatureSchemes().forEach(ss ->
92+
assertFalse(sigAlgsSS.contains(ss),
93+
"Signature Scheme " + ss
94+
+ " present in ClientHello's signature_algorithms extension"));
95+
96+
// Get signature_algorithms_cert extension signature schemes.
97+
List<String> sigAlgsCertSS = getSigSchemesCliHello(
98+
extractHandshakeMsg(cTOs, TLS_HS_CLI_HELLO),
99+
SIG_ALGS_CERT_EXT);
100+
101+
// Should be present in signature_algorithms_cert extension.
102+
getDisabledSignatureSchemes().forEach(ss ->
103+
assertTrue(sigAlgsCertSS.contains(ss),
104+
"Signature Scheme " + ss
105+
+ " isn't present in ClientHello's"
106+
+ " signature_algorithms extension"));
107+
}
108+
109+
protected void checkCertificateRequest() throws Exception {
110+
// Get CertificateRequest message signature schemes.
111+
List<String> sigAlgsCertSS = getSigSchemesCertReq(
112+
extractHandshakeMsg(sTOc, TLS_HS_CERT_REQ));
113+
114+
// Should not be present in CertificateRequest message.
115+
getDisabledSignatureSchemes().forEach(ss ->
116+
assertFalse(sigAlgsCertSS.contains(ss),
117+
"Signature Scheme " + ss
118+
+ " present in CertificateRequest"));
119+
}
120+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8340321
27+
* @summary Disable SHA-1 in TLS/DTLS 1.2 signatures.
28+
* This test only covers TLS 1.3.
29+
* @library /javax/net/ssl/templates
30+
* /test/lib
31+
* @run main/othervm DisableSHA1inHandshakeSignatureTLS13
32+
*/
33+
34+
import java.security.Security;
35+
import java.util.List;
36+
37+
public class DisableSHA1inHandshakeSignatureTLS13 extends
38+
DisableSHA1inHandshakeSignatureTLS12 {
39+
40+
protected DisableSHA1inHandshakeSignatureTLS13() throws Exception {
41+
super();
42+
}
43+
44+
public static void main(String[] args) throws Exception {
45+
// SHA-1 algorithm MUST NOT be used in any TLSv1.3 handshake signatures.
46+
// This is regardless of jdk.tls.disabledAlgorithms configuration.
47+
Security.setProperty("jdk.tls.disabledAlgorithms", "");
48+
new DisableSHA1inHandshakeSignatureTLS13().run();
49+
}
50+
51+
@Override
52+
protected String getProtocol() {
53+
return "TLSv1.3";
54+
}
55+
56+
// Returns SHA-1 signature schemes NOT supported for TLSv1.3 handshake
57+
// signatures, but supported for TLSv1.3 certificate signatures.
58+
@Override
59+
protected List<String> getDisabledSignatureSchemes() {
60+
return List.of("ecdsa_sha1", "rsa_pkcs1_sha1");
61+
}
62+
63+
// TLSv1.3 sends CertificateRequest signature schemes in
64+
// signature_algorithms and signature_algorithms_cert extensions. Same as
65+
// ClientHello, but they are encrypted. So we skip CertificateRequest
66+
// signature schemes verification for TLSv1.3.
67+
@Override
68+
protected void checkCertificateRequest() {
69+
}
70+
}

0 commit comments

Comments
 (0)