Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit fb37c54

Browse files
committedFeb 20, 2020
8238560: Cleanup and consolidate algorithms in the jdk.tls.legacyAlgorithms security property
Reviewed-by: xuelei
1 parent f40220f commit fb37c54

File tree

2 files changed

+111
-5
lines changed

2 files changed

+111
-5
lines changed
 

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,7 @@ jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, \
796796
# Example:
797797
# jdk.tls.legacyAlgorithms=DH_anon, DES_CBC, SSL_RSA_WITH_RC4_128_MD5
798798
#
799-
jdk.tls.legacyAlgorithms= \
800-
K_NULL, C_NULL, M_NULL, \
801-
DH_anon, ECDH_anon, \
802-
RC4_128, RC4_40, DES_CBC, DES40_CBC, \
803-
3DES_EDE_CBC
799+
jdk.tls.legacyAlgorithms=NULL, anon, RC4, DES, 3DES_EDE_CBC
804800

805801
#
806802
# The pre-defined default finite field Diffie-Hellman ephemeral (DHE)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2020, 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 8238560
27+
* @library /javax/net/ssl/templates
28+
* @summary Make sure that legacy suites are not selected if stronger choices
29+
* are available
30+
* @run main/othervm LegacyConstraints
31+
*/
32+
33+
import java.io.InputStream;
34+
import java.io.OutputStream;
35+
import java.security.Security;
36+
import java.util.Arrays;
37+
import java.util.ArrayList;
38+
import java.util.List;
39+
import javax.net.ssl.SSLSocket;
40+
41+
public class LegacyConstraints extends SSLSocketTemplate {
42+
43+
// none of the legacy suites are supported in TLS 1.3, so don't
44+
// test TLS 1.3
45+
private final static List<String> TLS_PROTOCOLS = List.of(
46+
"TLSv1", "TLSv1.1", "TLSv1.2");
47+
48+
// cipher suites that contain legacy algorithms
49+
private final static List<String> LEGACY_SUITES = List.of(
50+
"TLS_RSA_WITH_NULL_SHA256",
51+
"TLS_DH_anon_WITH_AES_128_CBC_SHA",
52+
"TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
53+
"TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
54+
"TLS_RSA_WITH_DES_CBC_SHA",
55+
"TLS_RSA_WITH_3DES_EDE_CBC_SHA");
56+
57+
private static String protocol;
58+
59+
public static void main(String[] args) throws Exception {
60+
// Clear disabled algorithms so that it doesn't interfere
61+
// with legacy suites
62+
Security.setProperty("jdk.tls.disabledAlgorithms", "");
63+
for (String tlsProtocol : TLS_PROTOCOLS) {
64+
protocol = tlsProtocol;
65+
System.out.println("Testing " + protocol);
66+
new LegacyConstraints().run();
67+
}
68+
}
69+
70+
/**
71+
* Prepends legacy suites to the array of enabled suites.
72+
*/
73+
private static void configureSocket(SSLSocket socket) {
74+
socket.setEnabledProtocols(new String[] {protocol});
75+
List<String> newSuites = new ArrayList(LEGACY_SUITES);
76+
Arrays.stream(socket.getEnabledCipherSuites())
77+
.forEachOrdered(suite -> newSuites.add(suite));
78+
socket.setEnabledCipherSuites(newSuites.toArray(new String[0]));
79+
}
80+
81+
@Override
82+
protected void runServerApplication(SSLSocket socket) throws Exception {
83+
configureSocket(socket);
84+
85+
InputStream sslIS = socket.getInputStream();
86+
OutputStream sslOS = socket.getOutputStream();
87+
88+
sslIS.read();
89+
sslOS.write(85);
90+
sslOS.flush();
91+
92+
String negotiatedSuite = socket.getSession().getCipherSuite();
93+
if (LEGACY_SUITES.contains(negotiatedSuite)) {
94+
throw new Exception("Test FAILED: the negotiated suite " +
95+
negotiatedSuite + " is a legacy suite");
96+
}
97+
}
98+
99+
@Override
100+
protected void runClientApplication(SSLSocket socket) throws Exception {
101+
configureSocket(socket);
102+
103+
InputStream sslIS = socket.getInputStream();
104+
OutputStream sslOS = socket.getOutputStream();
105+
106+
sslOS.write(280);
107+
sslOS.flush();
108+
sslIS.read();
109+
}
110+
}

0 commit comments

Comments
 (0)