Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/compatibility/Utils.java
41152 views
1
/*
2
* Copyright (c) 2017, 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
import java.io.IOException;
25
import java.nio.file.Files;
26
import java.nio.file.Paths;
27
import java.util.ArrayList;
28
import java.util.LinkedHashSet;
29
import java.util.List;
30
import java.util.Set;
31
import java.util.stream.Collectors;
32
import java.util.stream.Stream;
33
34
import jdk.test.lib.security.CertUtils;
35
36
/*
37
* Utilities for testing.
38
*/
39
public class Utils {
40
41
public static final String PROP_JDK_LIST_FILE = "test.jdk.list.file";
42
43
public static final String PROP_SEC_PROPS_FILE = "test.sec.props.file";
44
public static final String SEC_PROPS_FILE = System.getProperty(
45
PROP_SEC_PROPS_FILE,
46
System.getProperty("test.src") + "/java.security");
47
48
public static final Cert RSA_CERT = new Cert(
49
KeyAlgorithm.RSA,
50
SignatureAlgorithm.RSA,
51
HashAlgorithm.SHA256,
52
CertUtils.RSA_CERT, CertUtils.RSA_KEY);
53
public static final Cert ECDSA_CERT = new Cert(
54
KeyAlgorithm.EC,
55
SignatureAlgorithm.ECDSA,
56
HashAlgorithm.SHA256,
57
CertUtils.ECDSA_CERT, CertUtils.ECDSA_KEY);
58
public static final Cert ECRSA_CERT = new Cert(
59
KeyAlgorithm.EC,
60
SignatureAlgorithm.RSA,
61
HashAlgorithm.SHA256,
62
CertUtils.ECRSA_CERT, CertUtils.ECRSA_KEY);
63
public static final Cert DSA_CERT = new Cert(
64
KeyAlgorithm.DSA,
65
SignatureAlgorithm.DSA,
66
HashAlgorithm.SHA256,
67
CertUtils.DSA_CERT, CertUtils.DSA_KEY);
68
69
// Retrieves JDK info from the file which is specified by system property
70
// test.jdk.list.file.
71
public static Set<JdkInfo> jdkInfoList() {
72
List<String> jdkList = jdkList();
73
74
Set<JdkInfo> jdkInfoList = new LinkedHashSet<>();
75
for (String jdkPath : jdkList) {
76
JdkInfo jdkInfo = new JdkInfo(Paths.get(jdkPath, "bin", "java"));
77
// JDK version must be unique.
78
if (!jdkInfoList.add(jdkInfo)) {
79
System.out.println("The JDK version is duplicate: " + jdkPath);
80
}
81
}
82
return jdkInfoList;
83
}
84
85
private static List<String> jdkList() {
86
String listFile = System.getProperty(PROP_JDK_LIST_FILE);
87
System.out.println("jdk list file: " + listFile);
88
if (listFile != null && Files.exists(Paths.get(listFile))) {
89
try (Stream<String> lines = Files.lines(Paths.get(listFile))) {
90
return lines.filter(line -> {
91
return !line.trim().isEmpty();
92
}).collect(Collectors.toList());
93
} catch (IOException e) {
94
throw new RuntimeException("Cannot get jdk list", e);
95
}
96
} else {
97
return new ArrayList<>();
98
}
99
}
100
101
public static Cert getCert(KeyExAlgorithm keyExAlgorithm) {
102
if (keyExAlgorithm == KeyExAlgorithm.RSA
103
|| keyExAlgorithm == KeyExAlgorithm.DHE_RSA
104
|| keyExAlgorithm == KeyExAlgorithm.ECDHE_RSA) {
105
return RSA_CERT;
106
} else if (keyExAlgorithm == KeyExAlgorithm.DHE_DSS) {
107
return DSA_CERT;
108
} else if (keyExAlgorithm == KeyExAlgorithm.ECDH_RSA) {
109
return ECRSA_CERT;
110
} else {
111
return ECDSA_CERT;
112
}
113
}
114
}
115
116