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