Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLContextImpl/SSLContextVersion.java
41152 views
1
/*
2
* Copyright (c) 2011, 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
// 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 6976117 8234725
30
* @summary SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets
31
* without TLSv1.1 enabled
32
* @library /test/lib
33
* @run main/othervm SSLContextVersion
34
*/
35
36
import javax.net.ssl.*;
37
38
import jdk.test.lib.security.SecurityUtils;
39
40
public class SSLContextVersion {
41
static enum ContextVersion {
42
TLS_CV_01("SSL", "TLSv1.2", "TLSv1.2"),
43
TLS_CV_02("TLS", "TLSv1.2", "TLSv1.2"),
44
TLS_CV_03("SSLv3", "TLSv1", "TLSv1.2"),
45
TLS_CV_04("TLSv1", "TLSv1", "TLSv1.2"),
46
TLS_CV_05("TLSv1.1", "TLSv1.1", "TLSv1.2"),
47
TLS_CV_06("TLSv1.2", "TLSv1.2", "TLSv1.2"),
48
TLS_CV_07("Default", "TLSv1.2", "TLSv1.2"),
49
TLS_CV_08("Default", "TLSv1.3", "TLSv1.3"),
50
TLS_CV_09("TLS", "TLSv1.3", "TLSv1.3"),
51
TLS_CV_10("TLSv1.3", "TLSv1.3", "TLSv1.3");
52
53
final String contextVersion;
54
final String defaultProtocolVersion;
55
final String supportedProtocolVersion;
56
57
ContextVersion(String contextVersion, String defaultProtocolVersion,
58
String supportedProtocolVersion) {
59
this.contextVersion = contextVersion;
60
this.defaultProtocolVersion = defaultProtocolVersion;
61
this.supportedProtocolVersion = supportedProtocolVersion;
62
}
63
}
64
65
public static void main(String[] args) throws Exception {
66
// Re-enable TLSv1 and TLSv1.1 since test depends on them.
67
SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1");
68
69
for (ContextVersion cv : ContextVersion.values()) {
70
System.out.println("Checking SSLContext of " + cv.contextVersion);
71
SSLContext context = SSLContext.getInstance(cv.contextVersion);
72
73
// Default SSLContext is initialized automatically.
74
if (!cv.contextVersion.equals("Default")) {
75
// Use default TK, KM and random.
76
context.init((KeyManager[])null, (TrustManager[])null, null);
77
}
78
79
SSLParameters parameters = context.getDefaultSSLParameters();
80
81
String[] protocols = parameters.getProtocols();
82
String[] ciphers = parameters.getCipherSuites();
83
84
if (protocols.length == 0 || ciphers.length == 0) {
85
throw new Exception("No default protocols or cipher suites");
86
}
87
88
boolean isMatch = false;
89
for (String protocol : protocols) {
90
System.out.println("\tdefault protocol version " + protocol);
91
if (protocol.equals(cv.defaultProtocolVersion)) {
92
isMatch = true;
93
break;
94
}
95
}
96
97
if (!isMatch) {
98
throw new Exception("No matched default protocol");
99
}
100
101
parameters = context.getSupportedSSLParameters();
102
103
protocols = parameters.getProtocols();
104
ciphers = parameters.getCipherSuites();
105
106
if (protocols.length == 0 || ciphers.length == 0) {
107
throw new Exception("No supported protocols or cipher suites");
108
}
109
110
isMatch = false;
111
for (String protocol : protocols) {
112
System.out.println("\tsupported protocol version " + protocol);
113
if (protocol.equals(cv.supportedProtocolVersion)) {
114
isMatch = true;
115
break;
116
}
117
}
118
119
if (!isMatch) {
120
throw new Exception("No matched supported protocol");
121
}
122
System.out.println("\t... Success");
123
}
124
}
125
}
126
127