CheckSecurityProvider.java revision 11963:c5d10830cfb9
1/*
2 * Copyright (c) 2014, 2015, 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 6997010
27 * @summary Consolidate java.security files into one file with modifications
28 */
29
30import java.security.Provider;
31import java.security.Security;
32import java.util.ArrayList;
33import java.util.Iterator;
34import java.util.List;
35
36/*
37 * The main benefit of this test is to catch merge errors or other types
38 * of issues where one or more of the security providers are accidentally
39 * removed. This is why the known security providers have to
40 * be explicitly listed below.
41 */
42public class CheckSecurityProvider {
43    public static void main(String[] args) throws Exception {
44
45        String os = System.getProperty("os.name");
46
47        /*
48         * This array should be updated whenever new security providers
49         * are added to the the java.security file.
50         * NOTE: it should be in the same order as the java.security file
51         */
52
53        List<String> expected = new ArrayList<>();
54
55        if (os.equals("SunOS")) {
56            if (!isOpenJDKOnly()) {
57                expected.add("com.oracle.security.ucrypto.UcryptoProvider");
58            }
59            expected.add("sun.security.pkcs11.SunPKCS11");
60        }
61        expected.add("sun.security.provider.Sun");
62        expected.add("sun.security.rsa.SunRsaSign");
63        expected.add("sun.security.ec.SunEC");
64        expected.add("com.sun.net.ssl.internal.ssl.Provider");
65        expected.add("com.sun.crypto.provider.SunJCE");
66        expected.add("sun.security.jgss.SunProvider");
67        expected.add("com.sun.security.sasl.Provider");
68        expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI");
69        expected.add("sun.security.smartcardio.SunPCSC");
70        expected.add("sun.security.provider.certpath.ldap.JdkLDAP");
71        if (os.startsWith("Windows")) {
72            expected.add("sun.security.mscapi.SunMSCAPI");
73        }
74        if (os.contains("OS X")) {
75            expected.add("apple.security.AppleProvider");
76        }
77
78        Iterator<String> iter = expected.iterator();
79        for (Provider p: Security.getProviders()) {
80            if (!iter.hasNext()) {
81                throw new Exception("Less expected");
82            }
83            String n1 = iter.next();
84            String n2 = p.getClass().getName();
85            if (!n1.equals(n2)) {
86                throw new Exception("Expected " + n1 + ", actual " + n2);
87            }
88        }
89        if (iter.hasNext()) {
90            throw new Exception("More expected");
91        }
92    }
93
94    // Copied from CheckPackageAccess.java in the same directory
95    private static boolean isOpenJDKOnly() {
96        String prop = System.getProperty("java.runtime.name");
97        return prop != null && prop.startsWith("OpenJDK");
98    }
99}
100