Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLContextImpl/DefaultCipherSuitePreference.java
41152 views
1
/*
2
* Copyright (c) 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
// SunJSSE does not support dynamic system properties, no way to re-use
25
// system properties in samevm/agentvm mode.
26
27
/*
28
* @test
29
* @bug 8168261
30
* @summary Use server cipher suites preference by default
31
* @run main/othervm DefaultCipherSuitePreference
32
*/
33
34
import javax.net.SocketFactory;
35
import javax.net.ssl.KeyManager;
36
import javax.net.ssl.SSLContext;
37
import javax.net.ssl.SSLEngine;
38
import javax.net.ssl.SSLParameters;
39
import javax.net.ssl.SSLServerSocket;
40
import javax.net.ssl.SSLServerSocketFactory;
41
import javax.net.ssl.SSLSocket;
42
import javax.net.ssl.TrustManager;
43
44
public class DefaultCipherSuitePreference {
45
private static final String[] contextAlgorithms = {
46
"Default", "SSL", "TLS", "SSLv3", "TLSv1",
47
"TLSv1.1", "TLSv1.2", "TLSv1.3"
48
};
49
50
public static void main(String[] args) throws Exception {
51
for (String algorithm : contextAlgorithms) {
52
System.out.println("Checking SSLContext of " + algorithm);
53
SSLContext sslContext = SSLContext.getInstance(algorithm);
54
55
// Default SSLContext is initialized automatically.
56
if (!algorithm.equals("Default")) {
57
// Use default TK, KM and random.
58
sslContext.init((KeyManager[])null, (TrustManager[])null, null);
59
}
60
61
//
62
// Check SSLContext
63
//
64
// Check default SSLParameters of SSLContext
65
checkDefaultCipherSuitePreference(
66
sslContext.getDefaultSSLParameters(),
67
"SSLContext.getDefaultSSLParameters()");
68
69
// Check supported SSLParameters of SSLContext
70
checkDefaultCipherSuitePreference(
71
sslContext.getSupportedSSLParameters(),
72
"SSLContext.getSupportedSSLParameters()");
73
74
//
75
// Check SSLEngine
76
//
77
// Check SSLParameters of SSLEngine
78
SSLEngine engine = sslContext.createSSLEngine();
79
engine.setUseClientMode(true);
80
checkDefaultCipherSuitePreference(
81
engine.getSSLParameters(),
82
"client mode SSLEngine.getSSLParameters()");
83
84
engine.setUseClientMode(false);
85
checkDefaultCipherSuitePreference(
86
engine.getSSLParameters(),
87
"server mode SSLEngine.getSSLParameters()");
88
89
//
90
// Check SSLSocket
91
//
92
// Check SSLParameters of SSLSocket
93
SocketFactory fac = sslContext.getSocketFactory();
94
SSLSocket socket = (SSLSocket)fac.createSocket();
95
checkDefaultCipherSuitePreference(
96
socket.getSSLParameters(),
97
"SSLSocket.getSSLParameters()");
98
99
//
100
// Check SSLServerSocket
101
//
102
// Check SSLParameters of SSLServerSocket
103
SSLServerSocketFactory sf = sslContext.getServerSocketFactory();
104
SSLServerSocket ssocket = (SSLServerSocket)sf.createServerSocket();
105
checkDefaultCipherSuitePreference(
106
ssocket.getSSLParameters(),
107
"SSLServerSocket.getSSLParameters()");
108
}
109
}
110
111
private static void checkDefaultCipherSuitePreference(
112
SSLParameters parameters, String context) throws Exception {
113
if (!parameters.getUseCipherSuitesOrder()) {
114
throw new Exception(
115
"The local cipher suite preference is not honored " +
116
"in the connection populated SSLParameters object (" +
117
context + ")");
118
}
119
}
120
}
121
122