author | lana |
Thu, 11 Sep 2014 14:28:19 -0700 | |
changeset 26520 | abaac15e3bd1 |
parent 23052 | 241885315119 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
8791
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
8791
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
26 |
* @bug 4898428 7022855 |
2 | 27 |
* @summary verify getInstance() works using Provider.getService() |
8791
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
28 |
* Export "PKIX" as the standard algorithm name of KeyManagerFactory |
2 | 29 |
* @author Andreas Sterbenz |
30 |
*/ |
|
31 |
||
32 |
import java.security.*; |
|
33 |
||
34 |
import javax.net.ssl.*; |
|
35 |
||
36 |
public class GetInstance { |
|
37 |
||
38 |
private static void same(Provider p1, Provider p2) throws Exception { |
|
39 |
if (p1 != p2) { |
|
40 |
throw new Exception("not same object"); |
|
41 |
} |
|
42 |
} |
|
43 |
||
44 |
public static void main(String[] args) throws Exception { |
|
45 |
long start = System.currentTimeMillis(); |
|
46 |
||
47 |
Provider p = Security.getProvider("SunJSSE"); |
|
48 |
||
49 |
SSLContext context; |
|
50 |
context = SSLContext.getInstance("SSL"); |
|
51 |
same(p, context.getProvider()); |
|
52 |
context = SSLContext.getInstance("SSL", "SunJSSE"); |
|
53 |
same(p, context.getProvider()); |
|
54 |
context = SSLContext.getInstance("SSL", p); |
|
55 |
same(p, context.getProvider()); |
|
56 |
||
57 |
KeyManagerFactory kmf; |
|
58 |
kmf = KeyManagerFactory.getInstance("SunX509"); |
|
59 |
same(p, kmf.getProvider()); |
|
60 |
kmf = KeyManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
61 |
same(p, kmf.getProvider()); |
|
62 |
kmf = KeyManagerFactory.getInstance("SunX509", p); |
|
63 |
same(p, kmf.getProvider()); |
|
64 |
||
8791
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
65 |
kmf = KeyManagerFactory.getInstance("NewSunX509"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
66 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
67 |
kmf = KeyManagerFactory.getInstance("NewSunX509", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
68 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
69 |
kmf = KeyManagerFactory.getInstance("NewSunX509", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
70 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
71 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
72 |
kmf = KeyManagerFactory.getInstance("PKIX"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
73 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
74 |
kmf = KeyManagerFactory.getInstance("PKIX", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
75 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
76 |
kmf = KeyManagerFactory.getInstance("PKIX", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
77 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
78 |
|
2 | 79 |
TrustManagerFactory tmf; |
80 |
tmf = TrustManagerFactory.getInstance("SunX509"); |
|
81 |
same(p, tmf.getProvider()); |
|
82 |
tmf = TrustManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
83 |
same(p, tmf.getProvider()); |
|
84 |
tmf = TrustManagerFactory.getInstance("SunX509", p); |
|
85 |
same(p, tmf.getProvider()); |
|
86 |
||
8791
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
87 |
tmf = TrustManagerFactory.getInstance("PKIX"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
88 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
89 |
tmf = TrustManagerFactory.getInstance("PKIX", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
90 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
91 |
tmf = TrustManagerFactory.getInstance("PKIX", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
92 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
93 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
94 |
tmf = TrustManagerFactory.getInstance("SunPKIX"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
95 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
96 |
tmf = TrustManagerFactory.getInstance("SunPKIX", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
97 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
98 |
tmf = TrustManagerFactory.getInstance("SunPKIX", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
99 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
100 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
101 |
tmf = TrustManagerFactory.getInstance("X509"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
102 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
103 |
tmf = TrustManagerFactory.getInstance("X509", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
104 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
105 |
tmf = TrustManagerFactory.getInstance("X509", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
106 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
107 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
108 |
tmf = TrustManagerFactory.getInstance("X.509"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
109 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
110 |
tmf = TrustManagerFactory.getInstance("X.509", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
111 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
112 |
tmf = TrustManagerFactory.getInstance("X.509", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
113 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
114 |
|
2 | 115 |
testComSun(); |
116 |
||
117 |
long stop = System.currentTimeMillis(); |
|
118 |
System.out.println("Done (" + (stop - start) + " ms)."); |
|
119 |
} |
|
120 |
||
121 |
private static void testComSun() throws Exception { |
|
122 |
Provider p = Security.getProvider("SunJSSE"); |
|
123 |
||
124 |
com.sun.net.ssl.SSLContext context; |
|
125 |
context = com.sun.net.ssl.SSLContext.getInstance("SSL"); |
|
126 |
same(p, context.getProvider()); |
|
127 |
context = com.sun.net.ssl.SSLContext.getInstance("SSL", "SunJSSE"); |
|
128 |
same(p, context.getProvider()); |
|
129 |
context = com.sun.net.ssl.SSLContext.getInstance("SSL", p); |
|
130 |
same(p, context.getProvider()); |
|
131 |
||
132 |
com.sun.net.ssl.KeyManagerFactory kmf; |
|
133 |
kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509"); |
|
134 |
same(p, kmf.getProvider()); |
|
135 |
kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
136 |
same(p, kmf.getProvider()); |
|
137 |
kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509", p); |
|
138 |
same(p, kmf.getProvider()); |
|
139 |
||
140 |
com.sun.net.ssl.TrustManagerFactory tmf; |
|
141 |
tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509"); |
|
142 |
same(p, tmf.getProvider()); |
|
143 |
tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
144 |
same(p, tmf.getProvider()); |
|
145 |
tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509", p); |
|
146 |
same(p, tmf.getProvider()); |
|
147 |
} |
|
148 |
||
149 |
} |