Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/CipherSuite/LegacyConstraints.java
41152 views
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
}
111
112