Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/CertPolicy.java
41152 views
1
/*
2
* Copyright (c) 2014, 2019, 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 8036709
27
* @summary Java 7 jarsigner displays warning about cert policy tree
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.io.FileOutputStream;
36
import java.io.PrintStream;
37
import java.nio.file.Files;
38
import java.nio.file.Path;
39
import java.util.List;
40
41
public class CertPolicy {
42
static OutputAnalyzer keytool(String cmd) throws Exception {
43
return SecurityTools.keytool("-keypass changeit -storepass changeit "
44
+ "-keystore ks -keyalg rsa " + cmd);
45
}
46
47
static OutputAnalyzer jarsigner(String cmd) throws Exception {
48
return SecurityTools.jarsigner("-storepass changeit -keystore ks " + cmd);
49
}
50
51
public static void main(String[] args) throws Exception {
52
53
keytool("-genkeypair -alias ca -dname CN=CA -ext bc");
54
keytool("-genkeypair -alias int -dname CN=Int");
55
keytool("-genkeypair -alias ee -dname CN=EE");
56
57
// CertificatePolicies [[PolicyId: [1.2.3]], [PolicyId: [1.2.4]]]
58
// PolicyConstraints: [Require: 0; Inhibit: unspecified]
59
keytool("-certreq -alias int -file int.req");
60
keytool("-gencert -rfc -alias ca "
61
+ "-ext 2.5.29.32=300C300406022A03300406022A04 "
62
+ "-ext 2.5.29.36=3003800100 "
63
+ "-ext bc -infile int.req -outfile int.cert");
64
keytool("-import -alias int -file int.cert");
65
66
// CertificatePolicies [[PolicyId: [1.2.3]]]
67
keytool("-certreq -alias ee -file ee.req");
68
keytool("-gencert -rfc -alias int -ext 2.5.29.32=3006300406022A03 "
69
+ "-infile ee.req -outfile ee.cert");
70
keytool("-import -alias ee -file ee.cert");
71
72
Files.write(Path.of("cc"), List.of(
73
keytool("-export -alias ee -rfc").getOutput(),
74
keytool("-export -alias int -rfc").getOutput(),
75
keytool("-export -alias ca -rfc").getOutput()));
76
77
keytool("-delete -alias int");
78
79
JarUtils.createJarFile(Path.of("a.jar"), Path.of("."), Path.of("cc"));
80
81
// Make sure the certchain in the signed jar contains all 3 certs
82
jarsigner("-strict -certchain cc a.jar ee -debug")
83
.shouldHaveExitValue(0);
84
85
jarsigner("-strict -verify a.jar -debug")
86
.shouldHaveExitValue(0);
87
}
88
}
89
90