Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/sanity/ciphersuites/SystemPropCipherSuitesOrder.java
41154 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 set through System properties
36
* @run main/othervm
37
* -Djdk.tls.client.cipherSuites=TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384
38
* -Djdk.tls.server.cipherSuites=TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA256
39
* SystemPropCipherSuitesOrder TLSv1.3
40
* @run main/othervm
41
* -Djdk.tls.client.cipherSuites=TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384
42
* SystemPropCipherSuitesOrder TLSv1.3
43
* @run main/othervm
44
* -Djdk.tls.server.cipherSuites=TLS_AES_128_GCM_SHA256,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_256_GCM_SHA384
45
* SystemPropCipherSuitesOrder TLSv1.3
46
* @run main/othervm
47
* -Djdk.tls.client.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
48
* -Djdk.tls.server.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
49
* SystemPropCipherSuitesOrder TLSv1.2
50
* @run main/othervm
51
* -Djdk.tls.client.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
52
* SystemPropCipherSuitesOrder TLSv1.2
53
* @run main/othervm
54
* -Djdk.tls.server.cipherSuites=TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
55
* SystemPropCipherSuitesOrder TLSv1.2
56
* @run main/othervm
57
* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
58
* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
59
* SystemPropCipherSuitesOrder TLSv1.1
60
* @run main/othervm
61
* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
62
* SystemPropCipherSuitesOrder TLSv1.1
63
* @run main/othervm
64
* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
65
* SystemPropCipherSuitesOrder TLSv1.1
66
* @run main/othervm
67
* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
68
* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
69
* SystemPropCipherSuitesOrder TLSv1
70
* @run main/othervm
71
* -Djdk.tls.client.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
72
* SystemPropCipherSuitesOrder TLSv1
73
* @run main/othervm
74
* -Djdk.tls.server.cipherSuites=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
75
* SystemPropCipherSuitesOrder TLSv1
76
*/
77
public class SystemPropCipherSuitesOrder extends SSLSocketTemplate {
78
79
private final String protocol;
80
private static String[] servercipherSuites;
81
private static String[] clientcipherSuites;
82
83
public static void main(String[] args) {
84
servercipherSuites
85
= toArray(System.getProperty("jdk.tls.server.cipherSuites"));
86
clientcipherSuites
87
= toArray(System.getProperty("jdk.tls.client.cipherSuites"));
88
System.out.printf("SYSTEM PROPERTIES: ServerProp:%s - ClientProp:%s%n",
89
Arrays.deepToString(servercipherSuites),
90
Arrays.deepToString(clientcipherSuites));
91
92
try {
93
new SystemPropCipherSuitesOrder(args[0]).run();
94
} catch (Exception e) {
95
throw new RuntimeException(e);
96
}
97
}
98
99
private SystemPropCipherSuitesOrder(String protocol) {
100
this.protocol = protocol;
101
// Re-enable protocol if disabled.
102
if (protocol.equals("TLSv1") || protocol.equals("TLSv1.1")) {
103
SecurityUtils.removeFromDisabledTlsAlgs(protocol);
104
}
105
}
106
107
// Servers are configured before clients, increment test case after.
108
@Override
109
protected void configureClientSocket(SSLSocket socket) {
110
socket.setEnabledProtocols(new String[]{protocol});
111
}
112
113
@Override
114
protected void configureServerSocket(SSLServerSocket serverSocket) {
115
serverSocket.setEnabledProtocols(new String[]{protocol});
116
}
117
118
protected void runServerApplication(SSLSocket socket) throws Exception {
119
if (servercipherSuites != null) {
120
System.out.printf("SERVER: SystemProperty:%s - "
121
+ "getEnabledCipherSuites:%s%n",
122
Arrays.deepToString(servercipherSuites),
123
Arrays.deepToString(socket.getEnabledCipherSuites()));
124
}
125
if (servercipherSuites != null && !Arrays.equals(
126
servercipherSuites, socket.getEnabledCipherSuites())) {
127
throw new RuntimeException("Unmatched server side CipherSuite order");
128
}
129
super.runServerApplication(socket);
130
}
131
132
protected void runClientApplication(SSLSocket socket) throws Exception {
133
if (clientcipherSuites != null) {
134
System.out.printf("CLIENT: SystemProperty:%s - "
135
+ "getEnabledCipherSuites:%s%n",
136
Arrays.deepToString(clientcipherSuites),
137
Arrays.deepToString(socket.getEnabledCipherSuites()));
138
}
139
if (clientcipherSuites != null && !Arrays.equals(clientcipherSuites,
140
socket.getEnabledCipherSuites())) {
141
throw new RuntimeException("Unmatched client side CipherSuite order");
142
}
143
super.runClientApplication(socket);
144
}
145
146
private static String[] toArray(String prop) {
147
return (prop != null) ? prop.split(",") : null;
148
}
149
}
150
151