Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/mscapi/nonUniqueAliases/NonUniqueAliases.java
41155 views
1
/*
2
* Copyright (c) 2018, 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 6483657 8154113
27
* @requires os.family == "windows"
28
* @library /test/lib
29
* @summary Test "keytool -list" displays correctly same named certificates
30
* @ignore Uses certutil.exe that isn't guaranteed to be installed
31
*/
32
33
import jdk.test.lib.process.ProcessTools;
34
35
import java.security.KeyStore;
36
import java.util.Collections;
37
38
public class NonUniqueAliases {
39
public static void main(String[] args) throws Throwable {
40
41
try {
42
String testSrc = System.getProperty("test.src", ".");
43
44
// removing the alias NonUniqueName if it already exists
45
ProcessTools.executeCommand("certutil", "-user", "-delstore", "MY",
46
"NonUniqueName");
47
48
// Importing 1st certificate into MY keystore using certutil tool
49
ProcessTools.executeCommand("certutil", "-user", "-addstore", "MY",
50
testSrc + "/nonUniq1.pem");
51
52
// Importing 2nd certificate into MY keystore using certutil tool
53
ProcessTools.executeCommand("certutil", "-user", "-addstore", "MY",
54
testSrc + "/nonUniq2.pem");
55
56
// Now we have 2
57
checkCount(1, 1);
58
59
ProcessTools.executeCommand("certutil", "-user", "-delstore", "MY",
60
"NonUniqueName");
61
62
// Now we have 2
63
checkCount(0, 0);
64
} finally {
65
ProcessTools.executeCommand("certutil", "-user", "-delstore", "MY",
66
"NonUniqueName");
67
}
68
}
69
70
static void checkCount(int c0, int c1) throws Exception {
71
72
KeyStore ks = KeyStore.getInstance("Windows-MY");
73
ks.load(null, null);
74
75
int count0 = 0, count1 = 0;
76
for (String alias : Collections.list(ks.aliases())) {
77
if (alias.equals("NonUniqueName")) {
78
count0++;
79
}
80
if (alias.equals("NonUniqueName (1)")) {
81
count1++;
82
}
83
}
84
if (count0 != c0) {
85
throw new Exception("error: unexpected number of entries ("
86
+ count0 + ") in the Windows-MY store");
87
}
88
if (count1 != c1) {
89
throw new Exception("error: unexpected number of entries ("
90
+ count1 + ") in the Windows-MY store");
91
}
92
}
93
}
94
95