equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /** |
24 /** |
25 * @see AccessKeyStore.sh |
25 * @test |
|
26 * @bug 6324295 6931562 8154113 |
|
27 * @modules jdk.crypto.mscapi |
|
28 * @run main/othervm/java.security.policy==access.policy AccessKeyStore pass |
|
29 * @run main/othervm/java.security.policy==noaccess.policy AccessKeyStore fail |
|
30 * @summary Confirm that right permissions are granted to access keystores. |
26 */ |
31 */ |
27 |
32 |
28 import java.security.Provider; |
33 import java.security.Provider; |
29 import java.security.*; |
34 import java.security.*; |
30 import java.security.cert.*; |
35 import java.security.cert.*; |
34 |
39 |
35 public class AccessKeyStore { |
40 public class AccessKeyStore { |
36 |
41 |
37 public static void main(String[] args) throws Exception { |
42 public static void main(String[] args) throws Exception { |
38 |
43 |
39 // Check that a security manager has been installed |
44 // Check for security manager and required arg(s) |
40 if (System.getSecurityManager() == null) { |
45 if (System.getSecurityManager() == null) { |
41 throw new Exception("A security manager has not been installed"); |
46 throw new Exception("Missing security manager"); |
42 } |
47 } |
|
48 if (args.length <= 0) { |
|
49 throw new Exception("Missing expected test status"); |
|
50 } |
|
51 boolean shouldPass = args[0].equalsIgnoreCase("pass"); |
43 |
52 |
44 Provider p = Security.getProvider("SunMSCAPI"); |
53 Provider p = Security.getProvider("SunMSCAPI"); |
45 |
|
46 System.out.println("SunMSCAPI provider classname is " + |
54 System.out.println("SunMSCAPI provider classname is " + |
47 p.getClass().getName()); |
55 p.getClass().getName()); |
48 |
56 |
49 KeyStore keyStore = KeyStore.getInstance("Windows-MY", p); |
57 KeyStore keyStore = KeyStore.getInstance("Windows-MY", p); |
50 |
58 |
54 * been granted: |
62 * been granted: |
55 * |
63 * |
56 * SecurityPermission("authProvider.SunMSCAPI") |
64 * SecurityPermission("authProvider.SunMSCAPI") |
57 */ |
65 */ |
58 try { |
66 try { |
59 |
|
60 keyStore.load(null, null); |
67 keyStore.load(null, null); |
61 |
68 if (!shouldPass) { |
62 if (args.length > 0 && "-deny".equals(args[0])) { |
|
63 throw new Exception( |
69 throw new Exception( |
64 "Expected KeyStore.load to throw a SecurityException"); |
70 "Expected KeyStore.load to throw a SecurityException"); |
65 } |
71 } |
66 |
|
67 } catch (SecurityException se) { |
72 } catch (SecurityException se) { |
68 |
73 if (!shouldPass) { |
69 if (args.length > 0 && "-deny".equals(args[0])) { |
74 System.out.println("Expected exception thrown: " + se); |
70 System.out.println("Caught the expected exception: " + se); |
|
71 return; |
75 return; |
72 } else { |
76 } else { |
73 throw se; |
77 throw se; |
74 } |
78 } |
75 } |
79 } |