Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/keytool/DefaultOptions.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 8023197
27
* @summary Pre-configured command line options for keytool and 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.process.ProcessTools;
34
35
import java.nio.file.Files;
36
import java.nio.file.Path;
37
import java.util.List;
38
39
public class DefaultOptions {
40
41
public static void main(String[] args) throws Throwable {
42
43
Files.write(Path.of("kt.conf"), List.of(
44
"# A Pre-configured options file",
45
"keytool.all = -storepass:env PASS -keypass:env PASS "
46
+ "-keystore ${user.dir}/ks -debug",
47
"keytool.genkey = -keyalg ec -ext bc",
48
"keytool.delete = -keystore nothing"));
49
50
// kt.conf is read
51
keytool("-conf kt.conf -genkeypair -dname CN=A -alias a")
52
.shouldHaveExitValue(0);
53
keytool("-conf kt.conf -list -alias a -v")
54
.shouldHaveExitValue(0)
55
.shouldMatch("Signature algorithm name.*ECDSA")
56
.shouldContain("BasicConstraints");
57
58
// kt.conf is read, and dup multi-valued options processed as expected
59
keytool("-conf kt.conf -genkeypair -dname CN=B -alias b -ext ku=ds")
60
.shouldHaveExitValue(0);
61
keytool("-conf kt.conf -list -alias b -v")
62
.shouldHaveExitValue(0)
63
.shouldContain("BasicConstraints")
64
.shouldContain("DigitalSignature");
65
66
// Single-valued option in command section override all
67
keytool("-conf kt.conf -delete -alias a")
68
.shouldNotHaveExitValue(0);
69
70
// Single-valued option on command line overrides again
71
keytool("-conf kt.conf -delete -alias b -keystore ks")
72
.shouldHaveExitValue(0);
73
74
// Error cases
75
76
// File does not exist
77
keytool("-conf no-such-file -help -list")
78
.shouldNotHaveExitValue(0);
79
80
// Cannot have both standard name (-genkeypair) and legacy name (-genkey)
81
Files.write(Path.of("bad.conf"), List.of(
82
"keytool.all = -storepass:env PASS -keypass:env PASS -keystore ks",
83
"keytool.genkeypair = -keyalg rsa",
84
"keytool.genkey = -keyalg ec"));
85
86
keytool("-conf bad.conf -genkeypair -alias me -dname cn=me")
87
.shouldNotHaveExitValue(0);
88
89
// Unknown options are rejected by tool
90
Files.write(Path.of("bad.conf"), List.of(
91
"keytool.all=-unknown"));
92
93
keytool("-conf bad.conf -help -list").shouldNotHaveExitValue(0);
94
95
// System property must be present
96
Files.write(Path.of("bad.conf"), List.of(
97
"keytool.all = -keystore ${no.such.prop}"));
98
99
keytool("-conf bad.conf -help -list").shouldNotHaveExitValue(0);
100
}
101
102
// Run keytool with one environment variable PASS=changeit
103
static OutputAnalyzer keytool(String cmd) throws Throwable {
104
ProcessBuilder pb = SecurityTools.getProcessBuilder(
105
"keytool", List.of(cmd.trim().split("\\s+")));
106
pb.environment().put("PASS", "changeit");
107
return ProcessTools.executeCommand(pb);
108
}
109
}
110
111