Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/compatibility/JdkInfoUtils.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
import java.security.NoSuchAlgorithmException;
25
26
import javax.net.ssl.SSLContext;
27
import javax.net.ssl.SSLParameters;
28
29
/*
30
* This class is used for returning some specific JDK information.
31
*/
32
public class JdkInfoUtils {
33
34
public static final String JAVA_RUNTIME_VERSION = "javaRuntimeVersion";
35
public static final String SUPPORTED_PROTOCOLS = "supportedProtocols";
36
public static final String ENABLED_PROTOCOLS = "enabledProtocols";
37
public static final String SUPPORTED_CIPHER_SUITES = "supportedCipherSuites";
38
public static final String ENABLED_CIPHER_SUITES = "enabledCipherSuites";
39
public static final String SUPPORTS_SNI = "supportsSNI";
40
public static final String SUPPORTS_ALPN = "supportsALPN";
41
42
// Returns the JDK build version.
43
public static String javaRuntimeVersion() {
44
return System.getProperty("java.runtime.version");
45
}
46
47
private static String supportedProtocols()
48
throws NoSuchAlgorithmException {
49
String[] protocols = SSLContext.getDefault()
50
.createSSLEngine().getSupportedProtocols();
51
return Utilities.join(Utilities.VALUE_DELIMITER, protocols).toString();
52
}
53
54
private static String enabledProtocols()
55
throws NoSuchAlgorithmException {
56
String[] protocols = SSLContext.getDefault()
57
.createSSLEngine().getEnabledProtocols();
58
return Utilities.join(Utilities.VALUE_DELIMITER, protocols).toString();
59
}
60
61
private static String supportedCipherSuites()
62
throws NoSuchAlgorithmException {
63
String[] supportedCipherSuites = SSLContext.getDefault()
64
.createSSLEngine().getSupportedCipherSuites();
65
return Utilities.join(Utilities.VALUE_DELIMITER, supportedCipherSuites)
66
.toString();
67
}
68
69
private static String enabledCipherSuites()
70
throws NoSuchAlgorithmException {
71
String[] enabledCipherSuites = SSLContext.getDefault()
72
.createSSLEngine().getEnabledCipherSuites();
73
return Utilities.join(Utilities.VALUE_DELIMITER, enabledCipherSuites)
74
.toString();
75
}
76
77
// Checks if SNI is supported by the JDK build.
78
private static boolean supportsSNI() {
79
boolean isSupported = true;
80
try {
81
SSLParameters.class.getMethod("getServerNames");
82
} catch (NoSuchMethodException e) {
83
isSupported = false;
84
}
85
return isSupported;
86
}
87
88
// Checks if ALPN is supported by the JDK build.
89
private static boolean supportsALPN() {
90
boolean isSupported = true;
91
try {
92
SSLParameters.class.getMethod("getApplicationProtocols");
93
} catch (NoSuchMethodException e) {
94
isSupported = false;
95
}
96
return isSupported;
97
}
98
99
public static void main(String[] args) throws NoSuchAlgorithmException {
100
System.out.print(Utilities.join(Utilities.PARAM_DELIMITER,
101
attr(JAVA_RUNTIME_VERSION, javaRuntimeVersion()),
102
attr(SUPPORTED_PROTOCOLS, supportedProtocols()),
103
attr(ENABLED_PROTOCOLS, enabledProtocols()),
104
attr(SUPPORTED_CIPHER_SUITES, supportedCipherSuites()),
105
attr(ENABLED_CIPHER_SUITES, enabledCipherSuites()),
106
attr(SUPPORTS_SNI, supportsSNI()),
107
attr(SUPPORTS_ALPN, supportsALPN())));
108
}
109
110
private static String attr(String name, Object value) {
111
return name + "=" + String.valueOf(value);
112
}
113
}
114
115