Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/CipherSuite/DisabledCurve.java
41152 views
1
/*
2
* Copyright (c) 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
/*
25
* @test
26
* @bug 8246330
27
* @library /javax/net/ssl/templates /test/lib
28
* @run main/othervm -Djdk.tls.namedGroups="secp384r1"
29
DisabledCurve DISABLE_NONE PASS
30
* @run main/othervm -Djdk.tls.namedGroups="secp384r1"
31
DisabledCurve secp384r1 FAIL
32
*/
33
import java.security.Security;
34
import java.util.Arrays;
35
import javax.net.ssl.SSLSocket;
36
import javax.net.ssl.SSLServerSocket;
37
import javax.net.ssl.SSLContext;
38
import javax.net.ssl.SSLException;
39
40
import jdk.test.lib.security.SecurityUtils;
41
42
public class DisabledCurve extends SSLSocketTemplate {
43
44
private static volatile int index;
45
private static final String[][][] protocols = {
46
{ { "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1" }, { "TLSv1.2" } },
47
{ { "TLSv1.2" }, { "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1" } },
48
{ { "TLSv1.2" }, { "TLSv1.2" } }, { { "TLSv1.1" }, { "TLSv1.1" } },
49
{ { "TLSv1" }, { "TLSv1" } } };
50
51
protected SSLContext createClientSSLContext() throws Exception {
52
return createSSLContext(
53
new SSLSocketTemplate.Cert[] {
54
SSLSocketTemplate.Cert.CA_ECDSA_SECP384R1 },
55
new SSLSocketTemplate.Cert[] {
56
SSLSocketTemplate.Cert.EE_ECDSA_SECP384R1 },
57
getClientContextParameters());
58
}
59
60
protected SSLContext createServerSSLContext() throws Exception {
61
return createSSLContext(
62
new SSLSocketTemplate.Cert[] {
63
SSLSocketTemplate.Cert.CA_ECDSA_SECP384R1 },
64
new SSLSocketTemplate.Cert[] {
65
SSLSocketTemplate.Cert.EE_ECDSA_SECP384R1 },
66
getServerContextParameters());
67
}
68
69
@Override
70
protected void configureClientSocket(SSLSocket socket) {
71
String[] ps = protocols[index][0];
72
73
System.out.print("Setting client protocol(s): ");
74
Arrays.stream(ps).forEachOrdered(System.out::print);
75
System.out.println();
76
77
socket.setEnabledProtocols(ps);
78
}
79
80
@Override
81
protected void configureServerSocket(SSLServerSocket serverSocket) {
82
String[] ps = protocols[index][1];
83
84
System.out.print("Setting server protocol(s): ");
85
Arrays.stream(ps).forEachOrdered(System.out::print);
86
System.out.println();
87
88
serverSocket.setEnabledProtocols(ps);
89
}
90
91
public static void main(String[] args) throws Exception {
92
String expected = args[1];
93
String disabledName = ("DISABLE_NONE".equals(args[0]) ? "" : args[0]);
94
boolean disabled = false;
95
if (disabledName.equals("")) {
96
Security.setProperty("jdk.disabled.namedCurves", "");
97
} else {
98
disabled = true;
99
Security.setProperty("jdk.certpath.disabledAlgorithms", "secp384r1");
100
}
101
102
// Re-enable TLSv1 and TLSv1.1 since test depends on it.
103
SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1");
104
105
for (index = 0; index < protocols.length; index++) {
106
try {
107
(new DisabledCurve()).run();
108
if (expected.equals("FAIL")) {
109
throw new RuntimeException(
110
"Expected test to fail, but it passed");
111
}
112
} catch (SSLException | IllegalStateException ssle) {
113
if (expected.equals("FAIL") && disabled) {
114
System.out.println(
115
"Expected exception was thrown: TEST PASSED");
116
} else {
117
throw new RuntimeException(ssle);
118
}
119
120
}
121
122
}
123
}
124
}
125
126