author | xuelei |
Fri, 08 Apr 2011 02:00:09 -0700 | |
changeset 9246 | c459f79af46b |
parent 7043 | 5e2d1edeb2c7 |
child 10125 | c70d99150c40 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
2 |
* Copyright (c) 1999, 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.ssl; |
|
27 |
||
28 |
import java.net.Socket; |
|
29 |
||
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
30 |
import java.io.*; |
7043 | 31 |
import java.util.*; |
2 | 32 |
import java.security.*; |
33 |
import java.security.cert.*; |
|
7043 | 34 |
import java.security.cert.Certificate; |
2 | 35 |
|
36 |
import javax.net.ssl.*; |
|
37 |
||
7043 | 38 |
import sun.security.provider.certpath.AlgorithmChecker; |
39 |
||
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
40 |
public abstract class SSLContextImpl extends SSLContextSpi { |
2 | 41 |
|
42 |
private static final Debug debug = Debug.getInstance("ssl"); |
|
43 |
||
44 |
private final EphemeralKeyManager ephemeralKeyManager; |
|
45 |
private final SSLSessionContextImpl clientCache; |
|
46 |
private final SSLSessionContextImpl serverCache; |
|
47 |
||
48 |
private boolean isInitialized; |
|
49 |
||
50 |
private X509ExtendedKeyManager keyManager; |
|
51 |
private X509TrustManager trustManager; |
|
52 |
private SecureRandom secureRandom; |
|
53 |
||
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
54 |
// The default algrithm constraints |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
55 |
private AlgorithmConstraints defaultAlgorithmConstraints = |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
56 |
new SSLAlgorithmConstraints(null); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
57 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
58 |
// supported and default protocols |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
59 |
private ProtocolList defaultServerProtocolList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
60 |
private ProtocolList defaultClientProtocolList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
61 |
private ProtocolList supportedProtocolList; |
2 | 62 |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
63 |
// supported and default cipher suites |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
64 |
private CipherSuiteList defaultServerCipherSuiteList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
65 |
private CipherSuiteList defaultClientCipherSuiteList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
66 |
private CipherSuiteList supportedCipherSuiteList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
67 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
68 |
SSLContextImpl() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
69 |
ephemeralKeyManager = new EphemeralKeyManager(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
70 |
clientCache = new SSLSessionContextImpl(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
71 |
serverCache = new SSLSessionContextImpl(); |
2 | 72 |
} |
73 |
||
74 |
protected void engineInit(KeyManager[] km, TrustManager[] tm, |
|
75 |
SecureRandom sr) throws KeyManagementException { |
|
76 |
isInitialized = false; |
|
77 |
keyManager = chooseKeyManager(km); |
|
78 |
||
79 |
if (tm == null) { |
|
80 |
try { |
|
81 |
TrustManagerFactory tmf = TrustManagerFactory.getInstance( |
|
82 |
TrustManagerFactory.getDefaultAlgorithm()); |
|
83 |
tmf.init((KeyStore)null); |
|
84 |
tm = tmf.getTrustManagers(); |
|
85 |
} catch (Exception e) { |
|
86 |
// eat |
|
87 |
} |
|
88 |
} |
|
89 |
trustManager = chooseTrustManager(tm); |
|
90 |
||
91 |
if (sr == null) { |
|
92 |
secureRandom = JsseJce.getSecureRandom(); |
|
93 |
} else { |
|
7043 | 94 |
if (SunJSSE.isFIPS() && |
95 |
(sr.getProvider() != SunJSSE.cryptoProvider)) { |
|
2 | 96 |
throw new KeyManagementException |
97 |
("FIPS mode: SecureRandom must be from provider " |
|
98 |
+ SunJSSE.cryptoProvider.getName()); |
|
99 |
} |
|
100 |
secureRandom = sr; |
|
101 |
} |
|
102 |
||
103 |
/* |
|
104 |
* The initial delay of seeding the random number generator |
|
105 |
* could be long enough to cause the initial handshake on our |
|
106 |
* first connection to timeout and fail. Make sure it is |
|
107 |
* primed and ready by getting some initial output from it. |
|
108 |
*/ |
|
109 |
if (debug != null && Debug.isOn("sslctx")) { |
|
110 |
System.out.println("trigger seeding of SecureRandom"); |
|
111 |
} |
|
112 |
secureRandom.nextInt(); |
|
113 |
if (debug != null && Debug.isOn("sslctx")) { |
|
114 |
System.out.println("done seeding SecureRandom"); |
|
115 |
} |
|
116 |
isInitialized = true; |
|
117 |
} |
|
118 |
||
119 |
private X509TrustManager chooseTrustManager(TrustManager[] tm) |
|
120 |
throws KeyManagementException { |
|
121 |
// We only use the first instance of X509TrustManager passed to us. |
|
122 |
for (int i = 0; tm != null && i < tm.length; i++) { |
|
123 |
if (tm[i] instanceof X509TrustManager) { |
|
7043 | 124 |
if (SunJSSE.isFIPS() && |
125 |
!(tm[i] instanceof X509TrustManagerImpl)) { |
|
2 | 126 |
throw new KeyManagementException |
127 |
("FIPS mode: only SunJSSE TrustManagers may be used"); |
|
128 |
} |
|
7043 | 129 |
|
130 |
if (tm[i] instanceof X509ExtendedTrustManager) { |
|
131 |
return (X509TrustManager)tm[i]; |
|
132 |
} else { |
|
133 |
return new AbstractTrustManagerWrapper( |
|
134 |
(X509TrustManager)tm[i]); |
|
135 |
} |
|
2 | 136 |
} |
137 |
} |
|
138 |
||
139 |
// nothing found, return a dummy X509TrustManager. |
|
140 |
return DummyX509TrustManager.INSTANCE; |
|
141 |
} |
|
142 |
||
143 |
private X509ExtendedKeyManager chooseKeyManager(KeyManager[] kms) |
|
144 |
throws KeyManagementException { |
|
145 |
for (int i = 0; kms != null && i < kms.length; i++) { |
|
146 |
KeyManager km = kms[i]; |
|
147 |
if (km instanceof X509KeyManager == false) { |
|
148 |
continue; |
|
149 |
} |
|
150 |
if (SunJSSE.isFIPS()) { |
|
151 |
// In FIPS mode, require that one of SunJSSE's own keymanagers |
|
152 |
// is used. Otherwise, we cannot be sure that only keys from |
|
153 |
// the FIPS token are used. |
|
154 |
if ((km instanceof X509KeyManagerImpl) |
|
155 |
|| (km instanceof SunX509KeyManagerImpl)) { |
|
156 |
return (X509ExtendedKeyManager)km; |
|
157 |
} else { |
|
158 |
// throw exception, we don't want to silently use the |
|
159 |
// dummy keymanager without telling the user. |
|
160 |
throw new KeyManagementException |
|
161 |
("FIPS mode: only SunJSSE KeyManagers may be used"); |
|
162 |
} |
|
163 |
} |
|
164 |
if (km instanceof X509ExtendedKeyManager) { |
|
165 |
return (X509ExtendedKeyManager)km; |
|
166 |
} |
|
167 |
if (debug != null && Debug.isOn("sslctx")) { |
|
168 |
System.out.println( |
|
169 |
"X509KeyManager passed to " + |
|
170 |
"SSLContext.init(): need an " + |
|
171 |
"X509ExtendedKeyManager for SSLEngine use"); |
|
172 |
} |
|
7043 | 173 |
return new AbstractKeyManagerWrapper((X509KeyManager)km); |
2 | 174 |
} |
175 |
||
176 |
// nothing found, return a dummy X509ExtendedKeyManager |
|
177 |
return DummyX509KeyManager.INSTANCE; |
|
178 |
} |
|
179 |
||
180 |
protected SSLSocketFactory engineGetSocketFactory() { |
|
181 |
if (!isInitialized) { |
|
182 |
throw new IllegalStateException( |
|
183 |
"SSLContextImpl is not initialized"); |
|
184 |
} |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
185 |
return new SSLSocketFactoryImpl(this); |
2 | 186 |
} |
187 |
||
188 |
protected SSLServerSocketFactory engineGetServerSocketFactory() { |
|
189 |
if (!isInitialized) { |
|
190 |
throw new IllegalStateException("SSLContext is not initialized"); |
|
191 |
} |
|
192 |
return new SSLServerSocketFactoryImpl(this); |
|
193 |
} |
|
194 |
||
195 |
protected SSLEngine engineCreateSSLEngine() { |
|
196 |
if (!isInitialized) { |
|
197 |
throw new IllegalStateException( |
|
198 |
"SSLContextImpl is not initialized"); |
|
199 |
} |
|
200 |
return new SSLEngineImpl(this); |
|
201 |
} |
|
202 |
||
203 |
protected SSLEngine engineCreateSSLEngine(String host, int port) { |
|
204 |
if (!isInitialized) { |
|
205 |
throw new IllegalStateException( |
|
206 |
"SSLContextImpl is not initialized"); |
|
207 |
} |
|
208 |
return new SSLEngineImpl(this, host, port); |
|
209 |
} |
|
210 |
||
211 |
protected SSLSessionContext engineGetClientSessionContext() { |
|
212 |
return clientCache; |
|
213 |
} |
|
214 |
||
215 |
protected SSLSessionContext engineGetServerSessionContext() { |
|
216 |
return serverCache; |
|
217 |
} |
|
218 |
||
219 |
SecureRandom getSecureRandom() { |
|
220 |
return secureRandom; |
|
221 |
} |
|
222 |
||
223 |
X509ExtendedKeyManager getX509KeyManager() { |
|
224 |
return keyManager; |
|
225 |
} |
|
226 |
||
227 |
X509TrustManager getX509TrustManager() { |
|
228 |
return trustManager; |
|
229 |
} |
|
230 |
||
231 |
EphemeralKeyManager getEphemeralKeyManager() { |
|
232 |
return ephemeralKeyManager; |
|
233 |
} |
|
234 |
||
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
235 |
abstract SSLParameters getDefaultServerSSLParams(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
236 |
abstract SSLParameters getDefaultClientSSLParams(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
237 |
abstract SSLParameters getSupportedSSLParams(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
238 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
239 |
// Get suported ProtoclList. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
240 |
ProtocolList getSuportedProtocolList() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
241 |
if (supportedProtocolList == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
242 |
supportedProtocolList = |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
243 |
new ProtocolList(getSupportedSSLParams().getProtocols()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
244 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
245 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
246 |
return supportedProtocolList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
247 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
248 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
249 |
// Get default ProtoclList. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
250 |
ProtocolList getDefaultProtocolList(boolean roleIsServer) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
251 |
if (roleIsServer) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
252 |
if (defaultServerProtocolList == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
253 |
defaultServerProtocolList = new ProtocolList( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
254 |
getDefaultServerSSLParams().getProtocols()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
255 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
256 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
257 |
return defaultServerProtocolList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
258 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
259 |
if (defaultClientProtocolList == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
260 |
defaultClientProtocolList = new ProtocolList( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
261 |
getDefaultClientSSLParams().getProtocols()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
262 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
263 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
264 |
return defaultClientProtocolList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
265 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
266 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
267 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
268 |
// Get suported CipherSuiteList. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
269 |
CipherSuiteList getSuportedCipherSuiteList() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
270 |
// Clear cache of available ciphersuites. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
271 |
clearAvailableCache(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
272 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
273 |
if (supportedCipherSuiteList == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
274 |
supportedCipherSuiteList = |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
275 |
getApplicableCipherSuiteList(getSuportedProtocolList(), false); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
276 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
277 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
278 |
return supportedCipherSuiteList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
279 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
280 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
281 |
// Get default CipherSuiteList. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
282 |
CipherSuiteList getDefaultCipherSuiteList(boolean roleIsServer) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
283 |
// Clear cache of available ciphersuites. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
284 |
clearAvailableCache(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
285 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
286 |
if (roleIsServer) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
287 |
if (defaultServerCipherSuiteList == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
288 |
defaultServerCipherSuiteList = getApplicableCipherSuiteList( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
289 |
getDefaultProtocolList(true), true); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
290 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
291 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
292 |
return defaultServerCipherSuiteList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
293 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
294 |
if (defaultClientCipherSuiteList == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
295 |
defaultClientCipherSuiteList = getApplicableCipherSuiteList( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
296 |
getDefaultProtocolList(false), true); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
297 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
298 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
299 |
return defaultClientCipherSuiteList; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
300 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
301 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
302 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
303 |
/** |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
304 |
* Return whether a protocol list is the original default enabled |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
305 |
* protocols. See: SSLSocket/SSLEngine.setEnabledProtocols() |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
306 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
307 |
boolean isDefaultProtocolList(ProtocolList protocols) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
308 |
return (protocols == defaultServerProtocolList) || |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
309 |
(protocols == defaultClientProtocolList); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
310 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
311 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
312 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
313 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
314 |
* Return the list of all available CipherSuites with a priority of |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
315 |
* minPriority or above. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
316 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
317 |
private CipherSuiteList getApplicableCipherSuiteList( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
318 |
ProtocolList protocols, boolean onlyEnabled) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
319 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
320 |
int minPriority = CipherSuite.SUPPORTED_SUITES_PRIORITY; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
321 |
if (onlyEnabled) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
322 |
minPriority = CipherSuite.DEFAULT_SUITES_PRIORITY; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
323 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
324 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
325 |
Collection<CipherSuite> allowedCipherSuites = |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
326 |
CipherSuite.allowedCipherSuites(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
327 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
328 |
ArrayList<CipherSuite> suites = new ArrayList<>(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
329 |
if (!(protocols.collection().isEmpty()) && |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
330 |
protocols.min.v != ProtocolVersion.NONE.v) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
331 |
for (CipherSuite suite : allowedCipherSuites) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
332 |
if (suite.allowed == false || suite.priority < minPriority) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
333 |
continue; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
334 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
335 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
336 |
if (suite.isAvailable() && |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
337 |
suite.obsoleted > protocols.min.v && |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
338 |
suite.supported <= protocols.max.v) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
339 |
if (defaultAlgorithmConstraints.permits( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
340 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
341 |
suite.name, null)) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
342 |
suites.add(suite); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
343 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
344 |
} else if (debug != null && |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
345 |
Debug.isOn("sslctx") && Debug.isOn("verbose")) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
346 |
if (suite.obsoleted <= protocols.min.v) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
347 |
System.out.println( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
348 |
"Ignoring obsoleted cipher suite: " + suite); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
349 |
} else if (suite.supported > protocols.max.v) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
350 |
System.out.println( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
351 |
"Ignoring unsupported cipher suite: " + suite); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
352 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
353 |
System.out.println( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
354 |
"Ignoring unavailable cipher suite: " + suite); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
355 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
356 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
357 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
358 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
359 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
360 |
return new CipherSuiteList(suites); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
361 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
362 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
363 |
/** |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
364 |
* Clear cache of available ciphersuites. If we support all ciphers |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
365 |
* internally, there is no need to clear the cache and calling this |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
366 |
* method has no effect. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
367 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
368 |
synchronized void clearAvailableCache() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
369 |
if (CipherSuite.DYNAMIC_AVAILABILITY) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
370 |
supportedCipherSuiteList = null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
371 |
defaultServerCipherSuiteList = null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
372 |
defaultClientCipherSuiteList = null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
373 |
CipherSuite.BulkCipher.clearAvailableCache(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
374 |
JsseJce.clearEcAvailable(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
375 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
376 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
377 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
378 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
379 |
* The SSLContext implementation for TLS/SSL algorithm |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
380 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
381 |
* SSL/TLS protocols specify the forward compatibility and version |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
382 |
* roll-back attack protections, however, a number of SSL/TLS server |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
383 |
* vendors did not implement these aspects properly, and some current |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
384 |
* SSL/TLS servers may refuse to talk to a TLS 1.1 or later client. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
385 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
386 |
* Considering above interoperability issues, SunJSSE will not set |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
387 |
* TLS 1.1 and TLS 1.2 as the enabled protocols for client by default. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
388 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
389 |
* For SSL/TLS servers, there is no such interoperability issues as |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
390 |
* SSL/TLS clients. In SunJSSE, TLS 1.1 or later version will be the |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
391 |
* enabled protocols for server by default. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
392 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
393 |
* We may change the behavior when popular TLS/SSL vendors support TLS |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
394 |
* forward compatibility properly. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
395 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
396 |
* SSLv2Hello is no longer necessary. This interoperability option was |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
397 |
* put in place in the late 90's when SSLv3/TLS1.0 were relatively new |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
398 |
* and there were a fair number of SSLv2-only servers deployed. Because |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
399 |
* of the security issues in SSLv2, it is rarely (if ever) used, as |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
400 |
* deployments should now be using SSLv3 and TLSv1. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
401 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
402 |
* Considering the issues of SSLv2Hello, we should not enable SSLv2Hello |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
403 |
* by default. Applications still can use it by enabling SSLv2Hello with |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
404 |
* the series of setEnabledProtocols APIs. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
405 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
406 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
407 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
408 |
* The conservative SSLContext implementation for TLS, SSL, SSLv3 and |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
409 |
* TLS10 algorithm. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
410 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
411 |
* This is a super class of DefaultSSLContext and TLS10Context. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
412 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
413 |
* @see SSLContext |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
414 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
415 |
private static class ConservativeSSLContext extends SSLContextImpl { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
416 |
// parameters |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
417 |
private static SSLParameters defaultServerSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
418 |
private static SSLParameters defaultClientSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
419 |
private static SSLParameters supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
420 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
421 |
static { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
422 |
if (SunJSSE.isFIPS()) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
423 |
supportedSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
424 |
supportedSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
425 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
426 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
427 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
428 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
429 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
430 |
defaultServerSSLParams = supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
431 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
432 |
defaultClientSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
433 |
defaultClientSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
434 |
ProtocolVersion.TLS10.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
435 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
436 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
437 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
438 |
supportedSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
439 |
supportedSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
440 |
ProtocolVersion.SSL20Hello.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
441 |
ProtocolVersion.SSL30.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
442 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
443 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
444 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
445 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
446 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
447 |
defaultServerSSLParams = supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
448 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
449 |
defaultClientSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
450 |
defaultClientSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
451 |
ProtocolVersion.SSL30.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
452 |
ProtocolVersion.TLS10.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
453 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
454 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
455 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
456 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
457 |
SSLParameters getDefaultServerSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
458 |
return defaultServerSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
459 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
460 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
461 |
SSLParameters getDefaultClientSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
462 |
return defaultClientSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
463 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
464 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
465 |
SSLParameters getSupportedSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
466 |
return supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
467 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
468 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
469 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
470 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
471 |
* The SSLContext implementation for default algorithm |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
472 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
473 |
* @see SSLContext |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
474 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
475 |
public static final class DefaultSSLContext extends ConservativeSSLContext { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
476 |
private static final String NONE = "NONE"; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
477 |
private static final String P11KEYSTORE = "PKCS11"; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
478 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
479 |
private static volatile SSLContextImpl defaultImpl; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
480 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
481 |
private static TrustManager[] defaultTrustManagers; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
482 |
private static KeyManager[] defaultKeyManagers; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
483 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
484 |
public DefaultSSLContext() throws Exception { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
485 |
try { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
486 |
super.engineInit(getDefaultKeyManager(), |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
487 |
getDefaultTrustManager(), null); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
488 |
} catch (Exception e) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
489 |
if (debug != null && Debug.isOn("defaultctx")) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
490 |
System.out.println("default context init failed: " + e); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
491 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
492 |
throw e; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
493 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
494 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
495 |
if (defaultImpl == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
496 |
defaultImpl = this; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
497 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
498 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
499 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
500 |
protected void engineInit(KeyManager[] km, TrustManager[] tm, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
501 |
SecureRandom sr) throws KeyManagementException { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
502 |
throw new KeyManagementException |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
503 |
("Default SSLContext is initialized automatically"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
504 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
505 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
506 |
static synchronized SSLContextImpl getDefaultImpl() throws Exception { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
507 |
if (defaultImpl == null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
508 |
new DefaultSSLContext(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
509 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
510 |
return defaultImpl; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
511 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
512 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
513 |
private static synchronized TrustManager[] getDefaultTrustManager() |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
514 |
throws Exception { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
515 |
if (defaultTrustManagers != null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
516 |
return defaultTrustManagers; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
517 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
518 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
519 |
KeyStore ks = |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
520 |
TrustManagerFactoryImpl.getCacertsKeyStore("defaultctx"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
521 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
522 |
TrustManagerFactory tmf = TrustManagerFactory.getInstance( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
523 |
TrustManagerFactory.getDefaultAlgorithm()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
524 |
tmf.init(ks); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
525 |
defaultTrustManagers = tmf.getTrustManagers(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
526 |
return defaultTrustManagers; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
527 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
528 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
529 |
private static synchronized KeyManager[] getDefaultKeyManager() |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
530 |
throws Exception { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
531 |
if (defaultKeyManagers != null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
532 |
return defaultKeyManagers; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
533 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
534 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
535 |
final Map<String,String> props = new HashMap<>(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
536 |
AccessController.doPrivileged( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
537 |
new PrivilegedExceptionAction<Object>() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
538 |
public Object run() throws Exception { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
539 |
props.put("keyStore", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
540 |
"javax.net.ssl.keyStore", "")); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
541 |
props.put("keyStoreType", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
542 |
"javax.net.ssl.keyStoreType", |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
543 |
KeyStore.getDefaultType())); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
544 |
props.put("keyStoreProvider", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
545 |
"javax.net.ssl.keyStoreProvider", "")); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
546 |
props.put("keyStorePasswd", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
547 |
"javax.net.ssl.keyStorePassword", "")); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
548 |
return null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
549 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
550 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
551 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
552 |
final String defaultKeyStore = props.get("keyStore"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
553 |
String defaultKeyStoreType = props.get("keyStoreType"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
554 |
String defaultKeyStoreProvider = props.get("keyStoreProvider"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
555 |
if (debug != null && Debug.isOn("defaultctx")) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
556 |
System.out.println("keyStore is : " + defaultKeyStore); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
557 |
System.out.println("keyStore type is : " + |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
558 |
defaultKeyStoreType); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
559 |
System.out.println("keyStore provider is : " + |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
560 |
defaultKeyStoreProvider); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
561 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
562 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
563 |
if (P11KEYSTORE.equals(defaultKeyStoreType) && |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
564 |
!NONE.equals(defaultKeyStore)) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
565 |
throw new IllegalArgumentException("if keyStoreType is " |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
566 |
+ P11KEYSTORE + ", then keyStore must be " + NONE); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
567 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
568 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
569 |
FileInputStream fs = null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
570 |
if (defaultKeyStore.length() != 0 && !NONE.equals(defaultKeyStore)) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
571 |
fs = AccessController.doPrivileged( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
572 |
new PrivilegedExceptionAction<FileInputStream>() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
573 |
public FileInputStream run() throws Exception { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
574 |
return new FileInputStream(defaultKeyStore); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
575 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
576 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
577 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
578 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
579 |
String defaultKeyStorePassword = props.get("keyStorePasswd"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
580 |
char[] passwd = null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
581 |
if (defaultKeyStorePassword.length() != 0) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
582 |
passwd = defaultKeyStorePassword.toCharArray(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
583 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
584 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
585 |
/** |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
586 |
* Try to initialize key store. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
587 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
588 |
KeyStore ks = null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
589 |
if ((defaultKeyStoreType.length()) != 0) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
590 |
if (debug != null && Debug.isOn("defaultctx")) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
591 |
System.out.println("init keystore"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
592 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
593 |
if (defaultKeyStoreProvider.length() == 0) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
594 |
ks = KeyStore.getInstance(defaultKeyStoreType); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
595 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
596 |
ks = KeyStore.getInstance(defaultKeyStoreType, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
597 |
defaultKeyStoreProvider); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
598 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
599 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
600 |
// if defaultKeyStore is NONE, fs will be null |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
601 |
ks.load(fs, passwd); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
602 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
603 |
if (fs != null) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
604 |
fs.close(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
605 |
fs = null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
606 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
607 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
608 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
609 |
* Try to initialize key manager. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
610 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
611 |
if (debug != null && Debug.isOn("defaultctx")) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
612 |
System.out.println("init keymanager of type " + |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
613 |
KeyManagerFactory.getDefaultAlgorithm()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
614 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
615 |
KeyManagerFactory kmf = KeyManagerFactory.getInstance( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
616 |
KeyManagerFactory.getDefaultAlgorithm()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
617 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
618 |
if (P11KEYSTORE.equals(defaultKeyStoreType)) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
619 |
kmf.init(ks, null); // do not pass key passwd if using token |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
620 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
621 |
kmf.init(ks, passwd); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
622 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
623 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
624 |
defaultKeyManagers = kmf.getKeyManagers(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
625 |
return defaultKeyManagers; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
626 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
627 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
628 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
629 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
630 |
* The SSLContext implementation for TLS, SSL, SSLv3 and TLS10 algorithm |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
631 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
632 |
* @see SSLContext |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
633 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
634 |
public static final class TLS10Context extends ConservativeSSLContext { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
635 |
// use the default constructor and methods |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
636 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
637 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
638 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
639 |
* The SSLContext implementation for TLS11 algorithm |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
640 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
641 |
* @see SSLContext |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
642 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
643 |
public static final class TLS11Context extends SSLContextImpl { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
644 |
// parameters |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
645 |
private static SSLParameters defaultServerSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
646 |
private static SSLParameters defaultClientSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
647 |
private static SSLParameters supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
648 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
649 |
static { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
650 |
if (SunJSSE.isFIPS()) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
651 |
supportedSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
652 |
supportedSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
653 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
654 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
655 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
656 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
657 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
658 |
defaultServerSSLParams = supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
659 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
660 |
defaultClientSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
661 |
defaultClientSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
662 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
663 |
ProtocolVersion.TLS11.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
664 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
665 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
666 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
667 |
supportedSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
668 |
supportedSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
669 |
ProtocolVersion.SSL20Hello.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
670 |
ProtocolVersion.SSL30.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
671 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
672 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
673 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
674 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
675 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
676 |
defaultServerSSLParams = supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
677 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
678 |
defaultClientSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
679 |
defaultClientSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
680 |
ProtocolVersion.SSL30.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
681 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
682 |
ProtocolVersion.TLS11.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
683 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
684 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
685 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
686 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
687 |
SSLParameters getDefaultServerSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
688 |
return defaultServerSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
689 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
690 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
691 |
SSLParameters getDefaultClientSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
692 |
return defaultClientSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
693 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
694 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
695 |
SSLParameters getSupportedSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
696 |
return supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
697 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
698 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
699 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
700 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
701 |
* The SSLContext implementation for TLS12 algorithm |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
702 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
703 |
* @see SSLContext |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
704 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
705 |
public static final class TLS12Context extends SSLContextImpl { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
706 |
// parameters |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
707 |
private static SSLParameters defaultServerSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
708 |
private static SSLParameters defaultClientSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
709 |
private static SSLParameters supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
710 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
711 |
static { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
712 |
if (SunJSSE.isFIPS()) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
713 |
supportedSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
714 |
supportedSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
715 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
716 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
717 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
718 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
719 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
720 |
defaultServerSSLParams = supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
721 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
722 |
defaultClientSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
723 |
defaultClientSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
724 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
725 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
726 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
727 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
728 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
729 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
730 |
supportedSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
731 |
supportedSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
732 |
ProtocolVersion.SSL20Hello.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
733 |
ProtocolVersion.SSL30.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
734 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
735 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
736 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
737 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
738 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
739 |
defaultServerSSLParams = supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
740 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
741 |
defaultClientSSLParams = new SSLParameters(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
742 |
defaultClientSSLParams.setProtocols(new String[] { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
743 |
ProtocolVersion.SSL30.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
744 |
ProtocolVersion.TLS10.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
745 |
ProtocolVersion.TLS11.name, |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
746 |
ProtocolVersion.TLS12.name |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
747 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
748 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
749 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
750 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
751 |
SSLParameters getDefaultServerSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
752 |
return defaultServerSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
753 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
754 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
755 |
SSLParameters getDefaultClientSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
756 |
return defaultClientSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
757 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
758 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
759 |
SSLParameters getSupportedSSLParams() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
760 |
return supportedSSLParams; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
761 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
762 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
763 |
|
2 | 764 |
} |
765 |
||
7043 | 766 |
|
767 |
final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager |
|
768 |
implements X509TrustManager { |
|
769 |
||
770 |
private final X509TrustManager tm; |
|
771 |
||
772 |
AbstractTrustManagerWrapper(X509TrustManager tm) { |
|
773 |
this.tm = tm; |
|
774 |
} |
|
775 |
||
776 |
@Override |
|
777 |
public void checkClientTrusted(X509Certificate[] chain, String authType) |
|
778 |
throws CertificateException { |
|
779 |
tm.checkClientTrusted(chain, authType); |
|
780 |
} |
|
781 |
||
782 |
@Override |
|
783 |
public void checkServerTrusted(X509Certificate[] chain, String authType) |
|
784 |
throws CertificateException { |
|
785 |
tm.checkServerTrusted(chain, authType); |
|
786 |
} |
|
787 |
||
788 |
@Override |
|
789 |
public X509Certificate[] getAcceptedIssuers() { |
|
790 |
return tm.getAcceptedIssuers(); |
|
791 |
} |
|
792 |
||
793 |
@Override |
|
794 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
795 |
Socket socket) throws CertificateException { |
|
796 |
tm.checkClientTrusted(chain, authType); |
|
797 |
checkAdditionalTrust(chain, authType, socket, true); |
|
798 |
} |
|
799 |
||
800 |
@Override |
|
801 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
802 |
Socket socket) throws CertificateException { |
|
803 |
tm.checkServerTrusted(chain, authType); |
|
804 |
checkAdditionalTrust(chain, authType, socket, false); |
|
805 |
} |
|
806 |
||
807 |
@Override |
|
808 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
809 |
SSLEngine engine) throws CertificateException { |
|
810 |
tm.checkClientTrusted(chain, authType); |
|
811 |
checkAdditionalTrust(chain, authType, engine, true); |
|
812 |
} |
|
813 |
||
814 |
@Override |
|
815 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
816 |
SSLEngine engine) throws CertificateException { |
|
817 |
tm.checkServerTrusted(chain, authType); |
|
818 |
checkAdditionalTrust(chain, authType, engine, false); |
|
819 |
} |
|
820 |
||
821 |
private void checkAdditionalTrust(X509Certificate[] chain, String authType, |
|
822 |
Socket socket, boolean isClient) throws CertificateException { |
|
823 |
if (socket != null && socket.isConnected() && |
|
824 |
socket instanceof SSLSocket) { |
|
825 |
||
826 |
SSLSocket sslSocket = (SSLSocket)socket; |
|
827 |
SSLSession session = sslSocket.getHandshakeSession(); |
|
828 |
if (session == null) { |
|
829 |
throw new CertificateException("No handshake session"); |
|
830 |
} |
|
831 |
||
832 |
// check endpoint identity |
|
833 |
String identityAlg = sslSocket.getSSLParameters(). |
|
834 |
getEndpointIdentificationAlgorithm(); |
|
835 |
if (identityAlg != null && identityAlg.length() != 0) { |
|
836 |
String hostname = session.getPeerHost(); |
|
837 |
X509TrustManagerImpl.checkIdentity( |
|
838 |
hostname, chain[0], identityAlg); |
|
839 |
} |
|
840 |
||
841 |
// try the best to check the algorithm constraints |
|
842 |
ProtocolVersion protocolVersion = |
|
843 |
ProtocolVersion.valueOf(session.getProtocol()); |
|
844 |
AlgorithmConstraints constraints = null; |
|
845 |
if (protocolVersion.v >= ProtocolVersion.TLS12.v) { |
|
846 |
if (session instanceof ExtendedSSLSession) { |
|
847 |
ExtendedSSLSession extSession = |
|
848 |
(ExtendedSSLSession)session; |
|
849 |
String[] peerSupportedSignAlgs = |
|
850 |
extSession.getLocalSupportedSignatureAlgorithms(); |
|
851 |
||
852 |
constraints = new SSLAlgorithmConstraints( |
|
853 |
sslSocket, peerSupportedSignAlgs, true); |
|
854 |
} else { |
|
855 |
constraints = |
|
856 |
new SSLAlgorithmConstraints(sslSocket, true); |
|
857 |
} |
|
858 |
} else { |
|
859 |
constraints = new SSLAlgorithmConstraints(sslSocket, true); |
|
860 |
} |
|
861 |
||
862 |
AlgorithmChecker checker = new AlgorithmChecker(constraints); |
|
863 |
try { |
|
864 |
checker.init(false); |
|
865 |
||
866 |
// a forward checker, need to check from trust to target |
|
867 |
for (int i = chain.length - 1; i >= 0; i--) { |
|
868 |
Certificate cert = chain[i]; |
|
869 |
// We don't care about the unresolved critical extensions. |
|
870 |
checker.check(cert, Collections.<String>emptySet()); |
|
871 |
} |
|
872 |
} catch (CertPathValidatorException cpve) { |
|
873 |
throw new CertificateException( |
|
874 |
"Certificates does not conform to algorithm constraints"); |
|
875 |
} |
|
876 |
} |
|
877 |
} |
|
878 |
||
879 |
private void checkAdditionalTrust(X509Certificate[] chain, String authType, |
|
880 |
SSLEngine engine, boolean isClient) throws CertificateException { |
|
881 |
if (engine != null) { |
|
882 |
SSLSession session = engine.getHandshakeSession(); |
|
883 |
if (session == null) { |
|
884 |
throw new CertificateException("No handshake session"); |
|
885 |
} |
|
886 |
||
887 |
// check endpoint identity |
|
888 |
String identityAlg = engine.getSSLParameters(). |
|
889 |
getEndpointIdentificationAlgorithm(); |
|
890 |
if (identityAlg != null && identityAlg.length() != 0) { |
|
891 |
String hostname = session.getPeerHost(); |
|
892 |
X509TrustManagerImpl.checkIdentity( |
|
893 |
hostname, chain[0], identityAlg); |
|
894 |
} |
|
895 |
||
896 |
// try the best to check the algorithm constraints |
|
897 |
ProtocolVersion protocolVersion = |
|
898 |
ProtocolVersion.valueOf(session.getProtocol()); |
|
899 |
AlgorithmConstraints constraints = null; |
|
900 |
if (protocolVersion.v >= ProtocolVersion.TLS12.v) { |
|
901 |
if (session instanceof ExtendedSSLSession) { |
|
902 |
ExtendedSSLSession extSession = |
|
903 |
(ExtendedSSLSession)session; |
|
904 |
String[] peerSupportedSignAlgs = |
|
905 |
extSession.getLocalSupportedSignatureAlgorithms(); |
|
906 |
||
907 |
constraints = new SSLAlgorithmConstraints( |
|
908 |
engine, peerSupportedSignAlgs, true); |
|
909 |
} else { |
|
910 |
constraints = |
|
911 |
new SSLAlgorithmConstraints(engine, true); |
|
912 |
} |
|
913 |
} else { |
|
914 |
constraints = new SSLAlgorithmConstraints(engine, true); |
|
915 |
} |
|
916 |
||
917 |
AlgorithmChecker checker = new AlgorithmChecker(constraints); |
|
918 |
try { |
|
919 |
checker.init(false); |
|
920 |
||
921 |
// A forward checker, need to check from trust to target |
|
922 |
for (int i = chain.length - 1; i >= 0; i--) { |
|
923 |
Certificate cert = chain[i]; |
|
924 |
// We don't care about the unresolved critical extensions. |
|
925 |
checker.check(cert, Collections.<String>emptySet()); |
|
926 |
} |
|
927 |
} catch (CertPathValidatorException cpve) { |
|
928 |
throw new CertificateException( |
|
929 |
"Certificates does not conform to algorithm constraints"); |
|
930 |
} |
|
931 |
} |
|
932 |
} |
|
933 |
} |
|
934 |
||
2 | 935 |
// Dummy X509TrustManager implementation, rejects all peer certificates. |
936 |
// Used if the application did not specify a proper X509TrustManager. |
|
7043 | 937 |
final class DummyX509TrustManager extends X509ExtendedTrustManager |
938 |
implements X509TrustManager { |
|
2 | 939 |
|
940 |
static final X509TrustManager INSTANCE = new DummyX509TrustManager(); |
|
941 |
||
942 |
private DummyX509TrustManager() { |
|
943 |
// empty |
|
944 |
} |
|
945 |
||
946 |
/* |
|
947 |
* Given the partial or complete certificate chain |
|
948 |
* provided by the peer, build a certificate path |
|
949 |
* to a trusted root and return if it can be |
|
950 |
* validated and is trusted for client SSL authentication. |
|
951 |
* If not, it throws an exception. |
|
952 |
*/ |
|
7043 | 953 |
@Override |
2 | 954 |
public void checkClientTrusted(X509Certificate[] chain, String authType) |
955 |
throws CertificateException { |
|
956 |
throw new CertificateException( |
|
957 |
"No X509TrustManager implementation avaiable"); |
|
958 |
} |
|
959 |
||
960 |
/* |
|
961 |
* Given the partial or complete certificate chain |
|
962 |
* provided by the peer, build a certificate path |
|
963 |
* to a trusted root and return if it can be |
|
964 |
* validated and is trusted for server SSL authentication. |
|
965 |
* If not, it throws an exception. |
|
966 |
*/ |
|
7043 | 967 |
@Override |
2 | 968 |
public void checkServerTrusted(X509Certificate[] chain, String authType) |
969 |
throws CertificateException { |
|
970 |
throw new CertificateException( |
|
971 |
"No X509TrustManager implementation available"); |
|
972 |
} |
|
973 |
||
974 |
/* |
|
975 |
* Return an array of issuer certificates which are trusted |
|
976 |
* for authenticating peers. |
|
977 |
*/ |
|
7043 | 978 |
@Override |
2 | 979 |
public X509Certificate[] getAcceptedIssuers() { |
980 |
return new X509Certificate[0]; |
|
981 |
} |
|
7043 | 982 |
|
983 |
@Override |
|
984 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
985 |
Socket socket) throws CertificateException { |
|
986 |
throw new CertificateException( |
|
987 |
"No X509TrustManager implementation available"); |
|
988 |
} |
|
989 |
||
990 |
@Override |
|
991 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
992 |
Socket socket) throws CertificateException { |
|
993 |
throw new CertificateException( |
|
994 |
"No X509TrustManager implementation available"); |
|
995 |
} |
|
996 |
||
997 |
@Override |
|
998 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
999 |
SSLEngine engine) throws CertificateException { |
|
1000 |
throw new CertificateException( |
|
1001 |
"No X509TrustManager implementation available"); |
|
1002 |
} |
|
1003 |
||
1004 |
@Override |
|
1005 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
1006 |
SSLEngine engine) throws CertificateException { |
|
1007 |
throw new CertificateException( |
|
1008 |
"No X509TrustManager implementation available"); |
|
1009 |
} |
|
2 | 1010 |
} |
1011 |
||
1012 |
/* |
|
1013 |
* A wrapper class to turn a X509KeyManager into an X509ExtendedKeyManager |
|
1014 |
*/ |
|
7043 | 1015 |
final class AbstractKeyManagerWrapper extends X509ExtendedKeyManager { |
2 | 1016 |
|
1017 |
private final X509KeyManager km; |
|
1018 |
||
7043 | 1019 |
AbstractKeyManagerWrapper(X509KeyManager km) { |
2 | 1020 |
this.km = km; |
1021 |
} |
|
1022 |
||
1023 |
public String[] getClientAliases(String keyType, Principal[] issuers) { |
|
1024 |
return km.getClientAliases(keyType, issuers); |
|
1025 |
} |
|
1026 |
||
1027 |
public String chooseClientAlias(String[] keyType, Principal[] issuers, |
|
1028 |
Socket socket) { |
|
1029 |
return km.chooseClientAlias(keyType, issuers, socket); |
|
1030 |
} |
|
1031 |
||
1032 |
public String[] getServerAliases(String keyType, Principal[] issuers) { |
|
1033 |
return km.getServerAliases(keyType, issuers); |
|
1034 |
} |
|
1035 |
||
1036 |
public String chooseServerAlias(String keyType, Principal[] issuers, |
|
1037 |
Socket socket) { |
|
1038 |
return km.chooseServerAlias(keyType, issuers, socket); |
|
1039 |
} |
|
1040 |
||
1041 |
public X509Certificate[] getCertificateChain(String alias) { |
|
1042 |
return km.getCertificateChain(alias); |
|
1043 |
} |
|
1044 |
||
1045 |
public PrivateKey getPrivateKey(String alias) { |
|
1046 |
return km.getPrivateKey(alias); |
|
1047 |
} |
|
1048 |
||
1049 |
// Inherit chooseEngineClientAlias() and chooseEngineServerAlias() from |
|
1050 |
// X509ExtendedKeymanager. It defines them to return null; |
|
1051 |
} |
|
1052 |
||
1053 |
||
1054 |
// Dummy X509KeyManager implementation, never returns any certificates/keys. |
|
1055 |
// Used if the application did not specify a proper X509TrustManager. |
|
1056 |
final class DummyX509KeyManager extends X509ExtendedKeyManager { |
|
1057 |
||
1058 |
static final X509ExtendedKeyManager INSTANCE = new DummyX509KeyManager(); |
|
1059 |
||
1060 |
private DummyX509KeyManager() { |
|
1061 |
// empty |
|
1062 |
} |
|
1063 |
||
1064 |
/* |
|
1065 |
* Get the matching aliases for authenticating the client side of a secure |
|
1066 |
* socket given the public key type and the list of |
|
1067 |
* certificate issuer authorities recognized by the peer (if any). |
|
1068 |
*/ |
|
1069 |
public String[] getClientAliases(String keyType, Principal[] issuers) { |
|
1070 |
return null; |
|
1071 |
} |
|
1072 |
||
1073 |
/* |
|
1074 |
* Choose an alias to authenticate the client side of a secure |
|
1075 |
* socket given the public key type and the list of |
|
1076 |
* certificate issuer authorities recognized by the peer (if any). |
|
1077 |
*/ |
|
1078 |
public String chooseClientAlias(String[] keyTypes, Principal[] issuers, |
|
1079 |
Socket socket) { |
|
1080 |
return null; |
|
1081 |
} |
|
1082 |
||
1083 |
/* |
|
1084 |
* Choose an alias to authenticate the client side of an |
|
1085 |
* engine given the public key type and the list of |
|
1086 |
* certificate issuer authorities recognized by the peer (if any). |
|
1087 |
*/ |
|
1088 |
public String chooseEngineClientAlias( |
|
1089 |
String[] keyTypes, Principal[] issuers, SSLEngine engine) { |
|
1090 |
return null; |
|
1091 |
} |
|
1092 |
||
1093 |
/* |
|
1094 |
* Get the matching aliases for authenticating the server side of a secure |
|
1095 |
* socket given the public key type and the list of |
|
1096 |
* certificate issuer authorities recognized by the peer (if any). |
|
1097 |
*/ |
|
1098 |
public String[] getServerAliases(String keyType, Principal[] issuers) { |
|
1099 |
return null; |
|
1100 |
} |
|
1101 |
||
1102 |
/* |
|
1103 |
* Choose an alias to authenticate the server side of a secure |
|
1104 |
* socket given the public key type and the list of |
|
1105 |
* certificate issuer authorities recognized by the peer (if any). |
|
1106 |
*/ |
|
1107 |
public String chooseServerAlias(String keyType, Principal[] issuers, |
|
1108 |
Socket socket) { |
|
1109 |
return null; |
|
1110 |
} |
|
1111 |
||
1112 |
/* |
|
1113 |
* Choose an alias to authenticate the server side of an engine |
|
1114 |
* given the public key type and the list of |
|
1115 |
* certificate issuer authorities recognized by the peer (if any). |
|
1116 |
*/ |
|
1117 |
public String chooseEngineServerAlias( |
|
1118 |
String keyType, Principal[] issuers, SSLEngine engine) { |
|
1119 |
return null; |
|
1120 |
} |
|
1121 |
||
1122 |
/** |
|
1123 |
* Returns the certificate chain associated with the given alias. |
|
1124 |
* |
|
1125 |
* @param alias the alias name |
|
1126 |
* |
|
1127 |
* @return the certificate chain (ordered with the user's certificate first |
|
1128 |
* and the root certificate authority last) |
|
1129 |
*/ |
|
1130 |
public X509Certificate[] getCertificateChain(String alias) { |
|
1131 |
return null; |
|
1132 |
} |
|
1133 |
||
1134 |
/* |
|
1135 |
* Returns the key associated with the given alias, using the given |
|
1136 |
* password to recover it. |
|
1137 |
* |
|
1138 |
* @param alias the alias name |
|
1139 |
* |
|
1140 |
* @return the requested key |
|
1141 |
*/ |
|
1142 |
public PrivateKey getPrivateKey(String alias) { |
|
1143 |
return null; |
|
1144 |
} |
|
1145 |
} |