Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/keytool/EmptySubject.java
41152 views
1
/*
2
* Copyright (c) 2009, 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 6847026
27
* @summary keytool should be able to generate certreq and cert without subject name
28
* @library /test/lib
29
*/
30
31
import jdk.test.lib.SecurityTools;
32
import jdk.test.lib.process.OutputAnalyzer;
33
34
import java.util.ArrayList;
35
import java.util.Arrays;
36
import java.util.List;
37
38
public class EmptySubject{
39
static final String KS = "emptysubject.jks";
40
public static void main(String[] args) throws Exception {
41
kt("-alias", "ca", "-dname", "CN=CA", "-genkeypair");
42
kt("-alias", "me", "-dname", "CN=Me", "-genkeypair");
43
44
// When -dname is recognized, SAN must be specified, otherwise,
45
// -printcert fails.
46
kt("-alias", "me", "-certreq", "-dname", "", "-file", "me1.req")
47
.shouldHaveExitValue(0);
48
kt("-alias", "ca", "-gencert",
49
"-infile", "me1.req", "-outfile", "me1.crt")
50
.shouldHaveExitValue(0);
51
kt("-printcert", "-file", "me1.crt").shouldNotHaveExitValue(0);
52
53
kt("-alias", "me", "-certreq", "-file", "me2.req")
54
.shouldHaveExitValue(0);
55
kt("-alias", "ca", "-gencert", "-dname", "",
56
"-infile", "me2.req", "-outfile", "me2.crt")
57
.shouldHaveExitValue(0);
58
kt("-printcert", "-file", "me2.crt").shouldNotHaveExitValue(0);
59
60
kt("-alias", "me", "-certreq", "-dname", "", "-file", "me3.req")
61
.shouldHaveExitValue(0);
62
kt("-alias", "ca", "-gencert", "-ext", "san:c=email:[email protected]",
63
"-infile", "me3.req", "-outfile", "me3.crt")
64
.shouldHaveExitValue(0);
65
kt("-printcert", "-file", "me3.crt").shouldHaveExitValue(0);
66
67
kt("-alias", "me", "-certreq", "-file", "me4.req")
68
.shouldHaveExitValue(0);
69
kt("-alias", "ca", "-gencert", "-dname", "",
70
"-ext", "san:c=email:[email protected]",
71
"-infile", "me4.req", "-outfile", "me4.crt")
72
.shouldHaveExitValue(0);
73
kt("-printcert", "-file", "me4.crt").shouldHaveExitValue(0);
74
}
75
76
static OutputAnalyzer kt(String... s) throws Exception {
77
List<String> cmd = new ArrayList<>();
78
cmd.addAll(Arrays.asList(
79
"-storepass", "changeit",
80
"-keypass", "changeit",
81
"-keystore", KS,
82
"-keyalg", "rsa"));
83
cmd.addAll(Arrays.asList(s));
84
return SecurityTools.keytool(cmd);
85
}
86
}
87
88