Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/sanity/ciphersuites/CipherSuitesInOrder.java
41154 views
1
/*
2
* Copyright (c) 2012, 2019, 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
// SunJSSE does not support dynamic system properties, no way to re-use
26
// system properties in samevm/agentvm mode.
27
//
28
29
/*
30
* @test
31
* @bug 7174244 8234728
32
* @summary Test for ciphersuites order
33
* @run main/othervm CipherSuitesInOrder
34
*/
35
import java.util.*;
36
import javax.net.ssl.*;
37
38
public class CipherSuitesInOrder {
39
40
// Supported ciphersuites
41
private final static List<String> supportedCipherSuites
42
= Arrays.<String>asList(
43
// TLS 1.3 cipher suites.
44
"TLS_AES_256_GCM_SHA384",
45
"TLS_AES_128_GCM_SHA256",
46
"TLS_CHACHA20_POLY1305_SHA256",
47
// Suite B compliant cipher suites, see RFC 6460.
48
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
49
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
50
// Not suite B, but we want it to position the suite early
51
//in the list of 1.2 suites.
52
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
53
//
54
// Forward secrecy cipher suites.
55
//
56
// AES_256(GCM) - ECDHE
57
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
58
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
59
// AES_128(GCM) - ECDHE
60
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
61
// AES_256(GCM) - DHE
62
"TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
63
"TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
64
"TLS_DHE_DSS_WITH_AES_256_GCM_SHA384",
65
// AES_128(GCM) - DHE
66
"TLS_DHE_RSA_WITH_AES_128_GCM_SHA256",
67
"TLS_DHE_DSS_WITH_AES_128_GCM_SHA256",
68
// AES_256(CBC) - ECDHE
69
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
70
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
71
// AES_128(CBC) - ECDHE
72
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
73
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
74
// AES_256(CBC) - DHE
75
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
76
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA256",
77
// AES_128(CBC) - DHE
78
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
79
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
80
//
81
// Not forward secret cipher suites.
82
//
83
// AES_256(GCM)
84
"TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384",
85
"TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384",
86
// AES_128(GCM)
87
"TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
88
"TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256",
89
// AES_256(CBC)
90
"TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384",
91
"TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
92
// AES_128(CBC)
93
"TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256",
94
"TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
95
//
96
// Legacy, used for compatibility
97
//
98
// AES_256(CBC) - ECDHE - Using SHA
99
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
100
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
101
// AES_128(CBC) - ECDHE - using SHA
102
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
103
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
104
// AES_256(CBC) - DHE - Using SHA
105
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
106
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
107
// AES_128(CBC) - DHE - using SHA
108
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
109
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
110
// AES_256(CBC) - using SHA, not forward secrecy
111
"TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
112
"TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
113
// AES_128(CBC) - using SHA, not forward secrecy
114
"TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
115
"TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
116
//
117
// Deprecated, used for compatibility
118
//
119
// RSA, AES_256(GCM)
120
"TLS_RSA_WITH_AES_256_GCM_SHA384",
121
// RSA, AES_128(GCM)
122
"TLS_RSA_WITH_AES_128_GCM_SHA256",
123
// RSA, AES_256(CBC)
124
"TLS_RSA_WITH_AES_256_CBC_SHA256",
125
// RSA, AES_128(CBC)
126
"TLS_RSA_WITH_AES_128_CBC_SHA256",
127
// RSA, AES_256(CBC) - using SHA, not forward secrecy
128
"TLS_RSA_WITH_AES_256_CBC_SHA",
129
// RSA, AES_128(CBC) - using SHA, not forward secrecy
130
"TLS_RSA_WITH_AES_128_CBC_SHA",
131
// 3DES_EDE, forward secrecy.
132
"TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
133
"TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
134
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
135
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
136
// 3DES_EDE, not forward secrecy.
137
"TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
138
"TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
139
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
140
// Renegotiation protection request Signalling
141
// Cipher Suite Value (SCSV).
142
"TLS_EMPTY_RENEGOTIATION_INFO_SCSV",
143
// Definition of the Cipher Suites that are supported but not
144
// enabled by default.
145
"TLS_DH_anon_WITH_AES_256_GCM_SHA384",
146
"TLS_DH_anon_WITH_AES_128_GCM_SHA256",
147
"TLS_DH_anon_WITH_AES_256_CBC_SHA256",
148
"TLS_ECDH_anon_WITH_AES_256_CBC_SHA",
149
"TLS_DH_anon_WITH_AES_256_CBC_SHA",
150
"TLS_DH_anon_WITH_AES_128_CBC_SHA256",
151
"TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
152
"TLS_DH_anon_WITH_AES_128_CBC_SHA",
153
"TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA",
154
"SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
155
// RC4
156
"TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
157
"TLS_ECDHE_RSA_WITH_RC4_128_SHA",
158
"SSL_RSA_WITH_RC4_128_SHA",
159
"TLS_ECDH_ECDSA_WITH_RC4_128_SHA",
160
"TLS_ECDH_RSA_WITH_RC4_128_SHA",
161
"SSL_RSA_WITH_RC4_128_MD5",
162
"TLS_ECDH_anon_WITH_RC4_128_SHA",
163
"SSL_DH_anon_WITH_RC4_128_MD5",
164
// Weak cipher suites obsoleted in TLS 1.2 [RFC 5246]
165
"SSL_RSA_WITH_DES_CBC_SHA",
166
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
167
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
168
"SSL_DH_anon_WITH_DES_CBC_SHA",
169
// Weak cipher suites obsoleted in TLS 1.1 [RFC 4346]
170
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
171
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
172
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
173
"SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
174
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
175
"SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
176
// No traffic encryption cipher suites
177
"TLS_RSA_WITH_NULL_SHA256",
178
"TLS_ECDHE_ECDSA_WITH_NULL_SHA",
179
"TLS_ECDHE_RSA_WITH_NULL_SHA",
180
"SSL_RSA_WITH_NULL_SHA",
181
"TLS_ECDH_ECDSA_WITH_NULL_SHA",
182
"TLS_ECDH_RSA_WITH_NULL_SHA",
183
"TLS_ECDH_anon_WITH_NULL_SHA",
184
"SSL_RSA_WITH_NULL_MD5",
185
// Definition of the cipher suites that are not supported but the names
186
// are known.
187
"TLS_AES_128_CCM_SHA256",
188
"TLS_AES_128_CCM_8_SHA256"
189
);
190
191
private final static String[] protocols = {
192
"", "SSL", "TLS", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"
193
};
194
195
public static void main(String[] args) throws Exception {
196
// show all of the supported cipher suites
197
showSuites(supportedCipherSuites.toArray(new String[0]),
198
"All supported cipher suites");
199
200
for (String protocol : protocols) {
201
System.out.println("//");
202
System.out.println("// "
203
+ "Testing for SSLContext of " + protocol);
204
System.out.println("//");
205
checkForProtocols(protocol);
206
}
207
}
208
209
public static void checkForProtocols(String protocol) throws Exception {
210
SSLContext context;
211
if (protocol.isEmpty()) {
212
context = SSLContext.getDefault();
213
} else {
214
context = SSLContext.getInstance(protocol);
215
context.init(null, null, null);
216
}
217
218
// check the order of default cipher suites of SSLContext
219
SSLParameters parameters = context.getDefaultSSLParameters();
220
checkSuites(parameters.getCipherSuites(),
221
"Default cipher suites in SSLContext");
222
223
// check the order of supported cipher suites of SSLContext
224
parameters = context.getSupportedSSLParameters();
225
checkSuites(parameters.getCipherSuites(),
226
"Supported cipher suites in SSLContext");
227
228
//
229
// Check the cipher suites order of SSLEngine
230
//
231
SSLEngine engine = context.createSSLEngine();
232
233
// check the order of endabled cipher suites
234
String[] ciphers = engine.getEnabledCipherSuites();
235
checkSuites(ciphers,
236
"Enabled cipher suites in SSLEngine");
237
238
// check the order of supported cipher suites
239
ciphers = engine.getSupportedCipherSuites();
240
checkSuites(ciphers,
241
"Supported cipher suites in SSLEngine");
242
243
//
244
// Check the cipher suites order of SSLSocket
245
//
246
SSLSocketFactory factory = context.getSocketFactory();
247
try (SSLSocket socket = (SSLSocket) factory.createSocket()) {
248
249
// check the order of endabled cipher suites
250
ciphers = socket.getEnabledCipherSuites();
251
checkSuites(ciphers,
252
"Enabled cipher suites in SSLSocket");
253
254
// check the order of supported cipher suites
255
ciphers = socket.getSupportedCipherSuites();
256
checkSuites(ciphers,
257
"Supported cipher suites in SSLSocket");
258
}
259
260
//
261
// Check the cipher suites order of SSLServerSocket
262
//
263
SSLServerSocketFactory serverFactory = context.getServerSocketFactory();
264
try (SSLServerSocket serverSocket
265
= (SSLServerSocket) serverFactory.createServerSocket()) {
266
// check the order of endabled cipher suites
267
ciphers = serverSocket.getEnabledCipherSuites();
268
checkSuites(ciphers,
269
"Enabled cipher suites in SSLServerSocket");
270
271
// check the order of supported cipher suites
272
ciphers = serverSocket.getSupportedCipherSuites();
273
checkSuites(ciphers,
274
"Supported cipher suites in SSLServerSocket");
275
}
276
}
277
278
private static void checkSuites(String[] suites, String title) {
279
showSuites(suites, title);
280
281
int loc = -1;
282
int index = 0;
283
for (String suite : suites) {
284
index = supportedCipherSuites.indexOf(suite);
285
if (index <= loc) {
286
throw new RuntimeException(suite + " is not in order");
287
}
288
loc = index;
289
}
290
}
291
292
private static void showSuites(String[] suites, String title) {
293
System.out.println(title + "[" + suites.length + "]:");
294
for (String suite : suites) {
295
System.out.println(" " + suite);
296
}
297
}
298
}
299
300