Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/pkcs12/SameDN.java
41149 views
1
/*
2
* Copyright (c) 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
import static jdk.test.lib.SecurityTools.keytool;
25
26
import java.io.File;
27
import java.security.KeyStore;
28
29
/*
30
* @test
31
* @bug 8215776
32
* @library /test/lib
33
* @summary Keytool importkeystore may mix up certificate chain entries when DNs conflict
34
*/
35
public class SameDN {
36
37
private static final String COMMON = "-keystore ks -storepass changeit ";
38
39
public static final void main(String[] args) throws Exception {
40
genkeypair("ca1", "CN=CA");
41
genkeypair("ca2", "CN=CA");
42
genkeypair("user1", "CN=user");
43
genkeypair("user2", "CN=user");
44
gencert("ca1", "user1");
45
gencert("ca2", "user2");
46
47
KeyStore ks = KeyStore.getInstance(
48
new File("ks"), "changeit".toCharArray());
49
if (!ks.getCertificate("ca1").equals(ks.getCertificateChain("user1")[1])) {
50
throw new Exception("user1 not signed by ca1");
51
}
52
if (!ks.getCertificate("ca2").equals(ks.getCertificateChain("user2")[1])) {
53
throw new Exception("user2 not signed by ca2");
54
}
55
}
56
57
static void genkeypair(String alias, String dn) throws Exception {
58
keytool(COMMON + "-genkeypair -keyalg DSA -alias " + alias + " -dname " + dn)
59
.shouldHaveExitValue(0);
60
}
61
62
static void gencert(String issuer, String subject) throws Exception {
63
keytool(COMMON + "-certreq -alias " + subject + " -file req")
64
.shouldHaveExitValue(0);
65
keytool(COMMON + "-gencert -alias " + issuer + " -infile req -outfile cert")
66
.shouldHaveExitValue(0);
67
keytool(COMMON + "-importcert -alias " + subject + " -file cert")
68
.shouldHaveExitValue(0);
69
}
70
}
71
72