1 /* 2 * Copyright (c) 2014, 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 30 import java.security.Provider; 31 import java.security.Security; 32 import java.util.ArrayList; 33 import java.util.Iterator; 34 import 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 */ 42 public 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 expected.add("com.oracle.security.ucrypto.UcryptoProvider"); 57 expected.add("sun.security.pkcs11.SunPKCS11"); 58 } 59 expected.add("sun.security.provider.Sun"); 60 expected.add("sun.security.rsa.SunRsaSign"); 61 expected.add("sun.security.ec.SunEC"); 62 expected.add("com.sun.net.ssl.internal.ssl.Provider"); 63 expected.add("com.sun.crypto.provider.SunJCE"); 64 expected.add("sun.security.jgss.SunProvider"); 65 expected.add("com.sun.security.sasl.Provider"); 66 expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI"); 67 expected.add("sun.security.smartcardio.SunPCSC"); 68 if (os.startsWith("Windows")) { 69 expected.add("sun.security.mscapi.SunMSCAPI"); 70 } 71 if (os.contains("OS X")) { 72 expected.add("apple.security.AppleProvider"); 73 } 74 75 Iterator<String> iter = expected.iterator(); 76 for (Provider p: Security.getProviders()) { 77 if (!iter.hasNext()) { 78 throw new Exception("Less expected"); 79 } 80 String n1 = iter.next(); 81 String n2 = p.getClass().getName(); 82 if (!n1.equals(n2)) { 83 throw new Exception("Expected " + n1 + ", actual " + n2); 84 } 85 } 86 if (iter.hasNext()) { 87 throw new Exception("More expected"); 88 } 89 } 90 }