author | dbuck |
Tue, 18 Aug 2015 04:29:28 -0700 | |
changeset 32417 | 6859107fc6c3 |
parent 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 |
30820 | 30 |
* @modules java.base/com.sun.net.ssl |
2 | 31 |
*/ |
32 |
||
33 |
import java.security.*; |
|
34 |
||
35 |
import javax.net.ssl.*; |
|
36 |
||
37 |
public class GetInstance { |
|
38 |
||
39 |
private static void same(Provider p1, Provider p2) throws Exception { |
|
40 |
if (p1 != p2) { |
|
41 |
throw new Exception("not same object"); |
|
42 |
} |
|
43 |
} |
|
44 |
||
45 |
public static void main(String[] args) throws Exception { |
|
46 |
long start = System.currentTimeMillis(); |
|
47 |
||
48 |
Provider p = Security.getProvider("SunJSSE"); |
|
49 |
||
50 |
SSLContext context; |
|
51 |
context = SSLContext.getInstance("SSL"); |
|
52 |
same(p, context.getProvider()); |
|
53 |
context = SSLContext.getInstance("SSL", "SunJSSE"); |
|
54 |
same(p, context.getProvider()); |
|
55 |
context = SSLContext.getInstance("SSL", p); |
|
56 |
same(p, context.getProvider()); |
|
57 |
||
58 |
KeyManagerFactory kmf; |
|
59 |
kmf = KeyManagerFactory.getInstance("SunX509"); |
|
60 |
same(p, kmf.getProvider()); |
|
61 |
kmf = KeyManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
62 |
same(p, kmf.getProvider()); |
|
63 |
kmf = KeyManagerFactory.getInstance("SunX509", p); |
|
64 |
same(p, kmf.getProvider()); |
|
65 |
||
8791
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
66 |
kmf = KeyManagerFactory.getInstance("NewSunX509"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
67 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
68 |
kmf = KeyManagerFactory.getInstance("NewSunX509", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
69 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
70 |
kmf = KeyManagerFactory.getInstance("NewSunX509", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
71 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
72 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
73 |
kmf = KeyManagerFactory.getInstance("PKIX"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
74 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
75 |
kmf = KeyManagerFactory.getInstance("PKIX", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
76 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
77 |
kmf = KeyManagerFactory.getInstance("PKIX", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
78 |
same(p, kmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
79 |
|
2 | 80 |
TrustManagerFactory tmf; |
81 |
tmf = TrustManagerFactory.getInstance("SunX509"); |
|
82 |
same(p, tmf.getProvider()); |
|
83 |
tmf = TrustManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
84 |
same(p, tmf.getProvider()); |
|
85 |
tmf = TrustManagerFactory.getInstance("SunX509", p); |
|
86 |
same(p, tmf.getProvider()); |
|
87 |
||
8791
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
88 |
tmf = TrustManagerFactory.getInstance("PKIX"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
89 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
90 |
tmf = TrustManagerFactory.getInstance("PKIX", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
91 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
92 |
tmf = TrustManagerFactory.getInstance("PKIX", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
93 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
94 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
95 |
tmf = TrustManagerFactory.getInstance("SunPKIX"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
96 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
97 |
tmf = TrustManagerFactory.getInstance("SunPKIX", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
98 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
99 |
tmf = TrustManagerFactory.getInstance("SunPKIX", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
100 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
101 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
102 |
tmf = TrustManagerFactory.getInstance("X509"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
103 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
104 |
tmf = TrustManagerFactory.getInstance("X509", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
105 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
106 |
tmf = TrustManagerFactory.getInstance("X509", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
107 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
108 |
|
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
109 |
tmf = TrustManagerFactory.getInstance("X.509"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
110 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
111 |
tmf = TrustManagerFactory.getInstance("X.509", "SunJSSE"); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
112 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
113 |
tmf = TrustManagerFactory.getInstance("X.509", p); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
114 |
same(p, tmf.getProvider()); |
f5106bbf577d
7022855: Export "PKIX" as the standard algorithm name of KeyManagerFactory
xuelei
parents:
5506
diff
changeset
|
115 |
|
2 | 116 |
testComSun(); |
117 |
||
118 |
long stop = System.currentTimeMillis(); |
|
119 |
System.out.println("Done (" + (stop - start) + " ms)."); |
|
120 |
} |
|
121 |
||
122 |
private static void testComSun() throws Exception { |
|
123 |
Provider p = Security.getProvider("SunJSSE"); |
|
124 |
||
125 |
com.sun.net.ssl.SSLContext context; |
|
126 |
context = com.sun.net.ssl.SSLContext.getInstance("SSL"); |
|
127 |
same(p, context.getProvider()); |
|
128 |
context = com.sun.net.ssl.SSLContext.getInstance("SSL", "SunJSSE"); |
|
129 |
same(p, context.getProvider()); |
|
130 |
context = com.sun.net.ssl.SSLContext.getInstance("SSL", p); |
|
131 |
same(p, context.getProvider()); |
|
132 |
||
133 |
com.sun.net.ssl.KeyManagerFactory kmf; |
|
134 |
kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509"); |
|
135 |
same(p, kmf.getProvider()); |
|
136 |
kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
137 |
same(p, kmf.getProvider()); |
|
138 |
kmf = com.sun.net.ssl.KeyManagerFactory.getInstance("SunX509", p); |
|
139 |
same(p, kmf.getProvider()); |
|
140 |
||
141 |
com.sun.net.ssl.TrustManagerFactory tmf; |
|
142 |
tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509"); |
|
143 |
same(p, tmf.getProvider()); |
|
144 |
tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509", "SunJSSE"); |
|
145 |
same(p, tmf.getProvider()); |
|
146 |
tmf = com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509", p); |
|
147 |
same(p, tmf.getProvider()); |
|
148 |
} |
|
149 |
||
150 |
} |