author | weijun |
Mon, 11 Aug 2014 11:11:55 +0800 | |
changeset 25974 | 850dc36ea410 |
child 30506 | 1998a5644f50 |
permissions | -rw-r--r-- |
25974
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
1 |
/* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
4 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
8 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
14 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
18 |
* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
21 |
* questions. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
22 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
23 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
24 |
/* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
25 |
* @test |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
26 |
* @bug 6997010 |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
27 |
* @summary Consolidate java.security files into one file with modifications |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
28 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
29 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
30 |
import java.security.Provider; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
31 |
import java.security.Security; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
32 |
import java.util.ArrayList; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
33 |
import java.util.Iterator; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
34 |
import java.util.List; |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
35 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
36 |
/* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
37 |
* The main benefit of this test is to catch merge errors or other types |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
38 |
* of issues where one or more of the security providers are accidentally |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
39 |
* removed. This is why the known security providers have to |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
40 |
* be explicitly listed below. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
41 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
42 |
public class CheckSecurityProvider { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
43 |
public static void main(String[] args) throws Exception { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
44 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
45 |
String os = System.getProperty("os.name"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
46 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
47 |
/* |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
48 |
* This array should be updated whenever new security providers |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
49 |
* are added to the the java.security file. |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
50 |
* NOTE: it should be in the same order as the java.security file |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
51 |
*/ |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
52 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
53 |
List<String> expected = new ArrayList<>(); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
54 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
55 |
if (os.equals("SunOS")) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
56 |
if (!isOpenJDKOnly()) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
57 |
expected.add("com.oracle.security.ucrypto.UcryptoProvider"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
58 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
59 |
expected.add("sun.security.pkcs11.SunPKCS11"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
60 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
61 |
expected.add("sun.security.provider.Sun"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
62 |
expected.add("sun.security.rsa.SunRsaSign"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
63 |
expected.add("sun.security.ec.SunEC"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
64 |
expected.add("com.sun.net.ssl.internal.ssl.Provider"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
65 |
expected.add("com.sun.crypto.provider.SunJCE"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
66 |
expected.add("sun.security.jgss.SunProvider"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
67 |
expected.add("com.sun.security.sasl.Provider"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
68 |
expected.add("org.jcp.xml.dsig.internal.dom.XMLDSigRI"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
69 |
expected.add("sun.security.smartcardio.SunPCSC"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
70 |
if (os.startsWith("Windows")) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
71 |
expected.add("sun.security.mscapi.SunMSCAPI"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
72 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
73 |
if (os.contains("OS X")) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
74 |
expected.add("apple.security.AppleProvider"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
75 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
76 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
77 |
Iterator<String> iter = expected.iterator(); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
78 |
for (Provider p: Security.getProviders()) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
79 |
if (!iter.hasNext()) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
80 |
throw new Exception("Less expected"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
81 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
82 |
String n1 = iter.next(); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
83 |
String n2 = p.getClass().getName(); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
84 |
if (!n1.equals(n2)) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
85 |
throw new Exception("Expected " + n1 + ", actual " + n2); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
86 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
87 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
88 |
if (iter.hasNext()) { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
89 |
throw new Exception("More expected"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
90 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
91 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
92 |
|
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
93 |
// Copied from CheckPackageAccess.java in the same directory |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
94 |
private static boolean isOpenJDKOnly() { |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
95 |
String prop = System.getProperty("java.runtime.name"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
96 |
return prop != null && prop.startsWith("OpenJDK"); |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
97 |
} |
850dc36ea410
6997010: Consolidate java.security files into one file with modifications
weijun
parents:
diff
changeset
|
98 |
} |