Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/EnableRevocation.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
/*
25
* @test
26
* @bug 8242060
27
* @summary Add a test to enable revocation check in jarsigner
28
* @library /test/lib
29
*/
30
31
import jdk.test.lib.SecurityTools;
32
import jdk.test.lib.process.OutputAnalyzer;
33
import jdk.test.lib.util.JarUtils;
34
35
import java.nio.file.Path;
36
37
public class EnableRevocation {
38
39
static OutputAnalyzer kt(String cmd, String ks) throws Exception {
40
return SecurityTools.keytool("-storepass changeit " + cmd +
41
" -keystore " + ks);
42
}
43
44
static void gencert(String owner, String cmd) throws Exception {
45
kt("-certreq -alias " + owner + " -file tmp.req", "ks");
46
kt("-gencert -infile tmp.req -outfile tmp.cert " + cmd, "ks");
47
kt("-importcert -alias " + owner + " -file tmp.cert", "ks");
48
}
49
50
public static void main(String[] args) throws Exception {
51
52
kt("-genkeypair -keyalg rsa -alias ca -dname CN=CA -ext bc:c", "ks");
53
kt("-genkeypair -keyalg rsa -alias ca1 -dname CN=CA1", "ks");
54
kt("-genkeypair -keyalg rsa -alias e1 -dname CN=E1", "ks");
55
56
gencert("ca1", "-alias ca -ext san=dns:ca1 -ext bc:c " +
57
"-ext crldp=URI:http://localhost:7000/crl.pem " +
58
"-ext aia=ocsp:URI:http://localhost:7200");
59
60
gencert("e1", "-alias ca1 -ext san=dns:e1 " +
61
"-ext crldp=URI:http://localhost:7000/crl.pem " +
62
"-ext aia=ocsp:URI:http://localhost:7100");
63
64
JarUtils.createJarFile(Path.of("a.jar"), Path.of("."), Path.of("ks"));
65
66
//Signing with -revCheck option
67
SecurityTools.jarsigner("-keystore ks -storepass changeit " +
68
"-signedjar signeda.jar " +
69
"-sigalg SHA256withRSA " +
70
" a.jar e1 -revCheck")
71
.shouldContain("Contacting OCSP server at")
72
.shouldContain("Downloading CRL from")
73
.shouldHaveExitValue(0);
74
75
kt("-exportcert -alias ca -rfc -file cacert", "ks");
76
kt("-importcert -noprompt -file cacert", "caks");
77
78
// Verifying with -revCheck option
79
SecurityTools.jarsigner("-verify -certs signeda.jar " +
80
"-keystore caks -storepass changeit -verbose -debug -revCheck")
81
.shouldContain("Contacting OCSP server at")
82
.shouldContain("Downloading CRL from")
83
.shouldHaveExitValue(0);
84
85
// Verifying with -revCheck and -strict options
86
SecurityTools.jarsigner("-verify -certs signeda.jar " +
87
"-keystore caks -storepass changeit " +
88
"-strict -verbose -debug -revCheck")
89
.shouldContain("Contacting OCSP server at")
90
.shouldContain("Downloading CRL from")
91
.shouldHaveExitValue(4);
92
}
93
}
94
95