Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/javax/net/ssl/compatibility/JdkInfo.java
66646 views
1
/*
2
* Copyright (c) 2017, 2021, 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.nio.file.Path;
25
import java.util.Arrays;
26
import java.util.LinkedHashMap;
27
import java.util.List;
28
import java.util.Map;
29
30
/*
31
* It represents a JDK with some specific attributes.
32
* If two JdkInfo instances have the same version value, the instances are
33
* regarded as equivalent.
34
*/
35
public class JdkInfo {
36
37
public static final JdkInfo DEFAULT = new JdkInfo(Jdk.DEFAULT.getPath());
38
39
public final Path javaPath;
40
41
public final String version;
42
public final List<String> supportedProtocols;
43
public final List<String> enabledProtocols;
44
public final List<String> supportedCipherSuites;
45
public final List<String> enabledCipherSuites;
46
public final boolean supportsSNI;
47
public final boolean supportsALPN;
48
49
public JdkInfo(Path javaPath) {
50
this.javaPath = javaPath;
51
52
String output = jdkAttributes(javaPath);
53
if (output == null || output.trim().isEmpty()) {
54
throw new RuntimeException(
55
"Cannot determine the JDK attributes: " + javaPath);
56
}
57
58
String[] attributes = Utilities.split(output, Utilities.PARAM_DELIMITER);
59
version = parseAttribute(attributes[0]);
60
supportedProtocols = parseListAttribute(attributes[1]);
61
enabledProtocols = parseListAttribute(attributes[2]);
62
supportedCipherSuites = parseListAttribute(attributes[3]);
63
enabledCipherSuites = parseListAttribute(attributes[4]);
64
supportsSNI = parseBooleanAttribute(attributes[5]);
65
supportsALPN = parseBooleanAttribute(attributes[6]);
66
}
67
68
private List<String> parseListAttribute(String attribute) {
69
attribute = parseAttribute(attribute);
70
return Arrays.asList(attribute.split(","));
71
}
72
73
private boolean parseBooleanAttribute(String attribute) {
74
attribute = parseAttribute(attribute);
75
return Boolean.parseBoolean(attribute);
76
}
77
private String parseAttribute(String attribute) {
78
return attribute.replaceAll(".*=", "");
79
}
80
81
// Determines the specific attributes for the specified JDK.
82
private static String jdkAttributes(Path javaPath) {
83
Map<String, String> props = new LinkedHashMap<>();
84
props.put("java.security.properties", Utils.SEC_PROPS_FILE);
85
return ProcUtils.java(javaPath, JdkInfoUtils.class, props).getOutput();
86
}
87
88
@Override
89
public int hashCode() {
90
return version == null ? 0 : version.hashCode();
91
}
92
93
@Override
94
public boolean equals(Object obj) {
95
if (this == obj) {
96
return true;
97
}
98
if (obj == null) {
99
return false;
100
}
101
if (getClass() != obj.getClass()) {
102
return false;
103
}
104
JdkInfo other = (JdkInfo) obj;
105
if (version == null) {
106
if (other.version != null) {
107
return false;
108
}
109
} else if (!version.equals(other.version)) {
110
return false;
111
}
112
return true;
113
}
114
115
public boolean supportsProtocol(Protocol protocol) {
116
return supportedProtocols.contains(protocol.name);
117
}
118
119
public boolean enablesProtocol(Protocol protocol) {
120
return enabledProtocols.contains(protocol.name);
121
}
122
123
public boolean supportsCipherSuite(CipherSuite cipherSuite) {
124
return supportedCipherSuites.contains(cipherSuite.name());
125
}
126
127
public boolean enablesCipherSuite(CipherSuite cipherSuite) {
128
return enabledCipherSuites.contains(cipherSuite.name());
129
}
130
}
131
132