Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/keytool/fakecacerts/TrustedCRL.java
41154 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
/*
25
* @test
26
* @bug 8244148
27
* @summary Test keytool -printcrl with -keystore and -trustcacerts options
28
* @library /test/lib
29
* @library /test/jdk/sun/security/util/module_patch
30
* @build java.base/sun.security.util.FilePaths
31
* @modules java.base/sun.security.util
32
* java.base/jdk.internal.misc
33
* @run main TrustedCRL
34
*/
35
36
import jdk.test.lib.SecurityTools;
37
import jdk.test.lib.process.OutputAnalyzer;
38
import jdk.test.lib.security.KeyStoreUtils;
39
40
import java.io.File;
41
import java.io.IOException;
42
import java.nio.file.Files;
43
import java.nio.file.Paths;
44
45
public class TrustedCRL {
46
47
// The --patch-module must be explicitly specified on the keytool
48
// command line because it's in a separate process
49
private static final String PATCH_OPTION;
50
51
static {
52
String tmp = "";
53
for (String a : jdk.internal.misc.VM.getRuntimeArguments()) {
54
if (a.startsWith("--patch-module")) {
55
tmp = "-J" + a + " ";
56
break;
57
}
58
}
59
PATCH_OPTION = tmp;
60
}
61
62
static OutputAnalyzer kt(String cmd) throws Exception {
63
return SecurityTools.keytool(cmd + " -keystore ks"
64
+ " -storepass changeit")
65
.shouldHaveExitValue(0);
66
}
67
68
static OutputAnalyzer patchcmd(String cmd, String options)
69
throws Exception {
70
return kt(PATCH_OPTION + " -" + cmd + " " + options);
71
}
72
73
static void rm(String s) throws IOException {
74
System.out.println("---------------------------------------------");
75
System.out.println("$ rm " + s);
76
Files.deleteIfExists(Paths.get(s));
77
}
78
79
public static void main(String[] args) throws Exception {
80
81
// Test -printcrl with root CA in cacerts keystore
82
kt("-genkeypair -alias myca -dname CN=CA -keyalg RSA"
83
+ " -keysize 1024 -sigalg SHA1withRSA");
84
85
kt("-exportcert -alias myca -rfc -file ca.pem");
86
87
// import root CA to mycacerts keystore
88
KeyStoreUtils.createCacerts("mycacerts", "ca.pem");
89
90
kt("-gencrl -alias myca -id 0 -file ca.crl -sigalg MD5withRSA");
91
92
patchcmd("printcrl", "-file ca.crl -trustcacerts")
93
.shouldMatch("Verified by.*in cacerts");
94
95
// Test -printcrl with root CA in local keystore
96
kt("-gencrl -alias myca -id 0 -file ca.crl");
97
98
kt("-printcrl -file ca.crl")
99
.shouldMatch("Verified by.*in keystore");
100
}
101
}
102
103