Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/sanity/ciphersuites/TLSCipherSuitesOrder.java
41155 views
1
/*
2
* Copyright (c) 2019, 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
import java.util.Arrays;
24
import javax.net.ssl.SSLServerSocket;
25
import javax.net.ssl.SSLSocket;
26
27
import jdk.test.lib.security.SecurityUtils;
28
29
/*
30
* @test
31
* @bug 8234728
32
* @library /javax/net/ssl/templates
33
* /javax/net/ssl/TLSCommon
34
* /test/lib
35
* @summary Test TLS ciphersuites order.
36
* Parameter order: <protocol> <client cipher order> <server cipher order>
37
* @run main/othervm TLSCipherSuitesOrder TLSv13 ORDERED default
38
* @run main/othervm TLSCipherSuitesOrder TLSv13 UNORDERED default
39
* @run main/othervm TLSCipherSuitesOrder TLSv13 UNORDERED UNORDERED
40
* @run main/othervm TLSCipherSuitesOrder TLSv13 ORDERED ORDERED
41
* @run main/othervm TLSCipherSuitesOrder TLSv12 ORDERED default
42
* @run main/othervm TLSCipherSuitesOrder TLSv12 UNORDERED default
43
* @run main/othervm TLSCipherSuitesOrder TLSv12 UNORDERED UNORDERED
44
* @run main/othervm TLSCipherSuitesOrder TLSv12 ORDERED ORDERED
45
* @run main/othervm TLSCipherSuitesOrder TLSv11 ORDERED default
46
* @run main/othervm TLSCipherSuitesOrder TLSv11 UNORDERED default
47
* @run main/othervm TLSCipherSuitesOrder TLSv11 UNORDERED UNORDERED
48
* @run main/othervm TLSCipherSuitesOrder TLSv11 ORDERED ORDERED
49
* @run main/othervm TLSCipherSuitesOrder TLSv1 ORDERED default
50
* @run main/othervm TLSCipherSuitesOrder TLSv1 UNORDERED default
51
* @run main/othervm TLSCipherSuitesOrder TLSv1 UNORDERED UNORDERED
52
* @run main/othervm TLSCipherSuitesOrder TLSv1 ORDERED ORDERED
53
*/
54
public class TLSCipherSuitesOrder extends SSLSocketTemplate {
55
56
private final String protocol;
57
private final String[] servercipherSuites;
58
private final String[] clientcipherSuites;
59
60
public static void main(String[] args) {
61
PROTOCOL protocol = PROTOCOL.valueOf(args[0]);
62
try {
63
new TLSCipherSuitesOrder(protocol.getProtocol(),
64
protocol.getCipherSuite(args[1]),
65
protocol.getCipherSuite(args[2])).run();
66
} catch (Exception e) {
67
throw new RuntimeException(e);
68
}
69
}
70
71
private TLSCipherSuitesOrder(String protocol, String[] clientcipherSuites,
72
String[] servercipherSuites) {
73
// Re-enable protocol if it is disabled.
74
if (protocol.equals("TLSv1") || protocol.equals("TLSv1.1")) {
75
SecurityUtils.removeFromDisabledTlsAlgs(protocol);
76
}
77
this.protocol = protocol;
78
this.clientcipherSuites = clientcipherSuites;
79
this.servercipherSuites = servercipherSuites;
80
}
81
82
// Servers are configured before clients, increment test case after.
83
@Override
84
protected void configureClientSocket(SSLSocket socket) {
85
socket.setEnabledProtocols(new String[]{protocol});
86
if (clientcipherSuites != null) {
87
socket.setEnabledCipherSuites(clientcipherSuites);
88
}
89
}
90
91
@Override
92
protected void configureServerSocket(SSLServerSocket serverSocket) {
93
serverSocket.setEnabledProtocols(new String[]{protocol});
94
if (servercipherSuites != null) {
95
serverSocket.setEnabledCipherSuites(servercipherSuites);
96
}
97
}
98
99
protected void runServerApplication(SSLSocket socket) throws Exception {
100
if (servercipherSuites != null) {
101
System.out.printf("SERVER: setEnabledCipherSuites:%s - "
102
+ "getEnabledCipherSuites:%s%n",
103
Arrays.deepToString(servercipherSuites),
104
Arrays.deepToString(socket.getEnabledCipherSuites()));
105
}
106
if (servercipherSuites != null && !Arrays.equals(servercipherSuites,
107
socket.getEnabledCipherSuites())) {
108
throw new RuntimeException("Unmatched server side CipherSuite order");
109
}
110
super.runServerApplication(socket);
111
}
112
113
protected void runClientApplication(SSLSocket socket) throws Exception {
114
if (clientcipherSuites != null) {
115
System.out.printf("CLIENT: setEnabledCipherSuites:%s - "
116
+ "getEnabledCipherSuites:%s%n",
117
Arrays.deepToString(clientcipherSuites),
118
Arrays.deepToString(socket.getEnabledCipherSuites()));
119
}
120
if (clientcipherSuites != null && !Arrays.equals(
121
clientcipherSuites, socket.getEnabledCipherSuites())) {
122
throw new RuntimeException("Unmatched client side CipherSuite order");
123
}
124
super.runClientApplication(socket);
125
}
126
127
enum PROTOCOL {
128
TLSv13("TLSv1.3",
129
new String[]{
130
"TLS_AES_256_GCM_SHA384",
131
"TLS_AES_128_GCM_SHA256",
132
"TLS_CHACHA20_POLY1305_SHA256"},
133
new String[]{"TLS_CHACHA20_POLY1305_SHA256",
134
"TLS_AES_128_GCM_SHA256",
135
"TLS_AES_256_GCM_SHA384"}),
136
TLSv12("TLSv1.2",
137
new String[]{
138
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
139
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
140
new String[]{
141
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
142
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"}),
143
TLSv11("TLSv1.1",
144
new String[]{
145
"TLS_RSA_WITH_AES_256_CBC_SHA",
146
"TLS_RSA_WITH_AES_128_CBC_SHA"},
147
new String[]{
148
"TLS_RSA_WITH_AES_128_CBC_SHA",
149
"TLS_RSA_WITH_AES_256_CBC_SHA"}),
150
TLSv1("TLSv1",
151
new String[]{
152
"TLS_RSA_WITH_AES_256_CBC_SHA",
153
"TLS_RSA_WITH_AES_128_CBC_SHA"},
154
new String[]{
155
"TLS_RSA_WITH_AES_128_CBC_SHA",
156
"TLS_RSA_WITH_AES_256_CBC_SHA"});
157
158
String protocol;
159
String[] orderedCiphers;
160
String[] unOrderedCiphers;
161
162
private PROTOCOL(String protocol, String[] orderedCiphers,
163
String[] unOrderedCiphers) {
164
this.protocol = protocol;
165
this.orderedCiphers = orderedCiphers;
166
this.unOrderedCiphers = unOrderedCiphers;
167
}
168
169
public String getProtocol() {
170
return protocol;
171
}
172
173
public String[] getOrderedCiphers() {
174
return orderedCiphers;
175
}
176
177
public String[] getUnOrderedCiphers() {
178
return unOrderedCiphers;
179
}
180
181
public String[] getCipherSuite(String order) {
182
switch (order) {
183
case "ORDERED":
184
return getOrderedCiphers();
185
case "UNORDERED":
186
return getUnOrderedCiphers();
187
default:
188
return null;
189
}
190
}
191
}
192
}
193
194