author | mchung |
Mon, 23 Nov 2015 12:44:43 -0800 | |
changeset 34253 | ba3946143842 |
parent 32005 | 2c716d9dac38 |
child 35315 | 67dcc46f8241 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test 1.5, 03/06/24 |
|
32005
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
26 |
* @bug 4850376 8130850 |
2 | 27 |
* @summary Provide generic storage KeyStore storage facilities |
28 |
*/ |
|
29 |
||
30 |
import java.security.*; |
|
31 |
import java.security.cert.*; |
|
32 |
import java.util.*; |
|
33 |
import java.io.*; |
|
34 |
||
35 |
import sun.security.provider.*; |
|
36 |
||
37 |
public class EntryMethods |
|
38 |
extends Provider |
|
39 |
implements KeyStore.Entry |
|
40 |
{ |
|
41 |
||
42 |
private static FileInputStream pre15fis; |
|
43 |
private static char[] password = {'f', 'o', 'o', 'b', 'a', 'r'}; |
|
44 |
private static char[] badPwd = {'b', 'a', 'd', 'p', 'w', 'd'}; |
|
45 |
||
46 |
public static class FooProtect implements KeyStore.ProtectionParameter { } |
|
47 |
public static class FooParameter implements KeyStore.LoadStoreParameter { |
|
48 |
public KeyStore.ProtectionParameter getProtectionParameter() { |
|
49 |
return null; |
|
50 |
} |
|
51 |
} |
|
52 |
||
32005
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
53 |
public static class MyLoadStoreParameter |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
54 |
implements KeyStore.LoadStoreParameter { |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
55 |
|
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
56 |
private KeyStore.ProtectionParameter protection; |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
57 |
|
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
58 |
MyLoadStoreParameter(KeyStore.ProtectionParameter protection) { |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
59 |
this.protection = protection; |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
60 |
} |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
61 |
|
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
62 |
public KeyStore.ProtectionParameter getProtectionParameter() { |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
63 |
return protection; |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
64 |
} |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
65 |
} |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
66 |
|
2 | 67 |
public static class FooEntry implements KeyStore.Entry { } |
68 |
||
69 |
public EntryMethods() throws Exception { |
|
70 |
super("EntryMethods", 0.0, "EntryMethods"); |
|
71 |
||
72 |
pre15fis = new FileInputStream |
|
73 |
(System.getProperty("test.src") + "/EntryMethods.pre15.keystore"); |
|
74 |
||
75 |
AccessController.doPrivileged(new PrivilegedAction() { |
|
76 |
public Object run() { |
|
77 |
put("KeyStore.Pre15KeyStore", "EntryMethods$Pre15"); |
|
78 |
put("KeyStore.Post15KeyStore", "EntryMethods$Post15"); |
|
79 |
put("KeyStore.UnrecoverableKeyStore", |
|
80 |
"EntryMethods$UnrecoverableKS"); |
|
81 |
return null; |
|
82 |
} |
|
83 |
}); |
|
84 |
} |
|
85 |
||
86 |
public static void main(String[] args) throws Exception { |
|
87 |
||
88 |
EntryMethods entry = new EntryMethods(); |
|
89 |
||
90 |
// test pre-JDK1.5 KeyStore throws UnsupportedOperationExceptions |
|
91 |
// for new methods |
|
92 |
KeyStore pre15KS = KeyStore.getInstance("Pre15KeyStore", entry); |
|
93 |
testPre15(pre15KS); |
|
94 |
||
95 |
// test post-JDK1.5 KeyStore does right thing with new methods |
|
96 |
KeyStore post15KS = KeyStore.getInstance("Post15KeyStore", entry); |
|
97 |
testPost15(post15KS); |
|
98 |
||
99 |
// test post-JDK1.5 KeyStore can throw new UnrecoverableEntryException |
|
100 |
KeyStore uKS = KeyStore.getInstance("UnrecoverableKeyStore", entry); |
|
101 |
testUnrecoverable(uKS); |
|
102 |
} |
|
103 |
||
104 |
private static void testPre15(KeyStore ks) throws Exception { |
|
105 |
||
106 |
int tNum = 1; |
|
107 |
KeyStore.Entry e = null; |
|
108 |
||
109 |
// TEST load null param |
|
110 |
ks.load((KeyStore.LoadStoreParameter)null); |
|
111 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
112 |
||
113 |
||
114 |
// TEST load random param |
|
115 |
try { |
|
116 |
ks.load(new FooParameter()); |
|
117 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
118 |
} catch (UnsupportedOperationException uoe) { |
|
119 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
32005
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
120 |
} catch (NoSuchAlgorithmException nsae) { |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
121 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
2 | 122 |
} |
123 |
||
124 |
||
32005
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
125 |
// TEST load custom param |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
126 |
ks.load(new MyLoadStoreParameter( |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
127 |
new KeyStore.PasswordProtection(password))); |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
128 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
129 |
|
2c716d9dac38
8130850: Support loading a keystore with a custom KeyStore.LoadStoreParameter class
vinnie
parents:
31422
diff
changeset
|
130 |
|
2 | 131 |
// TEST store random param |
132 |
ks.load(pre15fis, password); |
|
133 |
||
134 |
// setup for later user |
|
135 |
KeyStore.Entry pkeNew = ks.getEntry("privkey", |
|
136 |
new KeyStore.PasswordProtection(password)); |
|
137 |
KeyStore.Entry tceNew = ks.getEntry("trustedcert", null); |
|
138 |
||
139 |
try { |
|
140 |
ks.store(new FooParameter()); |
|
141 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
142 |
} catch (UnsupportedOperationException uoe) { |
|
143 |
// good |
|
144 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
145 |
} |
|
146 |
||
147 |
||
148 |
// TEST store null param |
|
149 |
try { |
|
150 |
ks.store(null); |
|
151 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
152 |
} catch (UnsupportedOperationException uoe) { |
|
153 |
// good |
|
154 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
155 |
} |
|
156 |
||
157 |
||
158 |
// TEST getEntry with alias/protParam - use invalid alias |
|
159 |
e = ks.getEntry("notPresent", |
|
160 |
new KeyStore.PasswordProtection(password)); |
|
161 |
if (e == null) { |
|
162 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
163 |
} else { |
|
164 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
165 |
"expected null entry returned"); |
|
166 |
} |
|
167 |
||
168 |
||
169 |
// TEST getEntry with alias/null protParam - get private key |
|
170 |
try { |
|
171 |
e = ks.getEntry("privkey", null); |
|
172 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
173 |
"expected UnrecoverableEntryException"); |
|
174 |
} catch (UnrecoverableEntryException uee) { |
|
175 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
176 |
} |
|
177 |
||
178 |
||
179 |
// TEST getEntry with alias/bad password - get private key |
|
180 |
try { |
|
181 |
e = ks.getEntry("privkey", |
|
182 |
new KeyStore.PasswordProtection(badPwd)); |
|
183 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
184 |
"expected UnrecoverableEntryException"); |
|
185 |
} catch (UnrecoverableEntryException uee) { |
|
186 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
187 |
} |
|
188 |
||
189 |
||
190 |
// TEST getEntry with alias/unknown protection - get private key |
|
191 |
try { |
|
192 |
e = ks.getEntry("privkey", new FooProtect()); |
|
193 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
194 |
"expected UnsupportedOperationException"); |
|
195 |
} catch (UnsupportedOperationException uoe) { |
|
196 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
197 |
} |
|
198 |
||
199 |
||
200 |
// TEST getEntry with alias/protParam - get private key |
|
201 |
e = ks.getEntry("privkey", new KeyStore.PasswordProtection(password)); |
|
202 |
if (e instanceof KeyStore.PrivateKeyEntry) { |
|
203 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
204 |
} else { |
|
205 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
206 |
"expected PrivateKeyEntry"); |
|
207 |
} |
|
208 |
||
209 |
||
210 |
// TEST getEntry with alias/null protParam - get trusted cert |
|
211 |
e = ks.getEntry("trustedcert", null); |
|
212 |
if (e instanceof KeyStore.TrustedCertificateEntry) { |
|
213 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
214 |
} else { |
|
215 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
216 |
} |
|
217 |
||
218 |
||
219 |
// TEST getEntry with alias/non-null protParam - get trusted cert |
|
220 |
try { |
|
221 |
e = ks.getEntry("trustedcert", |
|
222 |
new KeyStore.PasswordProtection(password)); |
|
223 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
224 |
} catch (UnsupportedOperationException uoe) { |
|
225 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
226 |
} |
|
227 |
||
228 |
||
229 |
// TEST setEntry with alias/entry/protParam - use invalid alias |
|
230 |
try { |
|
231 |
ks.setEntry("foo", new FooEntry(), |
|
232 |
new KeyStore.PasswordProtection(password)); |
|
233 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
234 |
"expected KeyStoreException"); |
|
235 |
} catch (KeyStoreException kse) { |
|
236 |
// good |
|
237 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
238 |
} |
|
239 |
||
240 |
||
241 |
// TEST setEntry with alias/entry/null protParam - set private key |
|
242 |
try { |
|
243 |
ks.setEntry("newPrivKey", pkeNew, null); |
|
244 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
245 |
"expected KeyStoreException"); |
|
246 |
} catch (KeyStoreException kse) { |
|
247 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
248 |
} |
|
249 |
||
250 |
||
251 |
// TEST setEntry with alias/entry/random protParam - set private key |
|
252 |
try { |
|
253 |
ks.setEntry("newPrivKey", pkeNew, new FooProtect()); |
|
254 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
255 |
"expected KeyStoreException"); |
|
256 |
} catch (KeyStoreException kse) { |
|
257 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
258 |
} |
|
259 |
||
260 |
||
261 |
// TEST setEntry with alias/entry/protParam - set private key |
|
262 |
ks.setEntry("newPrivKey", pkeNew, |
|
263 |
new KeyStore.PasswordProtection(password)); |
|
264 |
e = ks.getEntry("newPrivKey", |
|
265 |
new KeyStore.PasswordProtection(password)); |
|
266 |
if (e instanceof KeyStore.PrivateKeyEntry) { |
|
267 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
268 |
} else { |
|
269 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
270 |
"expected PrivateKeyEntry"); |
|
271 |
} |
|
272 |
||
273 |
||
274 |
// TEST setEntry with alias/entry/non null protParam - set trusted cert |
|
275 |
try { |
|
276 |
ks.setEntry("newTrustedcert", tceNew, |
|
277 |
new KeyStore.PasswordProtection(password)); |
|
278 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
279 |
"expected KeyStoreException"); |
|
280 |
} catch (KeyStoreException kse) { |
|
281 |
// good |
|
282 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
283 |
} |
|
284 |
||
285 |
||
286 |
// TEST setEntry with alias/entry/null protParam - set trusted cert |
|
287 |
ks.setEntry("newTrustedcert", tceNew, null); |
|
288 |
e = ks.getEntry("newTrustedcert", null); |
|
289 |
if (e instanceof KeyStore.TrustedCertificateEntry) { |
|
290 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
291 |
} else { |
|
292 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed - " + |
|
293 |
"expected TrustedCertificateEntry"); |
|
294 |
} |
|
295 |
||
296 |
||
297 |
// TEST entryInstanceOf - invalid alias |
|
298 |
if (ks.entryInstanceOf("foo", EntryMethods.class) == false) { |
|
299 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
300 |
} else { |
|
301 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
302 |
} |
|
303 |
||
304 |
||
305 |
// TEST entryInstanceOf - false case |
|
306 |
if (ks.entryInstanceOf("privkey", EntryMethods.class) == false) { |
|
307 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
308 |
} else { |
|
309 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
310 |
} |
|
311 |
||
312 |
||
313 |
// TEST entryInstanceOf - true case, trustedcert entry |
|
314 |
if (ks.entryInstanceOf("trustedcert", |
|
315 |
KeyStore.TrustedCertificateEntry.class)) { |
|
316 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
317 |
} else { |
|
318 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
319 |
} |
|
320 |
||
321 |
||
322 |
// TEST entryInstanceOf - true case, private key entry |
|
323 |
if (ks.entryInstanceOf("privkey", |
|
324 |
KeyStore.PrivateKeyEntry.class)) { |
|
325 |
System.out.println("[Pre1.5] test " + tNum++ + " passed"); |
|
326 |
} else { |
|
327 |
throw new SecurityException("[Pre1.5] test " + tNum + " failed"); |
|
328 |
} |
|
329 |
||
330 |
} |
|
331 |
||
332 |
private static void testPost15(KeyStore ks) throws Exception { |
|
333 |
||
334 |
KeyStore.Entry e = null; |
|
335 |
||
336 |
ks.load(new EntryMethods.FooParameter()); |
|
337 |
ks.store(new EntryMethods.FooParameter()); |
|
338 |
||
339 |
e = ks.getEntry("foo", new KeyStore.PasswordProtection(password)); |
|
340 |
if (!(e instanceof EntryMethods.FooEntry)) { |
|
341 |
throw new SecurityException |
|
342 |
("testPost15 getEntry(String, ProtParm) " + |
|
343 |
"expected EntryMethods.FooEntry returned"); |
|
344 |
} |
|
345 |
||
346 |
ks.setEntry("foo", new EntryMethods.FooEntry(), |
|
347 |
new KeyStore.PasswordProtection(password)); |
|
348 |
||
349 |
if (!ks.entryInstanceOf("foo", KeyStore.PrivateKeyEntry.class)) { |
|
350 |
throw new SecurityException |
|
351 |
("testPost15 entryInstanceOf(String, Class) " + |
|
352 |
"expected true returned"); |
|
353 |
} |
|
354 |
||
355 |
System.out.println("[Post1.5] tests all passed"); |
|
356 |
} |
|
357 |
||
358 |
private static void testUnrecoverable(KeyStore ks) throws Exception { |
|
359 |
ks.load(new EntryMethods.FooParameter()); |
|
360 |
try { |
|
361 |
ks.getEntry("foo", new KeyStore.PasswordProtection(password)); |
|
362 |
throw new SecurityException |
|
363 |
("UnrecoverableEntryException not thrown for " + |
|
364 |
"getEntry(String, ProtectionParam)"); |
|
365 |
} catch (UnrecoverableEntryException uee) { |
|
366 |
// good |
|
367 |
System.out.println("[UnrecoverableEntry] test passed"); |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
public static class Pre15 extends KeyStoreSpi { |
|
372 |
||
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
373 |
private static KeyStore jks = getJKS(); |
2 | 374 |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
375 |
private static KeyStore getJKS() { |
2 | 376 |
try { |
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
377 |
return (KeyStore) KeyStore.getInstance("JKS"); |
2 | 378 |
} catch (Exception e) { |
379 |
e.printStackTrace(); |
|
380 |
throw new RuntimeException(e); |
|
381 |
} |
|
382 |
} |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
383 |
public Pre15() { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
384 |
} |
2 | 385 |
|
386 |
public Key engineGetKey(String alias, char[] password) |
|
387 |
throws NoSuchAlgorithmException, UnrecoverableKeyException { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
388 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
389 |
return jks.getKey(alias, password); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
390 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
391 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
392 |
} |
2 | 393 |
} |
394 |
||
395 |
public java.security.cert.Certificate[] engineGetCertificateChain |
|
396 |
(String alias) { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
397 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
398 |
return jks.getCertificateChain(alias); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
399 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
400 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
401 |
} |
2 | 402 |
} |
403 |
||
404 |
public java.security.cert.Certificate engineGetCertificate |
|
405 |
(String alias) { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
406 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
407 |
return jks.getCertificate(alias); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
408 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
409 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
410 |
} |
2 | 411 |
} |
412 |
||
413 |
public Date engineGetCreationDate(String alias) { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
414 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
415 |
return jks.getCreationDate(alias); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
416 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
417 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
418 |
} |
2 | 419 |
} |
420 |
||
421 |
public void engineSetKeyEntry(String alias, Key key, |
|
422 |
char[] password, |
|
423 |
java.security.cert.Certificate[] chain) |
|
424 |
throws KeyStoreException { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
425 |
jks.setKeyEntry(alias, key, password, chain); |
2 | 426 |
} |
427 |
||
428 |
public void engineSetKeyEntry(String alias, byte[] key, |
|
429 |
java.security.cert.Certificate[] chain) |
|
430 |
throws KeyStoreException { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
431 |
jks.setKeyEntry(alias, key, chain); |
2 | 432 |
} |
433 |
||
434 |
public void engineSetCertificateEntry(String alias, |
|
435 |
java.security.cert.Certificate cert) |
|
436 |
throws KeyStoreException { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
437 |
jks.setCertificateEntry(alias, cert); |
2 | 438 |
} |
439 |
||
440 |
public void engineDeleteEntry(String alias) |
|
441 |
throws KeyStoreException { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
442 |
jks.deleteEntry(alias); |
2 | 443 |
} |
444 |
||
445 |
public Enumeration engineAliases() { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
446 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
447 |
return jks.aliases(); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
448 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
449 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
450 |
} |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
451 |
|
2 | 452 |
} |
453 |
||
454 |
public boolean engineContainsAlias(String alias) { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
455 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
456 |
return jks.containsAlias(alias); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
457 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
458 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
459 |
} |
2 | 460 |
} |
461 |
||
462 |
public int engineSize() { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
463 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
464 |
return jks.size(); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
465 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
466 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
467 |
} |
2 | 468 |
} |
469 |
||
470 |
public boolean engineIsKeyEntry(String alias) { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
471 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
472 |
return jks.isKeyEntry(alias); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
473 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
474 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
475 |
} |
2 | 476 |
} |
477 |
||
478 |
public boolean engineIsCertificateEntry(String alias) { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
479 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
480 |
return jks.isCertificateEntry(alias); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
481 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
482 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
483 |
} |
2 | 484 |
} |
485 |
||
486 |
public String engineGetCertificateAlias |
|
487 |
(java.security.cert.Certificate cert) { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
488 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
489 |
return jks.getCertificateAlias(cert); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
490 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
491 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
492 |
} |
2 | 493 |
} |
494 |
||
495 |
public void engineStore(OutputStream stream, char[] password) |
|
496 |
throws IOException, NoSuchAlgorithmException, CertificateException { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
497 |
try { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
498 |
jks.store(stream, password); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
499 |
} catch (KeyStoreException ke) { |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
500 |
throw new RuntimeException("Unexpected exception", ke); |
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
501 |
} |
2 | 502 |
} |
503 |
||
504 |
public void engineLoad(InputStream stream, char[] password) |
|
505 |
throws IOException, NoSuchAlgorithmException, CertificateException { |
|
31422
67cd03bc9cce
8130007: Update security tests to use Security.getProvider to get security provider
mchung
parents:
5506
diff
changeset
|
506 |
jks.load(stream, password); |
2 | 507 |
} |
508 |
} |
|
509 |
||
510 |
public static class Post15 extends Pre15 { |
|
511 |
||
512 |
public void engineStore(KeyStore.LoadStoreParameter parameter) |
|
513 |
throws IOException, NoSuchAlgorithmException, CertificateException { |
|
514 |
if (!(parameter instanceof EntryMethods.FooParameter)) { |
|
515 |
throw new IOException("Post15 engineStore method expected " + |
|
516 |
"FooParameter"); |
|
517 |
} |
|
518 |
} |
|
519 |
||
520 |
public void engineLoad(KeyStore.LoadStoreParameter parameter) |
|
521 |
throws IOException, NoSuchAlgorithmException, CertificateException { |
|
522 |
if (!(parameter instanceof EntryMethods.FooParameter)) { |
|
523 |
throw new IOException("Post15 engineLoadFrom method expected " + |
|
524 |
"FooParameter"); |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
public KeyStore.Entry engineGetEntry(String alias, |
|
529 |
KeyStore.ProtectionParameter protectionParam) |
|
530 |
throws UnrecoverableEntryException { |
|
531 |
if (!alias.equals("foo")) { |
|
532 |
throw new SecurityException |
|
533 |
("Post15 engineGetEntry(String, ProtectionParam) " + |
|
534 |
"expected [foo] alias"); |
|
535 |
} |
|
536 |
KeyStore.PasswordProtection pwdParam = |
|
537 |
(KeyStore.PasswordProtection)protectionParam; |
|
538 |
if (pwdParam.getPassword().length != 6) { |
|
539 |
throw new SecurityException |
|
540 |
("Post15 engineGetEntry(String, ProtectionParam) " + |
|
541 |
"expected [foobar] password"); |
|
542 |
} |
|
543 |
||
544 |
return new EntryMethods.FooEntry(); |
|
545 |
} |
|
546 |
||
547 |
public void engineSetEntry(String alias, KeyStore.Entry entry, |
|
548 |
KeyStore.ProtectionParameter protectionParam) { |
|
549 |
if (!alias.equals("foo") || |
|
550 |
!(entry instanceof EntryMethods.FooEntry)) { |
|
551 |
throw new SecurityException |
|
552 |
("Post15 engineSetEntry(String, entry, ProtParm) " + |
|
553 |
"expected [foo] alias and EntryMethods.FooEntry"); |
|
554 |
} |
|
555 |
||
556 |
KeyStore.PasswordProtection pwdParam = |
|
557 |
(KeyStore.PasswordProtection)protectionParam; |
|
558 |
if (pwdParam.getPassword().length != 6) { |
|
559 |
throw new SecurityException |
|
560 |
("Post15 engineSetEntry(String, entry, ProtParm) " + |
|
561 |
"expected [foobar] password"); |
|
562 |
} |
|
563 |
} |
|
564 |
||
565 |
public boolean engineEntryInstanceOf(String alias, |
|
566 |
Class<? extends KeyStore.Entry> entryClass) |
|
567 |
{ |
|
568 |
if (!alias.equals("foo") || |
|
569 |
entryClass != KeyStore.PrivateKeyEntry.class) { |
|
570 |
throw new SecurityException |
|
571 |
("Post15 engineEntryInstanceOf(String, Class) " + |
|
572 |
"expected [foo] alias " + |
|
573 |
"and [KeyStore.PrivateKeyEntry] class"); |
|
574 |
} |
|
575 |
return true; |
|
576 |
} |
|
577 |
} |
|
578 |
||
579 |
public static class UnrecoverableKS extends Post15 { |
|
580 |
public KeyStore.Entry engineGetEntry(String alias, |
|
581 |
KeyStore.ProtectionParameter protectionParam) |
|
582 |
throws UnrecoverableEntryException { |
|
583 |
throw new UnrecoverableEntryException(); |
|
584 |
} |
|
585 |
} |
|
586 |
} |