Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/AlgOptions.java
41152 views
1
/*
2
* Copyright (c) 2005, 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 5094028 6219522
27
* @summary test new jarsigner -sigalg and -digestalg options
28
* @author Sean Mullan
29
* @library /test/lib
30
*/
31
32
import jdk.test.lib.SecurityTools;
33
import jdk.test.lib.process.OutputAnalyzer;
34
35
import java.nio.file.Files;
36
import java.nio.file.Path;
37
import java.util.ArrayList;
38
import java.util.List;
39
40
public class AlgOptions {
41
public static void main(String[] args) throws Exception {
42
43
// copy jar file into writeable location
44
Files.copy(Path.of(System.getProperty("test.src"), "AlgOptions.jar"),
45
Path.of("AlgOptionsTmp.jar"));
46
47
// test missing signature algorithm arg
48
sign("-sigalg").shouldNotHaveExitValue(0);
49
50
// test missing digest algorithm arg
51
sign("-digestalg").shouldNotHaveExitValue(0);
52
53
// test BOGUS signature algorithm
54
sign("-sigalg", "BOGUS").shouldNotHaveExitValue(0);
55
56
// test BOGUS digest algorithm
57
sign("-digestalg", "BOGUS").shouldNotHaveExitValue(0);
58
59
// test incompatible signature algorithm
60
sign("-sigalg", "SHA1withDSA").shouldNotHaveExitValue(0);
61
62
// test compatible signature algorithm
63
sign("-sigalg", "SHA512withRSA").shouldHaveExitValue(0);
64
verify();
65
66
// test non-default digest algorithm
67
sign("-digestalg", "SHA-1").shouldHaveExitValue(0);
68
verify();
69
70
// test SHA-512 digest algorithm (creates long lines)
71
sign("-digestalg", "SHA-512", "-sigalg", "SHA512withRSA")
72
.shouldHaveExitValue(0);
73
verify();
74
}
75
76
static OutputAnalyzer sign(String... options) throws Exception {
77
List<String> args = new ArrayList<>();
78
args.add("-keystore");
79
args.add(Path.of(System.getProperty("test.src"), "JarSigning.keystore")
80
.toString());
81
args.add("-storepass");
82
args.add("bbbbbb");
83
for (String option : options) {
84
args.add(option);
85
}
86
args.add("AlgOptionsTmp.jar");
87
args.add("c");
88
return SecurityTools.jarsigner(args);
89
}
90
91
static void verify() throws Exception {
92
SecurityTools.jarsigner(
93
"-verify", "AlgOptionsTmp.jar")
94
.shouldHaveExitValue(0);
95
}
96
}
97
98