Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/DefaultOptions.java
41152 views
1
/*
2
* Copyright (c) 2014, 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 8049834
27
* @summary Two security tools tests do not run with only JRE
28
* @library /test/lib
29
*/
30
31
import jdk.test.lib.Asserts;
32
import jdk.test.lib.SecurityTools;
33
import jdk.test.lib.process.OutputAnalyzer;
34
import jdk.test.lib.process.ProcessTools;
35
import jdk.test.lib.util.JarUtils;
36
37
import java.nio.file.Files;
38
import java.nio.file.Path;
39
import java.util.List;
40
import java.util.jar.JarFile;
41
42
public class DefaultOptions {
43
44
static OutputAnalyzer jarsigner(String cmd) throws Throwable {
45
ProcessBuilder pb = SecurityTools.getProcessBuilder(
46
"jarsigner", List.of(cmd.trim().split("\\s+")));
47
pb.environment().put("PASS", "changeit");
48
return ProcessTools.executeCommand(pb);
49
}
50
51
static OutputAnalyzer keytool(String cmd) throws Throwable {
52
cmd = "-storepass:env PASS -keypass:env PASS -keystore ks " + cmd;
53
ProcessBuilder pb = SecurityTools.getProcessBuilder(
54
"keytool", List.of(cmd.trim().split("\\s+")));
55
pb.environment().put("PASS", "changeit");
56
return ProcessTools.executeCommand(pb);
57
}
58
59
public static void main(String[] args) throws Throwable {
60
keytool("-genkeypair -dname CN=A -alias a -keyalg rsa")
61
.shouldHaveExitValue(0);
62
keytool("-genkeypair -dname CN=CA -alias ca -keyalg rsa -ext bc:c")
63
.shouldHaveExitValue(0);
64
keytool("-alias a -certreq -file a.req");
65
keytool("-alias ca -gencert -infile a.req -outfile a.cert");
66
keytool("-alias a -import -file a.cert").shouldHaveExitValue(0);
67
68
Files.write(Path.of("js.conf"), List.of(
69
"jarsigner.all = -keystore ${user.dir}/ks -storepass:env PASS "
70
+ "-debug -strict",
71
"jarsigner.sign = -digestalg SHA-512",
72
"jarsigner.verify = -verbose:summary"));
73
74
JarUtils.createJarFile(Path.of("a.jar"), Path.of("."),
75
Path.of("ks"), Path.of("js.conf"));
76
77
jarsigner("-conf js.conf a.jar a").shouldHaveExitValue(0);
78
jarsigner("-conf js.conf -verify a.jar").shouldHaveExitValue(0)
79
.shouldContain("and 1 more");
80
81
try (JarFile jf = new JarFile("a.jar")) {
82
Asserts.assertTrue(jf.getManifest().getAttributes("ks").keySet()
83
.stream()
84
.anyMatch(s -> s.toString().contains("SHA-512-Digest")));
85
}
86
}
87
}
88
89