1 /*
2 * Copyright (c) 2014, 2016, 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 */
45 */
46 public class CheckSecurityProvider {
47 public static void main(String[] args) throws Exception {
48 Layer layer = Layer.boot();
49
50 System.setSecurityManager(new SecurityManager());
51
52 String os = System.getProperty("os.name");
53 /*
54 * This array should be updated whenever new security providers
55 * are added to the the java.security file.
56 * NOTE: it should be in the same order as the java.security file
57 */
58
59 List<String> expected = new ArrayList<>();
60
61 // NOTE: the ordering must match what's defined inside java.security
62 if (os.equals("SunOS")) {
63 layer.findModule("jdk.crypto.ucrypto")
64 .ifPresent(m -> expected.add("com.oracle.security.ucrypto.UcryptoProvider"));
65 layer.findModule("jdk.crypto.token")
66 .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
67 }
68 expected.add("sun.security.provider.Sun");
69 expected.add("sun.security.rsa.SunRsaSign");
70 layer.findModule("jdk.crypto.ec")
71 .ifPresent(m -> expected.add("sun.security.ec.SunEC"));
72 expected.add("com.sun.net.ssl.internal.ssl.Provider");
73 expected.add("com.sun.crypto.provider.SunJCE");
74 layer.findModule("jdk.security.jgss")
75 .ifPresent(m -> expected.add("sun.security.jgss.SunProvider"));
76 layer.findModule("java.security.sasl")
77 .ifPresent(m -> expected.add("com.sun.security.sasl.Provider"));
78 layer.findModule("java.xml.crypto")
79 .ifPresent(m -> expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI"));
80 layer.findModule("java.smartcardio")
81 .ifPresent(m -> expected.add("sun.security.smartcardio.SunPCSC"));
82 layer.findModule("java.naming")
83 .ifPresent(m -> expected.add("sun.security.provider.certpath.ldap.JdkLDAP"));
84 layer.findModule("jdk.security.jgss")
85 .ifPresent(m -> expected.add("com.sun.security.sasl.gsskerb.JdkSASL"));
86 if (os.startsWith("Windows")) {
87 layer.findModule("jdk.crypto.mscapi")
88 .ifPresent(m -> expected.add("sun.security.mscapi.SunMSCAPI"));
89 }
90 if (os.contains("OS X")) {
91 expected.add("apple.security.AppleProvider");
92 }
93 if (!os.equals("SunOS")) {
94 layer.findModule("jdk.crypto.token")
95 .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
96 }
97
98 List<String> actual = Stream.of(Security.getProviders())
99 .map(p -> p.getClass().getName())
100 .collect(Collectors.toList());
101
102 System.out.println("Expected providers:");
103 expected.stream().forEach(System.out::println);
104 System.out.println("Actual providers:");
105 actual.stream().forEach(System.out::println);
106
107 if (expected.size() != actual.size()) {
108 throw new Exception("Unexpected provider count. "
109 + "Expected: " + expected.size() + ". Actual: " + actual.size());
110 }
111 Iterator<String> iter = expected.iterator();
112 for (String p: actual) {
113 String nextExpected = iter.next();
114 if (!nextExpected.equals(p)) {
|
1 /*
2 * Copyright (c) 2014, 2017, 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 */
45 */
46 public class CheckSecurityProvider {
47 public static void main(String[] args) throws Exception {
48 Layer layer = Layer.boot();
49
50 System.setSecurityManager(new SecurityManager());
51
52 String os = System.getProperty("os.name");
53 /*
54 * This array should be updated whenever new security providers
55 * are added to the the java.security file.
56 * NOTE: it should be in the same order as the java.security file
57 */
58
59 List<String> expected = new ArrayList<>();
60
61 // NOTE: the ordering must match what's defined inside java.security
62 if (os.equals("SunOS")) {
63 layer.findModule("jdk.crypto.ucrypto")
64 .ifPresent(m -> expected.add("com.oracle.security.ucrypto.UcryptoProvider"));
65 layer.findModule("jdk.crypto.cryptoki")
66 .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
67 }
68 expected.add("sun.security.provider.Sun");
69 expected.add("sun.security.rsa.SunRsaSign");
70 layer.findModule("jdk.crypto.ec")
71 .ifPresent(m -> expected.add("sun.security.ec.SunEC"));
72 expected.add("com.sun.net.ssl.internal.ssl.Provider");
73 expected.add("com.sun.crypto.provider.SunJCE");
74 layer.findModule("jdk.security.jgss")
75 .ifPresent(m -> expected.add("sun.security.jgss.SunProvider"));
76 layer.findModule("java.security.sasl")
77 .ifPresent(m -> expected.add("com.sun.security.sasl.Provider"));
78 layer.findModule("java.xml.crypto")
79 .ifPresent(m -> expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI"));
80 layer.findModule("java.smartcardio")
81 .ifPresent(m -> expected.add("sun.security.smartcardio.SunPCSC"));
82 layer.findModule("java.naming")
83 .ifPresent(m -> expected.add("sun.security.provider.certpath.ldap.JdkLDAP"));
84 layer.findModule("jdk.security.jgss")
85 .ifPresent(m -> expected.add("com.sun.security.sasl.gsskerb.JdkSASL"));
86 if (os.startsWith("Windows")) {
87 layer.findModule("jdk.crypto.mscapi")
88 .ifPresent(m -> expected.add("sun.security.mscapi.SunMSCAPI"));
89 }
90 if (os.contains("OS X")) {
91 expected.add("apple.security.AppleProvider");
92 }
93 if (!os.equals("SunOS")) {
94 layer.findModule("jdk.crypto.cryptoki")
95 .ifPresent(m -> expected.add("sun.security.pkcs11.SunPKCS11"));
96 }
97
98 List<String> actual = Stream.of(Security.getProviders())
99 .map(p -> p.getClass().getName())
100 .collect(Collectors.toList());
101
102 System.out.println("Expected providers:");
103 expected.stream().forEach(System.out::println);
104 System.out.println("Actual providers:");
105 actual.stream().forEach(System.out::println);
106
107 if (expected.size() != actual.size()) {
108 throw new Exception("Unexpected provider count. "
109 + "Expected: " + expected.size() + ". Actual: " + actual.size());
110 }
111 Iterator<String> iter = expected.iterator();
112 for (String p: actual) {
113 String nextExpected = iter.next();
114 if (!nextExpected.equals(p)) {
|