Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/lib/CheckBlockedCerts.java
41149 views
1
/*
2
* Copyright (c) 2013, 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
/*
25
* @test
26
* @bug 8011402 8211969 8237995
27
* @summary Move blacklisting certificate logic from hard code to data
28
* @modules java.base/sun.security.util
29
*/
30
31
import sun.security.util.UntrustedCertificates;
32
33
import java.io.*;
34
import java.security.KeyStore;
35
import java.security.cert.*;
36
import java.util.*;
37
38
public class CheckBlockedCerts {
39
public static void main(String[] args) throws Exception {
40
41
String home = System.getProperty("java.home");
42
boolean failed = false;
43
44
// Root CAs should always be trusted
45
File file = new File(home, "lib/security/cacerts");
46
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
47
try (FileInputStream fis = new FileInputStream(file)) {
48
ks.load(fis, null);
49
}
50
System.out.println("Check for cacerts: " + ks.size());
51
for (String alias: Collections.list(ks.aliases())) {
52
X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
53
if (UntrustedCertificates.isUntrusted(cert)) {
54
System.out.print(alias + " is untrusted");
55
failed = true;
56
}
57
}
58
59
// All certs in the pem files
60
Set<Certificate> blocked = new HashSet<>();
61
62
// Assumes the full src is available
63
File blockedCertsFile = new File(System.getProperty("test.src"),
64
"../../../../../make/data/blockedcertsconverter/blocked.certs.pem");
65
66
CertificateFactory cf = CertificateFactory.getInstance("X.509");
67
try (FileInputStream fis = new FileInputStream(blockedCertsFile)) {
68
Collection<? extends Certificate> certs
69
= cf.generateCertificates(fis);
70
System.out.println(certs.size());
71
for (Certificate c: certs) {
72
blocked.add(c);
73
X509Certificate cert = ((X509Certificate)c);
74
if (!UntrustedCertificates.isUntrusted(cert)) {
75
System.out.println(cert.getSubjectX500Principal() +
76
" is trusted");
77
failed = true;
78
}
79
}
80
}
81
82
// Check the blocked.certs file itself
83
file = new File(home, "lib/security/blocked.certs");
84
System.out.print("Check for " + file + ": ");
85
try (BufferedReader reader = new BufferedReader(
86
new InputStreamReader(new FileInputStream(file)))) {
87
int acount = 0;
88
int ccount = 0;
89
while (true) {
90
String line = reader.readLine();
91
if (line == null) break;
92
if (line.startsWith("Algorithm")) {
93
acount++;
94
} else if (!line.isEmpty() && !line.startsWith("#")) {
95
ccount++;
96
}
97
}
98
System.out.println(acount + " algs, " + ccount + " certs" );
99
if (acount != 1) {
100
System.out.println("There are " + acount + " algorithms");
101
failed = true;
102
}
103
// There are two unique fingerprints for each RSA certificate
104
if (ccount != blocked.size() * 2
105
&& !blocked.isEmpty()) {
106
System.out.println("Wrong blocked.certs size: "
107
+ ccount + " fingerprints, "
108
+ blocked.size() + " certs");
109
failed = true;
110
}
111
}
112
113
if (failed) {
114
throw new Exception("Failed");
115
}
116
}
117
}
118
119