Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/keytool/SelfIssued.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 6825352 6937978
27
* @summary support self-issued certificate in keytool and let -gencert generate the chain
28
* @library /test/lib
29
*/
30
31
import jdk.test.lib.SecurityTools;
32
import jdk.test.lib.process.OutputAnalyzer;
33
34
public class SelfIssued {
35
public static void main(String[] args) throws Exception {
36
keytool("-alias ca -dname CN=CA -genkeypair");
37
keytool("-alias ca1 -dname CN=CA1 -genkeypair");
38
keytool("-alias ca2 -dname CN=CA2 -genkeypair");
39
keytool("-alias e1 -dname CN=E1 -genkeypair");
40
41
// ca signs ca1, ca1 signs ca2, all self-issued
42
keytool("-alias ca1 -certreq -file ca1.req");
43
keytool("-alias ca -gencert -ext san=dns:ca1 "
44
+ "-infile ca1.req -outfile ca1.crt");
45
keytool("-alias ca1 -importcert -file ca1.crt");
46
47
keytool("-alias ca2 -certreq -file ca2.req");
48
keytool("-alias ca1 -gencert -ext san=dns:ca2 "
49
+ "-infile ca2.req -outfile ca2.crt");
50
keytool("-alias ca2 -importcert -file ca2.crt");
51
52
// Import e1 signed by ca2, should add ca2 and ca1, at least 3 certs in the chain
53
keytool("-alias e1 -certreq -file e1.req");
54
keytool("-alias ca2 -gencert -infile e1.req -outfile e1.crt");
55
56
keytool("-alias ca1 -delete");
57
keytool("-alias ca2 -delete");
58
keytool("-alias e1 -importcert -file e1.crt");
59
keytool("-alias e1 -list -v")
60
.shouldContain("[3]");
61
}
62
63
static OutputAnalyzer keytool(String s) throws Exception {
64
return SecurityTools.keytool("-storepass changeit -keypass changeit "
65
+ "-keystore ks -keyalg rsa " + s);
66
}
67
}
68
69
70