Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/pkcs11/Secmod/TrustAnchors.java
38855 views
1
/*
2
* Copyright (c) 2005, 2016, 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 6298106 6275523 6420252
27
* @summary make sure we can access the NSS trust anchor module
28
* @author Andreas Sterbenz
29
* @library ..
30
* @run main/othervm TrustAnchors
31
* @run main/othervm TrustAnchors sm policy
32
*/
33
34
import java.io.File;
35
import java.security.KeyStore;
36
import java.security.Provider;
37
import java.security.Security;
38
import java.security.cert.X509Certificate;
39
import java.util.Collection;
40
import java.util.Collections;
41
import java.util.TreeSet;
42
43
public class TrustAnchors extends SecmodTest {
44
45
public static void main(String[] args) throws Exception {
46
if (initSecmod() == false) {
47
return;
48
}
49
50
if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
51
// our secmod.db file says nssckbi.*so*, so NSS does not find the
52
// *DLL* on windows.
53
System.out.println("Test currently does not work on Windows, skipping");
54
return;
55
}
56
57
String configName = BASE + SEP + "nsstrust.cfg";
58
Provider p = getSunPKCS11(configName);
59
60
System.out.println(p);
61
Security.addProvider(p);
62
63
if (args.length > 1 && "sm".equals(args[0])) {
64
System.setProperty("java.security.policy",
65
BASE + File.separator + args[1]);
66
System.setSecurityManager(new SecurityManager());
67
}
68
69
KeyStore ks = KeyStore.getInstance("PKCS11", p);
70
ks.load(null, null);
71
Collection<String> aliases = new TreeSet<>(Collections.list(ks.aliases()));
72
System.out.println("entries: " + aliases.size());
73
System.out.println(aliases);
74
75
for (String alias : aliases) {
76
if (ks.isCertificateEntry(alias) == false) {
77
throw new Exception("not trusted: " + alias);
78
}
79
X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
80
// verify self-signed certs
81
if (cert.getSubjectX500Principal().equals(cert.getIssuerX500Principal())) {
82
System.out.print(".");
83
cert.verify(cert.getPublicKey());
84
} else {
85
System.out.print("-");
86
}
87
}
88
89
System.out.println();
90
System.out.println("OK");
91
}
92
93
}
94
95