Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/mscapi/KeyStoreCompatibilityMode.java
41152 views
1
/*
2
* Copyright (c) 2005, 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 6324294 6931562 8180570
27
* @requires os.family == "windows"
28
* @run main KeyStoreCompatibilityMode
29
* @run main/othervm -Dsun.security.mscapi.keyStoreCompatibilityMode=true KeyStoreCompatibilityMode
30
* @run main/othervm -Dsun.security.mscapi.keyStoreCompatibilityMode=false KeyStoreCompatibilityMode -disable
31
* @summary Confirm that a null stream or password is not permitted when
32
* compatibility mode is enabled (and vice versa).
33
*/
34
35
import java.io.*;
36
import java.security.Provider;
37
import java.security.*;
38
39
public class KeyStoreCompatibilityMode {
40
41
private static final String KEYSTORE_COMPATIBILITY_MODE_PROP =
42
"sun.security.mscapi.keyStoreCompatibilityMode";
43
44
private static boolean mode;
45
46
public static void main(String[] args) throws Exception {
47
48
if (args.length > 0 && "-disable".equals(args[0])) {
49
mode = false;
50
} else {
51
mode = true;
52
}
53
54
Provider p = Security.getProvider("SunMSCAPI");
55
56
System.out.println("SunMSCAPI provider classname is " +
57
p.getClass().getName());
58
System.out.println(KEYSTORE_COMPATIBILITY_MODE_PROP + " = " +
59
System.getProperty(KEYSTORE_COMPATIBILITY_MODE_PROP));
60
61
KeyStore myKeyStore = KeyStore.getInstance("Windows-MY", p);
62
KeyStore myKeyStore2 = KeyStore.getInstance("Windows-MY", p);
63
KeyStore rootKeyStore = KeyStore.getInstance("Windows-ROOT", p);
64
KeyStore rootKeyStore2 = KeyStore.getInstance("Windows-ROOT", p);
65
66
InputStream inStream = new ByteArrayInputStream(new byte[1]);
67
OutputStream outStream = new ByteArrayOutputStream();
68
char[] password = new char[1];
69
70
// Checking keystore load operations
71
testLoadStore(myKeyStore, null, null, true);
72
testLoadStore(myKeyStore2, null, password, true);
73
testLoadStore(rootKeyStore, inStream, null, true);
74
testLoadStore(rootKeyStore2, inStream, password, true);
75
76
// Checking keystore store operations
77
testLoadStore(myKeyStore, null, null, false);
78
testLoadStore(myKeyStore2, null, password, false);
79
testLoadStore(rootKeyStore, outStream, null, false);
80
testLoadStore(rootKeyStore2, outStream, password, false);
81
}
82
83
private static void testLoadStore(KeyStore keyStore, Object stream,
84
char[] password, boolean doLoad) throws Exception {
85
86
String streamValue = stream == null ? "null" : "non-null";
87
String passwordValue = password == null ? "null" : "non-null";
88
89
System.out.println("Checking " + (doLoad ? "load" : "store") +
90
"(stream=" + streamValue + ", password=" + passwordValue + ")...");
91
92
try {
93
94
if (doLoad) {
95
keyStore.load((InputStream) stream, password);
96
} else {
97
keyStore.store((OutputStream) stream, password);
98
}
99
100
if (!mode && keyStore != null && password != null) {
101
throw new Exception(
102
"Expected an IOException to be thrown by KeyStore.load");
103
}
104
105
} catch (IOException ioe) {
106
// When mode=false the exception is expected.
107
if (mode) {
108
throw ioe;
109
} else {
110
System.out.println("caught the expected exception: " + ioe);
111
}
112
113
} catch (KeyStoreException kse) {
114
// store will fail if load has previously failed
115
if (doLoad) {
116
throw kse;
117
} else {
118
System.out.println("caught the expected exception: " + kse);
119
}
120
}
121
}
122
}
123
124