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