author | wetmore |
Fri, 11 May 2018 15:53:12 -0700 | |
branch | JDK-8145252-TLS13-branch |
changeset 56542 | 56aaa6cb3693 |
parent 47216 | 71c04702a3d5 |
child 56611 | f8f7e604e1f8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
56542 | 2 |
* Copyright (c) 1999, 2018, 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 |
||
56542 | 28 |
import java.io.*; |
2 | 29 |
import java.net.Socket; |
30 |
import java.security.*; |
|
31 |
import java.security.cert.*; |
|
56542 | 32 |
import java.util.*; |
2 | 33 |
import javax.net.ssl.*; |
56542 | 34 |
import sun.security.action.GetPropertyAction; |
7043 | 35 |
import sun.security.provider.certpath.AlgorithmChecker; |
43701
fe8c324ba97c
8160655: Fix denyAfter and usage types for security properties
ascarpino
parents:
43009
diff
changeset
|
36 |
import sun.security.validator.Validator; |
7043 | 37 |
|
56542 | 38 |
/** |
39 |
* Implementation of an SSLContext. |
|
40 |
* |
|
41 |
* Instances of this class are immutable after the context is initialized. |
|
42 |
*/ |
|
2 | 43 |
|
56542 | 44 |
public abstract class SSLContextImpl extends SSLContextSpi { |
2 | 45 |
|
46 |
private final EphemeralKeyManager ephemeralKeyManager; |
|
47 |
private final SSLSessionContextImpl clientCache; |
|
48 |
private final SSLSessionContextImpl serverCache; |
|
49 |
||
50 |
private boolean isInitialized; |
|
51 |
||
52 |
private X509ExtendedKeyManager keyManager; |
|
53 |
private X509TrustManager trustManager; |
|
54 |
private SecureRandom secureRandom; |
|
55 |
||
30904 | 56 |
// DTLS cookie exchange manager |
34826 | 57 |
private volatile HelloCookieManager helloCookieManager; |
30904 | 58 |
|
56542 | 59 |
private final boolean clientEnableStapling = Utilities.getBooleanProperty( |
36132
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
60 |
"jdk.tls.client.enableStatusRequestExtension", true); |
56542 | 61 |
private final boolean serverEnableStapling = Utilities.getBooleanProperty( |
36132
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
62 |
"jdk.tls.server.enableStatusRequestExtension", false); |
56542 | 63 |
private static final Collection<CipherSuite> clientCustomizedCipherSuites = |
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
64 |
getCustomizedCipherSuites("jdk.tls.client.cipherSuites"); |
56542 | 65 |
private static final Collection<CipherSuite> serverCustomizedCipherSuites = |
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
66 |
getCustomizedCipherSuites("jdk.tls.server.cipherSuites"); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
67 |
|
36132
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
68 |
private volatile StatusResponseManager statusResponseManager; |
32032 | 69 |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
70 |
SSLContextImpl() { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
71 |
ephemeralKeyManager = new EphemeralKeyManager(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
72 |
clientCache = new SSLSessionContextImpl(); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
73 |
serverCache = new SSLSessionContextImpl(); |
2 | 74 |
} |
75 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
76 |
@Override |
2 | 77 |
protected void engineInit(KeyManager[] km, TrustManager[] tm, |
78 |
SecureRandom sr) throws KeyManagementException { |
|
79 |
isInitialized = false; |
|
80 |
keyManager = chooseKeyManager(km); |
|
81 |
||
82 |
if (tm == null) { |
|
83 |
try { |
|
84 |
TrustManagerFactory tmf = TrustManagerFactory.getInstance( |
|
85 |
TrustManagerFactory.getDefaultAlgorithm()); |
|
86 |
tmf.init((KeyStore)null); |
|
87 |
tm = tmf.getTrustManagers(); |
|
88 |
} catch (Exception e) { |
|
89 |
// eat |
|
90 |
} |
|
91 |
} |
|
92 |
trustManager = chooseTrustManager(tm); |
|
93 |
||
94 |
if (sr == null) { |
|
95 |
secureRandom = JsseJce.getSecureRandom(); |
|
96 |
} else { |
|
7043 | 97 |
if (SunJSSE.isFIPS() && |
98 |
(sr.getProvider() != SunJSSE.cryptoProvider)) { |
|
2 | 99 |
throw new KeyManagementException |
100 |
("FIPS mode: SecureRandom must be from provider " |
|
101 |
+ SunJSSE.cryptoProvider.getName()); |
|
102 |
} |
|
103 |
secureRandom = sr; |
|
104 |
} |
|
105 |
||
106 |
/* |
|
107 |
* The initial delay of seeding the random number generator |
|
108 |
* could be long enough to cause the initial handshake on our |
|
109 |
* first connection to timeout and fail. Make sure it is |
|
110 |
* primed and ready by getting some initial output from it. |
|
111 |
*/ |
|
56542 | 112 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) { |
113 |
SSLLogger.finest("trigger seeding of SecureRandom"); |
|
2 | 114 |
} |
115 |
secureRandom.nextInt(); |
|
56542 | 116 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) { |
117 |
SSLLogger.finest("done seeding of SecureRandom"); |
|
2 | 118 |
} |
34826 | 119 |
|
2 | 120 |
isInitialized = true; |
121 |
} |
|
122 |
||
123 |
private X509TrustManager chooseTrustManager(TrustManager[] tm) |
|
124 |
throws KeyManagementException { |
|
125 |
// We only use the first instance of X509TrustManager passed to us. |
|
126 |
for (int i = 0; tm != null && i < tm.length; i++) { |
|
127 |
if (tm[i] instanceof X509TrustManager) { |
|
7043 | 128 |
if (SunJSSE.isFIPS() && |
129 |
!(tm[i] instanceof X509TrustManagerImpl)) { |
|
2 | 130 |
throw new KeyManagementException |
131 |
("FIPS mode: only SunJSSE TrustManagers may be used"); |
|
132 |
} |
|
7043 | 133 |
|
134 |
if (tm[i] instanceof X509ExtendedTrustManager) { |
|
135 |
return (X509TrustManager)tm[i]; |
|
136 |
} else { |
|
137 |
return new AbstractTrustManagerWrapper( |
|
138 |
(X509TrustManager)tm[i]); |
|
139 |
} |
|
2 | 140 |
} |
141 |
} |
|
142 |
||
143 |
// nothing found, return a dummy X509TrustManager. |
|
144 |
return DummyX509TrustManager.INSTANCE; |
|
145 |
} |
|
146 |
||
147 |
private X509ExtendedKeyManager chooseKeyManager(KeyManager[] kms) |
|
148 |
throws KeyManagementException { |
|
149 |
for (int i = 0; kms != null && i < kms.length; i++) { |
|
150 |
KeyManager km = kms[i]; |
|
12874 | 151 |
if (!(km instanceof X509KeyManager)) { |
2 | 152 |
continue; |
153 |
} |
|
154 |
if (SunJSSE.isFIPS()) { |
|
155 |
// In FIPS mode, require that one of SunJSSE's own keymanagers |
|
156 |
// is used. Otherwise, we cannot be sure that only keys from |
|
157 |
// the FIPS token are used. |
|
158 |
if ((km instanceof X509KeyManagerImpl) |
|
159 |
|| (km instanceof SunX509KeyManagerImpl)) { |
|
160 |
return (X509ExtendedKeyManager)km; |
|
161 |
} else { |
|
162 |
// throw exception, we don't want to silently use the |
|
163 |
// dummy keymanager without telling the user. |
|
164 |
throw new KeyManagementException |
|
165 |
("FIPS mode: only SunJSSE KeyManagers may be used"); |
|
166 |
} |
|
167 |
} |
|
168 |
if (km instanceof X509ExtendedKeyManager) { |
|
169 |
return (X509ExtendedKeyManager)km; |
|
170 |
} |
|
56542 | 171 |
|
172 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) { |
|
173 |
SSLLogger.warning( |
|
174 |
"X509KeyManager passed to SSLContext.init(): need an " + |
|
2 | 175 |
"X509ExtendedKeyManager for SSLEngine use"); |
176 |
} |
|
7043 | 177 |
return new AbstractKeyManagerWrapper((X509KeyManager)km); |
2 | 178 |
} |
179 |
||
180 |
// nothing found, return a dummy X509ExtendedKeyManager |
|
181 |
return DummyX509KeyManager.INSTANCE; |
|
182 |
} |
|
183 |
||
30904 | 184 |
abstract SSLEngine createSSLEngineImpl(); |
185 |
abstract SSLEngine createSSLEngineImpl(String host, int port); |
|
186 |
||
187 |
@Override |
|
188 |
protected SSLEngine engineCreateSSLEngine() { |
|
189 |
if (!isInitialized) { |
|
190 |
throw new IllegalStateException("SSLContext is not initialized"); |
|
191 |
} |
|
192 |
return createSSLEngineImpl(); |
|
193 |
} |
|
194 |
||
195 |
@Override |
|
196 |
protected SSLEngine engineCreateSSLEngine(String host, int port) { |
|
197 |
if (!isInitialized) { |
|
198 |
throw new IllegalStateException("SSLContext is not initialized"); |
|
199 |
} |
|
200 |
return createSSLEngineImpl(host, port); |
|
201 |
} |
|
202 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
203 |
@Override |
2 | 204 |
protected SSLSocketFactory engineGetSocketFactory() { |
205 |
if (!isInitialized) { |
|
30904 | 206 |
throw new IllegalStateException("SSLContext is not initialized"); |
2 | 207 |
} |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
208 |
return new SSLSocketFactoryImpl(this); |
2 | 209 |
} |
210 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
211 |
@Override |
2 | 212 |
protected SSLServerSocketFactory engineGetServerSocketFactory() { |
213 |
if (!isInitialized) { |
|
214 |
throw new IllegalStateException("SSLContext is not initialized"); |
|
215 |
} |
|
216 |
return new SSLServerSocketFactoryImpl(this); |
|
217 |
} |
|
218 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
219 |
@Override |
2 | 220 |
protected SSLSessionContext engineGetClientSessionContext() { |
221 |
return clientCache; |
|
222 |
} |
|
223 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
224 |
@Override |
2 | 225 |
protected SSLSessionContext engineGetServerSessionContext() { |
226 |
return serverCache; |
|
227 |
} |
|
228 |
||
229 |
SecureRandom getSecureRandom() { |
|
230 |
return secureRandom; |
|
231 |
} |
|
232 |
||
233 |
X509ExtendedKeyManager getX509KeyManager() { |
|
234 |
return keyManager; |
|
235 |
} |
|
236 |
||
237 |
X509TrustManager getX509TrustManager() { |
|
238 |
return trustManager; |
|
239 |
} |
|
240 |
||
241 |
EphemeralKeyManager getEphemeralKeyManager() { |
|
242 |
return ephemeralKeyManager; |
|
243 |
} |
|
244 |
||
56542 | 245 |
// Used for DTLS in server mode only. |
246 |
HelloCookieManager getHelloCookieManager(ProtocolVersion protocolVersion) { |
|
34826 | 247 |
if (helloCookieManager != null) { |
56542 | 248 |
return helloCookieManager.valueOf(protocolVersion); |
34826 | 249 |
} |
250 |
||
251 |
synchronized (this) { |
|
252 |
if (helloCookieManager == null) { |
|
56542 | 253 |
helloCookieManager = new HelloCookieManager(secureRandom); |
34826 | 254 |
} |
30904 | 255 |
} |
256 |
||
56542 | 257 |
return helloCookieManager.valueOf(protocolVersion); |
30904 | 258 |
} |
259 |
||
32032 | 260 |
StatusResponseManager getStatusResponseManager() { |
36132
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
261 |
if (serverEnableStapling && statusResponseManager == null) { |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
262 |
synchronized (this) { |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
263 |
if (statusResponseManager == null) { |
56542 | 264 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) { |
265 |
SSLLogger.finest( |
|
36132
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
266 |
"Initializing StatusResponseManager"); |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
267 |
} |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
268 |
statusResponseManager = new StatusResponseManager(); |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
269 |
} |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
270 |
} |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
271 |
} |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
272 |
|
32032 | 273 |
return statusResponseManager; |
274 |
} |
|
275 |
||
56542 | 276 |
// Get supported protocols. |
277 |
abstract List<ProtocolVersion> getSuportedProtocolVersions(); |
|
278 |
||
279 |
// Get default protocols for server mode. |
|
280 |
abstract List<ProtocolVersion> getServerDefaultProtocolVersions(); |
|
34826 | 281 |
|
56542 | 282 |
// Get default protocols for client mode. |
283 |
abstract List<ProtocolVersion> getClientDefaultProtocolVersions(); |
|
34826 | 284 |
|
56542 | 285 |
// Get supported CipherSuite list. |
286 |
abstract List<CipherSuite> getSupportedCipherSuites(); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
287 |
|
56542 | 288 |
// Get default CipherSuite list for server mode. |
289 |
abstract List<CipherSuite> getServerDefaultCipherSuites(); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
290 |
|
56542 | 291 |
// Get default CipherSuite list for client mode. |
292 |
abstract List<CipherSuite> getClientDefaultCipherSuites(); |
|
34826 | 293 |
|
56542 | 294 |
// Is the context for DTLS protocols? |
295 |
abstract boolean isDTLS(); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
296 |
|
56542 | 297 |
// Get default protocols. |
298 |
List<ProtocolVersion> getDefaultProtocolVersions(boolean roleIsServer) { |
|
299 |
return roleIsServer ? getServerDefaultProtocolVersions() |
|
300 |
: getClientDefaultProtocolVersions(); |
|
9246
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 |
|
56542 | 303 |
// Get default CipherSuite list. |
304 |
List<CipherSuite> getDefaultCipherSuites(boolean roleIsServer) { |
|
305 |
return roleIsServer ? getServerDefaultCipherSuites() |
|
306 |
: getClientDefaultCipherSuites(); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
307 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
308 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
309 |
/** |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
310 |
* 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
|
311 |
* protocols. See: SSLSocket/SSLEngine.setEnabledProtocols() |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
312 |
*/ |
56542 | 313 |
boolean isDefaultProtocolVesions(List<ProtocolVersion> protocols) { |
314 |
return (protocols == getServerDefaultProtocolVersions()) || |
|
315 |
(protocols == getClientDefaultProtocolVersions()); |
|
9246
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 |
|
30904 | 318 |
/** |
319 |
* Return whether a protocol list is the original default enabled |
|
320 |
* protocols. See: SSLSocket/SSLEngine.setEnabledProtocols() |
|
321 |
*/ |
|
56542 | 322 |
boolean isDefaultCipherSuiteList(List<CipherSuite> cipherSuites) { |
323 |
return (cipherSuites == getServerDefaultCipherSuites()) || |
|
324 |
(cipherSuites == getClientDefaultCipherSuites()); |
|
30904 | 325 |
} |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
326 |
|
36132
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
327 |
/** |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
328 |
* Return whether client or server side stapling has been enabled |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
329 |
* for this SSLContextImpl |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
330 |
* @param isClient true if the caller is operating in a client side role, |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
331 |
* false if acting as a server. |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
332 |
* @return true if stapling has been enabled for the specified role, false |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
333 |
* otherwise. |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
334 |
*/ |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
335 |
boolean isStaplingEnabled(boolean isClient) { |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
336 |
return isClient ? clientEnableStapling : serverEnableStapling; |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
337 |
} |
c99a60377145
8145854: SSLContextImpl.statusResponseManager should be generated if required
jnimeh
parents:
34826
diff
changeset
|
338 |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
339 |
/* |
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
340 |
* Return the list of all available CipherSuites that are supported |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
341 |
* using currently installed providers. |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
342 |
*/ |
56542 | 343 |
private static List<CipherSuite> getApplicableSupportedCipherSuites( |
344 |
List<ProtocolVersion> protocols) { |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
345 |
|
56542 | 346 |
return getApplicableCipherSuites( |
347 |
CipherSuite.allowedCipherSuites(), protocols); |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
348 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
349 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
350 |
/* |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
351 |
* Return the list of all available CipherSuites that are default enabled |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
352 |
* in client or server side. |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
353 |
*/ |
56542 | 354 |
private static List<CipherSuite> getApplicableEnabledCipherSuites( |
355 |
List<ProtocolVersion> protocols, boolean isClient) { |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
356 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
357 |
if (isClient) { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
358 |
if (!clientCustomizedCipherSuites.isEmpty()) { |
56542 | 359 |
return getApplicableCipherSuites( |
360 |
clientCustomizedCipherSuites, protocols); |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
361 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
362 |
} else { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
363 |
if (!serverCustomizedCipherSuites.isEmpty()) { |
56542 | 364 |
return getApplicableCipherSuites( |
365 |
serverCustomizedCipherSuites, protocols); |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
366 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
367 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
368 |
|
56542 | 369 |
return getApplicableCipherSuites( |
370 |
CipherSuite.defaultCipherSuites(), protocols); |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
371 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
372 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
373 |
/* |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
374 |
* Return the list of available CipherSuites which are applicable to |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
375 |
* the specified protocols. |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
376 |
*/ |
56542 | 377 |
private static List<CipherSuite> getApplicableCipherSuites( |
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
378 |
Collection<CipherSuite> allowedCipherSuites, |
56542 | 379 |
List<ProtocolVersion> protocols) { |
12874 | 380 |
TreeSet<CipherSuite> suites = new TreeSet<>(); |
56542 | 381 |
if (protocols != null && (!protocols.isEmpty())) { |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
382 |
for (CipherSuite suite : allowedCipherSuites) { |
56542 | 383 |
if (!suite.isAvailable()) { |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
384 |
continue; |
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 |
|
56542 | 387 |
boolean isSupported = false; |
388 |
for (ProtocolVersion protocol : protocols) { |
|
389 |
if (!suite.supports(protocol)) { |
|
390 |
continue; |
|
391 |
} |
|
392 |
||
28555 | 393 |
if (SSLAlgorithmConstraints.DEFAULT.permits( |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
394 |
EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
395 |
suite.name, null)) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
396 |
suites.add(suite); |
56542 | 397 |
isSupported = true; |
398 |
} else if (SSLLogger.isOn && |
|
399 |
SSLLogger.isOn("ssl,sslctx,verbose")) { |
|
400 |
SSLLogger.fine( |
|
401 |
"Ignore disabled cipher suite: " + suite.name); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
402 |
} |
56542 | 403 |
|
404 |
break; |
|
405 |
} |
|
406 |
||
407 |
if (!isSupported && SSLLogger.isOn && |
|
408 |
SSLLogger.isOn("ssl,sslctx,verbose")) { |
|
409 |
SSLLogger.finest( |
|
410 |
"Ignore unsupported cipher suite: " + suite); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
411 |
} |
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 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
414 |
|
56542 | 415 |
return Arrays.asList(suites.toArray(new CipherSuite[0])); |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
416 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
417 |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
418 |
/* |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
419 |
* Get the customized cipher suites specified by the given system property. |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
420 |
*/ |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
421 |
private static Collection<CipherSuite> getCustomizedCipherSuites( |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
422 |
String propertyName) { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
423 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
424 |
String property = GetPropertyAction.privilegedGetProperty(propertyName); |
56542 | 425 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) { |
426 |
SSLLogger.fine( |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
427 |
"System property " + propertyName + " is set to '" + |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
428 |
property + "'"); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
429 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
430 |
if (property != null && property.length() != 0) { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
431 |
// remove double quote marks from beginning/end of the property |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
432 |
if (property.length() > 1 && property.charAt(0) == '"' && |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
433 |
property.charAt(property.length() - 1) == '"') { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
434 |
property = property.substring(1, property.length() - 1); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
435 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
436 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
437 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
438 |
if (property != null && property.length() != 0) { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
439 |
String[] cipherSuiteNames = property.split(","); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
440 |
Collection<CipherSuite> cipherSuites = |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
441 |
new ArrayList<>(cipherSuiteNames.length); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
442 |
for (int i = 0; i < cipherSuiteNames.length; i++) { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
443 |
cipherSuiteNames[i] = cipherSuiteNames[i].trim(); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
444 |
if (cipherSuiteNames[i].isEmpty()) { |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
445 |
continue; |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
446 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
447 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
448 |
CipherSuite suite; |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
449 |
try { |
56542 | 450 |
suite = CipherSuite.nameOf(cipherSuiteNames[i]); |
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
451 |
} catch (IllegalArgumentException iae) { |
56542 | 452 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) { |
453 |
SSLLogger.fine( |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
454 |
"Unknown or unsupported cipher suite name: " + |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
455 |
cipherSuiteNames[i]); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
456 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
457 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
458 |
continue; |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
459 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
460 |
|
56542 | 461 |
if (suite != null && suite.isAvailable()) { |
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
462 |
cipherSuites.add(suite); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
463 |
} else { |
56542 | 464 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,sslctx")) { |
465 |
SSLLogger.fine( |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
466 |
"The current installed providers do not " + |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
467 |
"support cipher suite: " + cipherSuiteNames[i]); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
468 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
469 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
470 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
471 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
472 |
return cipherSuites; |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
473 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
474 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
475 |
return Collections.emptyList(); |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
476 |
} |
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
477 |
|
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
478 |
|
56542 | 479 |
private static List<ProtocolVersion> getAvailableProtocols( |
30904 | 480 |
ProtocolVersion[] protocolCandidates) { |
481 |
||
56542 | 482 |
List<ProtocolVersion> availableProtocols = |
483 |
Collections.<ProtocolVersion>emptyList(); |
|
30904 | 484 |
if (protocolCandidates != null && protocolCandidates.length != 0) { |
485 |
availableProtocols = new ArrayList<>(protocolCandidates.length); |
|
486 |
for (ProtocolVersion p : protocolCandidates) { |
|
56542 | 487 |
if (p.isAvailable) { |
488 |
availableProtocols.add(p); |
|
30904 | 489 |
} |
490 |
} |
|
491 |
} |
|
492 |
||
56542 | 493 |
return availableProtocols; |
30904 | 494 |
} |
495 |
||
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
496 |
/* |
30904 | 497 |
* The SSLContext implementation for SSL/(D)TLS algorithm |
9246
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 |
* 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
|
500 |
* 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
|
501 |
* 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
|
502 |
* 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
|
503 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
504 |
* 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
|
505 |
* 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
|
506 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
507 |
* 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
|
508 |
* 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
|
509 |
* enabled protocols for server by default. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
510 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
511 |
* 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
|
512 |
* forward compatibility properly. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
513 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
514 |
* 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
|
515 |
* 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
|
516 |
* 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
|
517 |
* 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
|
518 |
* 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
|
519 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
520 |
* 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
|
521 |
* 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
|
522 |
* the series of setEnabledProtocols APIs. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
523 |
*/ |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
524 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
525 |
/* |
30904 | 526 |
* The base abstract SSLContext implementation for the Transport Layer |
527 |
* Security (TLS) protocols. |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
528 |
* |
22068 | 529 |
* This abstract class encapsulates supported and the default server |
30904 | 530 |
* SSL/TLS parameters. |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
531 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
532 |
* @see SSLContext |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
533 |
*/ |
30904 | 534 |
private abstract static class AbstractTLSContext extends SSLContextImpl { |
56542 | 535 |
private static final List<ProtocolVersion> supportedProtocols; |
536 |
private static final List<ProtocolVersion> serverDefaultProtocols; |
|
34826 | 537 |
|
56542 | 538 |
private static final List<CipherSuite> supportedCipherSuites; |
539 |
private static final List<CipherSuite> serverDefaultCipherSuites; |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
540 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
541 |
static { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
542 |
if (SunJSSE.isFIPS()) { |
56542 | 543 |
supportedProtocols = Arrays.asList( |
544 |
ProtocolVersion.TLS13, |
|
545 |
ProtocolVersion.TLS12, |
|
546 |
ProtocolVersion.TLS11, |
|
547 |
ProtocolVersion.TLS10 |
|
548 |
); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
549 |
|
56542 | 550 |
serverDefaultProtocols = getAvailableProtocols( |
551 |
new ProtocolVersion[] { |
|
552 |
ProtocolVersion.TLS13, |
|
553 |
ProtocolVersion.TLS12, |
|
28555 | 554 |
ProtocolVersion.TLS11, |
56542 | 555 |
ProtocolVersion.TLS10 |
556 |
}); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
557 |
} else { |
56542 | 558 |
supportedProtocols = Arrays.asList( |
559 |
ProtocolVersion.TLS13, |
|
560 |
ProtocolVersion.TLS12, |
|
561 |
ProtocolVersion.TLS11, |
|
562 |
ProtocolVersion.TLS10, |
|
563 |
ProtocolVersion.SSL30, |
|
564 |
ProtocolVersion.SSL20Hello |
|
565 |
); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
566 |
|
56542 | 567 |
serverDefaultProtocols = getAvailableProtocols( |
568 |
new ProtocolVersion[] { |
|
569 |
ProtocolVersion.TLS13, |
|
570 |
ProtocolVersion.TLS12, |
|
571 |
ProtocolVersion.TLS11, |
|
572 |
ProtocolVersion.TLS10, |
|
28555 | 573 |
ProtocolVersion.SSL30, |
56542 | 574 |
ProtocolVersion.SSL20Hello |
575 |
}); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
576 |
} |
28555 | 577 |
|
56542 | 578 |
supportedCipherSuites = getApplicableSupportedCipherSuites( |
579 |
supportedProtocols); |
|
580 |
serverDefaultCipherSuites = getApplicableEnabledCipherSuites( |
|
581 |
serverDefaultProtocols, false); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
582 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
583 |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
584 |
@Override |
56542 | 585 |
List<ProtocolVersion> getSuportedProtocolVersions() { |
586 |
return supportedProtocols; |
|
9246
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 |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
589 |
@Override |
56542 | 590 |
List<CipherSuite> getSupportedCipherSuites() { |
591 |
return supportedCipherSuites; |
|
34826 | 592 |
} |
593 |
||
594 |
@Override |
|
56542 | 595 |
List<ProtocolVersion> getServerDefaultProtocolVersions() { |
596 |
return serverDefaultProtocols; |
|
34826 | 597 |
} |
598 |
||
599 |
@Override |
|
56542 | 600 |
List<CipherSuite> getServerDefaultCipherSuites() { |
601 |
return serverDefaultCipherSuites; |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
602 |
} |
28555 | 603 |
|
30904 | 604 |
@Override |
605 |
SSLEngine createSSLEngineImpl() { |
|
56542 | 606 |
return new SSLEngineImpl(this); |
30904 | 607 |
} |
28555 | 608 |
|
30904 | 609 |
@Override |
610 |
SSLEngine createSSLEngineImpl(String host, int port) { |
|
56542 | 611 |
return new SSLEngineImpl(this, host, port); |
612 |
} |
|
613 |
||
614 |
@Override |
|
615 |
boolean isDTLS() { |
|
616 |
return false; |
|
28555 | 617 |
} |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
618 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
619 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
620 |
/* |
22068 | 621 |
* The SSLContext implementation for SSLv3 and TLS10 algorithm |
622 |
* |
|
623 |
* @see SSLContext |
|
624 |
*/ |
|
30904 | 625 |
public static final class TLS10Context extends AbstractTLSContext { |
56542 | 626 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
627 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
22068 | 628 |
|
629 |
static { |
|
630 |
if (SunJSSE.isFIPS()) { |
|
56542 | 631 |
clientDefaultProtocols = getAvailableProtocols( |
632 |
new ProtocolVersion[] { |
|
28555 | 633 |
ProtocolVersion.TLS10 |
56542 | 634 |
}); |
28555 | 635 |
} else { |
56542 | 636 |
clientDefaultProtocols = getAvailableProtocols( |
637 |
new ProtocolVersion[] { |
|
638 |
ProtocolVersion.TLS10, |
|
639 |
ProtocolVersion.SSL30 |
|
640 |
}); |
|
28555 | 641 |
} |
22068 | 642 |
|
56542 | 643 |
clientDefaultCipherSuites = getApplicableEnabledCipherSuites( |
644 |
clientDefaultProtocols, true); |
|
22068 | 645 |
} |
646 |
||
647 |
@Override |
|
56542 | 648 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
649 |
return clientDefaultProtocols; |
|
34826 | 650 |
} |
651 |
||
652 |
@Override |
|
56542 | 653 |
List<CipherSuite> getClientDefaultCipherSuites() { |
654 |
return clientDefaultCipherSuites; |
|
22068 | 655 |
} |
656 |
} |
|
657 |
||
658 |
/* |
|
659 |
* The SSLContext implementation for TLS11 algorithm |
|
660 |
* |
|
661 |
* @see SSLContext |
|
662 |
*/ |
|
30904 | 663 |
public static final class TLS11Context extends AbstractTLSContext { |
56542 | 664 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
665 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
22068 | 666 |
|
667 |
static { |
|
668 |
if (SunJSSE.isFIPS()) { |
|
56542 | 669 |
clientDefaultProtocols = getAvailableProtocols( |
670 |
new ProtocolVersion[] { |
|
671 |
ProtocolVersion.TLS11, |
|
672 |
ProtocolVersion.TLS10 |
|
673 |
}); |
|
28555 | 674 |
} else { |
56542 | 675 |
clientDefaultProtocols = getAvailableProtocols( |
676 |
new ProtocolVersion[] { |
|
677 |
ProtocolVersion.TLS11, |
|
28555 | 678 |
ProtocolVersion.TLS10, |
56542 | 679 |
ProtocolVersion.SSL30 |
680 |
}); |
|
28555 | 681 |
} |
22068 | 682 |
|
56542 | 683 |
clientDefaultCipherSuites = getApplicableEnabledCipherSuites( |
684 |
clientDefaultProtocols, true); |
|
40275
6a37d5a9619d
8162362: Introduce system property to control enabled ciphersuites
xuelei
parents:
37781
diff
changeset
|
685 |
|
22068 | 686 |
} |
687 |
||
688 |
@Override |
|
56542 | 689 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
690 |
return clientDefaultProtocols; |
|
34826 | 691 |
} |
692 |
||
693 |
@Override |
|
56542 | 694 |
List<CipherSuite> getClientDefaultCipherSuites() { |
695 |
return clientDefaultCipherSuites; |
|
22068 | 696 |
} |
697 |
} |
|
698 |
||
699 |
/* |
|
700 |
* The SSLContext implementation for TLS12 algorithm |
|
701 |
* |
|
702 |
* @see SSLContext |
|
703 |
*/ |
|
30904 | 704 |
public static final class TLS12Context extends AbstractTLSContext { |
56542 | 705 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
706 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
22068 | 707 |
|
708 |
static { |
|
709 |
if (SunJSSE.isFIPS()) { |
|
56542 | 710 |
clientDefaultProtocols = getAvailableProtocols( |
711 |
new ProtocolVersion[] { |
|
712 |
ProtocolVersion.TLS12, |
|
28555 | 713 |
ProtocolVersion.TLS11, |
56542 | 714 |
ProtocolVersion.TLS10 |
715 |
}); |
|
28555 | 716 |
} else { |
56542 | 717 |
clientDefaultProtocols = getAvailableProtocols( |
718 |
new ProtocolVersion[] { |
|
719 |
ProtocolVersion.TLS12, |
|
720 |
ProtocolVersion.TLS11, |
|
28555 | 721 |
ProtocolVersion.TLS10, |
56542 | 722 |
ProtocolVersion.SSL30 |
723 |
}); |
|
28555 | 724 |
} |
22068 | 725 |
|
56542 | 726 |
clientDefaultCipherSuites = getApplicableEnabledCipherSuites( |
727 |
clientDefaultProtocols, true); |
|
728 |
} |
|
729 |
||
730 |
@Override |
|
731 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
|
732 |
return clientDefaultProtocols; |
|
22068 | 733 |
} |
734 |
||
735 |
@Override |
|
56542 | 736 |
List<CipherSuite> getClientDefaultCipherSuites() { |
737 |
return clientDefaultCipherSuites; |
|
738 |
} |
|
739 |
} |
|
740 |
||
741 |
/* |
|
742 |
* The SSLContext implementation for TLS1.3 algorithm |
|
743 |
* |
|
744 |
* @see SSLContext |
|
745 |
*/ |
|
746 |
public static final class TLS13Context extends AbstractTLSContext { |
|
747 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
|
748 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
749 |
||
750 |
static { |
|
751 |
if (SunJSSE.isFIPS()) { |
|
752 |
clientDefaultProtocols = getAvailableProtocols( |
|
753 |
new ProtocolVersion[] { |
|
754 |
ProtocolVersion.TLS13, |
|
755 |
ProtocolVersion.TLS12, |
|
756 |
ProtocolVersion.TLS11, |
|
757 |
ProtocolVersion.TLS10 |
|
758 |
}); |
|
759 |
} else { |
|
760 |
clientDefaultProtocols = getAvailableProtocols( |
|
761 |
new ProtocolVersion[] { |
|
762 |
ProtocolVersion.TLS13, |
|
763 |
ProtocolVersion.TLS12, |
|
764 |
ProtocolVersion.TLS11, |
|
765 |
ProtocolVersion.TLS10, |
|
766 |
ProtocolVersion.SSL30 |
|
767 |
}); |
|
768 |
} |
|
769 |
||
770 |
clientDefaultCipherSuites = getApplicableEnabledCipherSuites( |
|
771 |
clientDefaultProtocols, true); |
|
34826 | 772 |
} |
773 |
||
774 |
@Override |
|
56542 | 775 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
776 |
return clientDefaultProtocols; |
|
777 |
} |
|
778 |
||
779 |
@Override |
|
780 |
List<CipherSuite> getClientDefaultCipherSuites() { |
|
781 |
return clientDefaultCipherSuites; |
|
22068 | 782 |
} |
783 |
} |
|
784 |
||
785 |
/* |
|
30904 | 786 |
* The interface for the customized SSL/(D)TLS SSLContext. |
787 |
* |
|
788 |
* @see SSLContext |
|
789 |
*/ |
|
790 |
private static class CustomizedSSLProtocols { |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32032
diff
changeset
|
791 |
private static final String PROPERTY_NAME = "jdk.tls.client.protocols"; |
30904 | 792 |
static IllegalArgumentException reservedException = null; |
56542 | 793 |
static final ArrayList<ProtocolVersion> |
30904 | 794 |
customizedProtocols = new ArrayList<>(); |
795 |
||
796 |
// Don't want a java.lang.LinkageError for illegal system property. |
|
797 |
// |
|
798 |
// Please don't throw exception in this static block. Otherwise, |
|
799 |
// java.lang.LinkageError may be thrown during the instantiation of |
|
800 |
// the provider service. Instead, please handle the initialization |
|
801 |
// exception in the caller's constructor. |
|
802 |
static { |
|
37781
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37593
diff
changeset
|
803 |
String property = GetPropertyAction |
71ed5645f17c
8155775: Re-examine naming of privileged methods to access System properties
redestad
parents:
37593
diff
changeset
|
804 |
.privilegedGetProperty(PROPERTY_NAME); |
30904 | 805 |
if (property != null && property.length() != 0) { |
806 |
// remove double quote marks from beginning/end of the property |
|
807 |
if (property.length() > 1 && property.charAt(0) == '"' && |
|
808 |
property.charAt(property.length() - 1) == '"') { |
|
809 |
property = property.substring(1, property.length() - 1); |
|
810 |
} |
|
811 |
} |
|
812 |
||
813 |
if (property != null && property.length() != 0) { |
|
814 |
String[] protocols = property.split(","); |
|
815 |
for (int i = 0; i < protocols.length; i++) { |
|
816 |
protocols[i] = protocols[i].trim(); |
|
817 |
// Is it a supported protocol name? |
|
56542 | 818 |
ProtocolVersion pv = |
819 |
ProtocolVersion.nameOf(protocols[i]); |
|
820 |
if (pv == null) { |
|
821 |
reservedException = new IllegalArgumentException( |
|
822 |
PROPERTY_NAME + ": " + protocols[i] + |
|
823 |
" is not a supported SSL protocol name"); |
|
824 |
} |
|
30904 | 825 |
|
56542 | 826 |
if (SunJSSE.isFIPS() && |
827 |
((pv == ProtocolVersion.SSL30) || |
|
828 |
(pv == ProtocolVersion.SSL20Hello))) { |
|
829 |
reservedException = new IllegalArgumentException( |
|
830 |
PROPERTY_NAME + ": " + pv + |
|
831 |
" is not FIPS compliant"); |
|
30904 | 832 |
|
56542 | 833 |
break; |
834 |
} |
|
835 |
||
836 |
// ignore duplicated protocols |
|
837 |
if (!customizedProtocols.contains(pv)) { |
|
838 |
customizedProtocols.add(pv); |
|
30904 | 839 |
} |
840 |
} |
|
841 |
} |
|
842 |
} |
|
843 |
} |
|
844 |
||
845 |
/* |
|
22068 | 846 |
* The SSLContext implementation for customized TLS protocols |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
847 |
* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
848 |
* @see SSLContext |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
849 |
*/ |
30904 | 850 |
private static class CustomizedTLSContext extends AbstractTLSContext { |
851 |
||
56542 | 852 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
853 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
854 |
private static final IllegalArgumentException reservedException; |
|
22068 | 855 |
|
856 |
// Don't want a java.lang.LinkageError for illegal system property. |
|
857 |
// |
|
858 |
// Please don't throw exception in this static block. Otherwise, |
|
859 |
// java.lang.LinkageError may be thrown during the instantiation of |
|
860 |
// the provider service. Instead, let's handle the initialization |
|
861 |
// exception in constructor. |
|
862 |
static { |
|
30904 | 863 |
reservedException = CustomizedSSLProtocols.reservedException; |
864 |
if (reservedException == null) { |
|
865 |
ArrayList<ProtocolVersion> |
|
866 |
customizedTLSProtocols = new ArrayList<>(); |
|
867 |
for (ProtocolVersion protocol : |
|
868 |
CustomizedSSLProtocols.customizedProtocols) { |
|
56542 | 869 |
if (!protocol.isDTLS) { |
30904 | 870 |
customizedTLSProtocols.add(protocol); |
22068 | 871 |
} |
872 |
} |
|
873 |
||
30904 | 874 |
// candidates for available protocols |
875 |
ProtocolVersion[] candidates; |
|
876 |
if (customizedTLSProtocols.isEmpty()) { |
|
877 |
// Use the default enabled client protocols if no |
|
878 |
// customized TLS protocols. |
|
879 |
if (SunJSSE.isFIPS()) { |
|
880 |
candidates = new ProtocolVersion[] { |
|
56542 | 881 |
ProtocolVersion.TLS13, |
882 |
ProtocolVersion.TLS12, |
|
30904 | 883 |
ProtocolVersion.TLS11, |
56542 | 884 |
ProtocolVersion.TLS10 |
30904 | 885 |
}; |
886 |
} else { |
|
887 |
candidates = new ProtocolVersion[] { |
|
56542 | 888 |
ProtocolVersion.TLS13, |
889 |
ProtocolVersion.TLS12, |
|
890 |
ProtocolVersion.TLS11, |
|
30904 | 891 |
ProtocolVersion.TLS10, |
56542 | 892 |
ProtocolVersion.SSL30 |
30904 | 893 |
}; |
22068 | 894 |
} |
30904 | 895 |
} else { |
896 |
// Use the customized TLS protocols. |
|
897 |
candidates = |
|
898 |
new ProtocolVersion[customizedTLSProtocols.size()]; |
|
899 |
candidates = customizedTLSProtocols.toArray(candidates); |
|
22068 | 900 |
} |
901 |
||
56542 | 902 |
clientDefaultProtocols = getAvailableProtocols(candidates); |
903 |
clientDefaultCipherSuites = |
|
904 |
getApplicableEnabledCipherSuites( |
|
905 |
clientDefaultProtocols, true); |
|
30904 | 906 |
} else { |
56542 | 907 |
clientDefaultProtocols = null; // unlikely to be used |
908 |
clientDefaultCipherSuites = null; // unlikely to be used |
|
22068 | 909 |
} |
910 |
} |
|
911 |
||
30904 | 912 |
protected CustomizedTLSContext() { |
22068 | 913 |
if (reservedException != null) { |
914 |
throw reservedException; |
|
915 |
} |
|
916 |
} |
|
917 |
||
918 |
@Override |
|
56542 | 919 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
920 |
return clientDefaultProtocols; |
|
34826 | 921 |
} |
922 |
||
923 |
@Override |
|
56542 | 924 |
List<CipherSuite> getClientDefaultCipherSuites() { |
925 |
return clientDefaultCipherSuites; |
|
22068 | 926 |
} |
927 |
} |
|
928 |
||
929 |
/* |
|
930 |
* The SSLContext implementation for default "TLS" algorithm |
|
931 |
* |
|
932 |
* @see SSLContext |
|
933 |
*/ |
|
30904 | 934 |
public static final class TLSContext extends CustomizedTLSContext { |
22068 | 935 |
// use the default constructor and methods |
936 |
} |
|
937 |
||
34826 | 938 |
// lazy initialization holder class idiom for static default parameters |
939 |
// |
|
940 |
// See Effective Java Second Edition: Item 71. |
|
941 |
private static final class DefaultManagersHolder { |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
942 |
private static final String NONE = "NONE"; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
943 |
private static final String P11KEYSTORE = "PKCS11"; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
944 |
|
34826 | 945 |
private static final TrustManager[] trustManagers; |
946 |
private static final KeyManager[] keyManagers; |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
947 |
|
56542 | 948 |
private static final Exception reservedException; |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
949 |
|
34826 | 950 |
static { |
56542 | 951 |
Exception reserved = null; |
34826 | 952 |
TrustManager[] tmMediator; |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
953 |
try { |
34826 | 954 |
tmMediator = getTrustManagers(); |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
955 |
} catch (Exception e) { |
56542 | 956 |
reserved = e; |
34826 | 957 |
tmMediator = new TrustManager[0]; |
958 |
} |
|
959 |
trustManagers = tmMediator; |
|
960 |
||
56542 | 961 |
if (reserved == null) { |
34826 | 962 |
KeyManager[] kmMediator; |
963 |
try { |
|
964 |
kmMediator = getKeyManagers(); |
|
965 |
} catch (Exception e) { |
|
56542 | 966 |
reserved = e; |
34826 | 967 |
kmMediator = new KeyManager[0]; |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
968 |
} |
34826 | 969 |
keyManagers = kmMediator; |
970 |
} else { |
|
971 |
keyManagers = new KeyManager[0]; |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
972 |
} |
56542 | 973 |
|
974 |
reservedException = reserved; |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
975 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
976 |
|
34826 | 977 |
private static TrustManager[] getTrustManagers() throws Exception { |
43009
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
978 |
TrustManagerFactory tmf = TrustManagerFactory.getInstance( |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
979 |
TrustManagerFactory.getDefaultAlgorithm()); |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
980 |
if ("SunJSSE".equals(tmf.getProvider().getName())) { |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
981 |
// The implementation will load the default KeyStore |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
982 |
// automatically. Cached trust materials may be used |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
983 |
// for performance improvement. |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
984 |
tmf.init((KeyStore)null); |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
985 |
} else { |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
986 |
// Use the explicitly specified KeyStore for third party's |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
987 |
// TrustManagerFactory implementation. |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
988 |
KeyStore ks = TrustStoreManager.getTrustedKeyStore(); |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
989 |
tmf.init(ks); |
5af9f7aa93e5
8129988: JSSE should create a single instance of the cacerts KeyStore
xuelei
parents:
42221
diff
changeset
|
990 |
} |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
991 |
|
34826 | 992 |
return tmf.getTrustManagers(); |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
993 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
994 |
|
34826 | 995 |
private static KeyManager[] getKeyManagers() throws Exception { |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
996 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
997 |
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
|
998 |
AccessController.doPrivileged( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
999 |
new PrivilegedExceptionAction<Object>() { |
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1000 |
@Override |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1001 |
public Object run() throws Exception { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1002 |
props.put("keyStore", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1003 |
"javax.net.ssl.keyStore", "")); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1004 |
props.put("keyStoreType", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1005 |
"javax.net.ssl.keyStoreType", |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1006 |
KeyStore.getDefaultType())); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1007 |
props.put("keyStoreProvider", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1008 |
"javax.net.ssl.keyStoreProvider", "")); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1009 |
props.put("keyStorePasswd", System.getProperty( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1010 |
"javax.net.ssl.keyStorePassword", "")); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1011 |
return null; |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1012 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1013 |
}); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1014 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1015 |
final String defaultKeyStore = props.get("keyStore"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1016 |
String defaultKeyStoreType = props.get("keyStoreType"); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1017 |
String defaultKeyStoreProvider = props.get("keyStoreProvider"); |
56542 | 1018 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,defaultctx")) { |
1019 |
SSLLogger.fine("keyStore is : " + defaultKeyStore); |
|
1020 |
SSLLogger.fine("keyStore type is : " + |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1021 |
defaultKeyStoreType); |
56542 | 1022 |
SSLLogger.fine("keyStore provider is : " + |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1023 |
defaultKeyStoreProvider); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1024 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1025 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1026 |
if (P11KEYSTORE.equals(defaultKeyStoreType) && |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1027 |
!NONE.equals(defaultKeyStore)) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1028 |
throw new IllegalArgumentException("if keyStoreType is " |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1029 |
+ P11KEYSTORE + ", then keyStore must be " + NONE); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1030 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1031 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1032 |
FileInputStream fs = null; |
10125 | 1033 |
KeyStore ks = null; |
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1034 |
char[] passwd = null; |
10125 | 1035 |
try { |
1036 |
if (defaultKeyStore.length() != 0 && |
|
1037 |
!NONE.equals(defaultKeyStore)) { |
|
1038 |
fs = AccessController.doPrivileged( |
|
1039 |
new PrivilegedExceptionAction<FileInputStream>() { |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1040 |
@Override |
10125 | 1041 |
public FileInputStream run() throws Exception { |
1042 |
return new FileInputStream(defaultKeyStore); |
|
1043 |
} |
|
1044 |
}); |
|
1045 |
} |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1046 |
|
10125 | 1047 |
String defaultKeyStorePassword = props.get("keyStorePasswd"); |
1048 |
if (defaultKeyStorePassword.length() != 0) { |
|
1049 |
passwd = defaultKeyStorePassword.toCharArray(); |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1050 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1051 |
|
10125 | 1052 |
/** |
1053 |
* Try to initialize key store. |
|
1054 |
*/ |
|
1055 |
if ((defaultKeyStoreType.length()) != 0) { |
|
56542 | 1056 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,defaultctx")) { |
1057 |
SSLLogger.finest("init keystore"); |
|
10125 | 1058 |
} |
1059 |
if (defaultKeyStoreProvider.length() == 0) { |
|
1060 |
ks = KeyStore.getInstance(defaultKeyStoreType); |
|
1061 |
} else { |
|
1062 |
ks = KeyStore.getInstance(defaultKeyStoreType, |
|
1063 |
defaultKeyStoreProvider); |
|
1064 |
} |
|
1065 |
||
1066 |
// if defaultKeyStore is NONE, fs will be null |
|
1067 |
ks.load(fs, passwd); |
|
1068 |
} |
|
1069 |
} finally { |
|
1070 |
if (fs != null) { |
|
1071 |
fs.close(); |
|
1072 |
fs = null; |
|
1073 |
} |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1074 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1075 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1076 |
/* |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1077 |
* Try to initialize key manager. |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1078 |
*/ |
56542 | 1079 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,defaultctx")) { |
1080 |
SSLLogger.fine("init keymanager of type " + |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1081 |
KeyManagerFactory.getDefaultAlgorithm()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1082 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1083 |
KeyManagerFactory kmf = KeyManagerFactory.getInstance( |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1084 |
KeyManagerFactory.getDefaultAlgorithm()); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1085 |
|
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1086 |
if (P11KEYSTORE.equals(defaultKeyStoreType)) { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1087 |
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
|
1088 |
} else { |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1089 |
kmf.init(ks, passwd); |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1090 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1091 |
|
34826 | 1092 |
return kmf.getKeyManagers(); |
1093 |
} |
|
1094 |
} |
|
1095 |
||
1096 |
// lazy initialization holder class idiom for static default parameters |
|
1097 |
// |
|
1098 |
// See Effective Java Second Edition: Item 71. |
|
1099 |
private static final class DefaultSSLContextHolder { |
|
1100 |
||
1101 |
private static final SSLContextImpl sslContext; |
|
1102 |
static Exception reservedException = null; |
|
1103 |
||
1104 |
static { |
|
1105 |
SSLContextImpl mediator = null; |
|
1106 |
if (DefaultManagersHolder.reservedException != null) { |
|
1107 |
reservedException = DefaultManagersHolder.reservedException; |
|
1108 |
} else { |
|
1109 |
try { |
|
1110 |
mediator = new DefaultSSLContext(); |
|
1111 |
} catch (Exception e) { |
|
1112 |
reservedException = e; |
|
1113 |
} |
|
1114 |
} |
|
1115 |
||
1116 |
sslContext = mediator; |
|
1117 |
} |
|
1118 |
} |
|
1119 |
||
1120 |
/* |
|
1121 |
* The SSLContext implementation for default "Default" algorithm |
|
1122 |
* |
|
1123 |
* @see SSLContext |
|
1124 |
*/ |
|
1125 |
public static final class DefaultSSLContext extends CustomizedTLSContext { |
|
1126 |
||
1127 |
// public constructor for SSLContext.getInstance("Default") |
|
1128 |
public DefaultSSLContext() throws Exception { |
|
1129 |
if (DefaultManagersHolder.reservedException != null) { |
|
1130 |
throw DefaultManagersHolder.reservedException; |
|
1131 |
} |
|
1132 |
||
1133 |
try { |
|
1134 |
super.engineInit(DefaultManagersHolder.keyManagers, |
|
1135 |
DefaultManagersHolder.trustManagers, null); |
|
1136 |
} catch (Exception e) { |
|
56542 | 1137 |
if (SSLLogger.isOn && SSLLogger.isOn("ssl,defaultctx")) { |
1138 |
SSLLogger.fine("default context init failed: ", e); |
|
34826 | 1139 |
} |
1140 |
throw e; |
|
1141 |
} |
|
1142 |
} |
|
1143 |
||
1144 |
@Override |
|
1145 |
protected void engineInit(KeyManager[] km, TrustManager[] tm, |
|
1146 |
SecureRandom sr) throws KeyManagementException { |
|
1147 |
throw new KeyManagementException |
|
1148 |
("Default SSLContext is initialized automatically"); |
|
1149 |
} |
|
1150 |
||
1151 |
static SSLContextImpl getDefaultImpl() throws Exception { |
|
1152 |
if (DefaultSSLContextHolder.reservedException != null) { |
|
1153 |
throw DefaultSSLContextHolder.reservedException; |
|
1154 |
} |
|
1155 |
||
1156 |
return DefaultSSLContextHolder.sslContext; |
|
9246
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1157 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1158 |
} |
c459f79af46b
6976117: SSLContext.getInstance("TLSv1.1") returns SSLEngines/SSLSockets without TLSv1.1 enabled
xuelei
parents:
7043
diff
changeset
|
1159 |
|
30904 | 1160 |
/* |
1161 |
* The base abstract SSLContext implementation for the Datagram Transport |
|
1162 |
* Layer Security (DTLS) protocols. |
|
1163 |
* |
|
1164 |
* This abstract class encapsulates supported and the default server DTLS |
|
1165 |
* parameters. |
|
1166 |
* |
|
1167 |
* @see SSLContext |
|
1168 |
*/ |
|
1169 |
private abstract static class AbstractDTLSContext extends SSLContextImpl { |
|
56542 | 1170 |
private static final List<ProtocolVersion> supportedProtocols; |
1171 |
private static final List<ProtocolVersion> serverDefaultProtocols; |
|
34826 | 1172 |
|
56542 | 1173 |
private static final List<CipherSuite> supportedCipherSuites; |
1174 |
private static final List<CipherSuite> serverDefaultCipherSuites; |
|
30904 | 1175 |
|
1176 |
static { |
|
1177 |
// Both DTLSv1.0 and DTLSv1.2 can be used in FIPS mode. |
|
56542 | 1178 |
supportedProtocols = Arrays.asList( |
1179 |
ProtocolVersion.DTLS12, |
|
1180 |
ProtocolVersion.DTLS10 |
|
1181 |
); |
|
30904 | 1182 |
|
34826 | 1183 |
// available protocols for server mode |
56542 | 1184 |
serverDefaultProtocols = getAvailableProtocols( |
1185 |
new ProtocolVersion[] { |
|
1186 |
ProtocolVersion.DTLS12, |
|
1187 |
ProtocolVersion.DTLS10 |
|
1188 |
}); |
|
30904 | 1189 |
|
56542 | 1190 |
supportedCipherSuites = getApplicableSupportedCipherSuites( |
1191 |
supportedProtocols); |
|
1192 |
serverDefaultCipherSuites = getApplicableEnabledCipherSuites( |
|
1193 |
serverDefaultProtocols, false); |
|
30904 | 1194 |
} |
1195 |
||
1196 |
@Override |
|
56542 | 1197 |
List<ProtocolVersion> getSuportedProtocolVersions() { |
1198 |
return supportedProtocols; |
|
30904 | 1199 |
} |
1200 |
||
1201 |
@Override |
|
56542 | 1202 |
List<CipherSuite> getSupportedCipherSuites() { |
1203 |
return supportedCipherSuites; |
|
34826 | 1204 |
} |
1205 |
||
1206 |
@Override |
|
56542 | 1207 |
List<ProtocolVersion> getServerDefaultProtocolVersions() { |
1208 |
return serverDefaultProtocols; |
|
34826 | 1209 |
} |
1210 |
||
1211 |
@Override |
|
56542 | 1212 |
List<CipherSuite> getServerDefaultCipherSuites() { |
1213 |
return serverDefaultCipherSuites; |
|
30904 | 1214 |
} |
1215 |
||
1216 |
@Override |
|
1217 |
SSLEngine createSSLEngineImpl() { |
|
56542 | 1218 |
return new SSLEngineImpl(this); |
30904 | 1219 |
} |
1220 |
||
1221 |
@Override |
|
1222 |
SSLEngine createSSLEngineImpl(String host, int port) { |
|
56542 | 1223 |
return new SSLEngineImpl(this, host, port); |
30904 | 1224 |
} |
1225 |
||
1226 |
@Override |
|
56542 | 1227 |
boolean isDTLS() { |
1228 |
return true; |
|
30904 | 1229 |
} |
1230 |
} |
|
1231 |
||
1232 |
/* |
|
1233 |
* The SSLContext implementation for DTLSv1.0 algorithm. |
|
1234 |
* |
|
1235 |
* @see SSLContext |
|
1236 |
*/ |
|
1237 |
public static final class DTLS10Context extends AbstractDTLSContext { |
|
56542 | 1238 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
1239 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
30904 | 1240 |
|
1241 |
static { |
|
34826 | 1242 |
// available protocols for client mode |
56542 | 1243 |
clientDefaultProtocols = getAvailableProtocols( |
1244 |
new ProtocolVersion[] { |
|
30904 | 1245 |
ProtocolVersion.DTLS10 |
56542 | 1246 |
}); |
30904 | 1247 |
|
56542 | 1248 |
clientDefaultCipherSuites = getApplicableEnabledCipherSuites( |
1249 |
clientDefaultProtocols, true); |
|
30904 | 1250 |
} |
1251 |
||
1252 |
@Override |
|
56542 | 1253 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
1254 |
return clientDefaultProtocols; |
|
34826 | 1255 |
} |
1256 |
||
1257 |
@Override |
|
56542 | 1258 |
List<CipherSuite> getClientDefaultCipherSuites() { |
1259 |
return clientDefaultCipherSuites; |
|
30904 | 1260 |
} |
1261 |
} |
|
1262 |
||
1263 |
/* |
|
1264 |
* The SSLContext implementation for DTLSv1.2 algorithm. |
|
1265 |
* |
|
1266 |
* @see SSLContext |
|
1267 |
*/ |
|
1268 |
public static final class DTLS12Context extends AbstractDTLSContext { |
|
56542 | 1269 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
1270 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
30904 | 1271 |
|
1272 |
static { |
|
34826 | 1273 |
// available protocols for client mode |
56542 | 1274 |
clientDefaultProtocols = getAvailableProtocols( |
1275 |
new ProtocolVersion[] { |
|
1276 |
ProtocolVersion.DTLS12, |
|
1277 |
ProtocolVersion.DTLS10 |
|
1278 |
}); |
|
30904 | 1279 |
|
56542 | 1280 |
clientDefaultCipherSuites = getApplicableEnabledCipherSuites( |
1281 |
clientDefaultProtocols, true); |
|
30904 | 1282 |
} |
1283 |
||
1284 |
@Override |
|
56542 | 1285 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
1286 |
return clientDefaultProtocols; |
|
34826 | 1287 |
} |
1288 |
||
1289 |
@Override |
|
56542 | 1290 |
List<CipherSuite> getClientDefaultCipherSuites() { |
1291 |
return clientDefaultCipherSuites; |
|
30904 | 1292 |
} |
1293 |
} |
|
1294 |
||
1295 |
/* |
|
1296 |
* The SSLContext implementation for customized TLS protocols |
|
1297 |
* |
|
1298 |
* @see SSLContext |
|
1299 |
*/ |
|
1300 |
private static class CustomizedDTLSContext extends AbstractDTLSContext { |
|
56542 | 1301 |
private static final List<ProtocolVersion> clientDefaultProtocols; |
1302 |
private static final List<CipherSuite> clientDefaultCipherSuites; |
|
34826 | 1303 |
|
30904 | 1304 |
private static IllegalArgumentException reservedException = null; |
1305 |
||
1306 |
// Don't want a java.lang.LinkageError for illegal system property. |
|
1307 |
// |
|
1308 |
// Please don't throw exception in this static block. Otherwise, |
|
1309 |
// java.lang.LinkageError may be thrown during the instantiation of |
|
1310 |
// the provider service. Instead, let's handle the initialization |
|
1311 |
// exception in constructor. |
|
1312 |
static { |
|
1313 |
reservedException = CustomizedSSLProtocols.reservedException; |
|
1314 |
if (reservedException == null) { |
|
1315 |
ArrayList<ProtocolVersion> |
|
1316 |
customizedDTLSProtocols = new ArrayList<>(); |
|
1317 |
for (ProtocolVersion protocol : |
|
1318 |
CustomizedSSLProtocols.customizedProtocols) { |
|
56542 | 1319 |
if (protocol.isDTLS) { |
30904 | 1320 |
customizedDTLSProtocols.add(protocol); |
1321 |
} |
|
1322 |
} |
|
1323 |
||
1324 |
// candidates for available protocols |
|
1325 |
ProtocolVersion[] candidates; |
|
1326 |
if (customizedDTLSProtocols.isEmpty()) { |
|
1327 |
// Use the default enabled client protocols if no |
|
1328 |
// customized TLS protocols. |
|
1329 |
// |
|
1330 |
// Both DTLSv1.0 and DTLSv1.2 can be used in FIPS mode. |
|
1331 |
candidates = new ProtocolVersion[] { |
|
56542 | 1332 |
ProtocolVersion.DTLS12, |
1333 |
ProtocolVersion.DTLS10 |
|
30904 | 1334 |
}; |
1335 |
||
1336 |
} else { |
|
1337 |
// Use the customized TLS protocols. |
|
1338 |
candidates = |
|
1339 |
new ProtocolVersion[customizedDTLSProtocols.size()]; |
|
1340 |
candidates = customizedDTLSProtocols.toArray(candidates); |
|
1341 |
} |
|
1342 |
||
56542 | 1343 |
clientDefaultProtocols = getAvailableProtocols(candidates); |
1344 |
clientDefaultCipherSuites = |
|
1345 |
getApplicableEnabledCipherSuites( |
|
1346 |
clientDefaultProtocols, true); |
|
30904 | 1347 |
} else { |
56542 | 1348 |
clientDefaultProtocols = null; // unlikely to be used |
1349 |
clientDefaultCipherSuites = null; // unlikely to be used |
|
30904 | 1350 |
} |
1351 |
} |
|
1352 |
||
1353 |
protected CustomizedDTLSContext() { |
|
1354 |
if (reservedException != null) { |
|
1355 |
throw reservedException; |
|
1356 |
} |
|
1357 |
} |
|
1358 |
||
1359 |
@Override |
|
56542 | 1360 |
List<ProtocolVersion> getClientDefaultProtocolVersions() { |
1361 |
return clientDefaultProtocols; |
|
34826 | 1362 |
} |
1363 |
||
1364 |
@Override |
|
56542 | 1365 |
List<CipherSuite> getClientDefaultCipherSuites() { |
1366 |
return clientDefaultCipherSuites; |
|
30904 | 1367 |
} |
1368 |
} |
|
1369 |
||
1370 |
/* |
|
1371 |
* The SSLContext implementation for default "DTLS" algorithm |
|
1372 |
* |
|
1373 |
* @see SSLContext |
|
1374 |
*/ |
|
1375 |
public static final class DTLSContext extends CustomizedDTLSContext { |
|
1376 |
// use the default constructor and methods |
|
1377 |
} |
|
1378 |
||
2 | 1379 |
} |
1380 |
||
7043 | 1381 |
final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager |
1382 |
implements X509TrustManager { |
|
1383 |
||
11037
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1384 |
// the delegated trust manager |
7043 | 1385 |
private final X509TrustManager tm; |
1386 |
||
1387 |
AbstractTrustManagerWrapper(X509TrustManager tm) { |
|
1388 |
this.tm = tm; |
|
1389 |
} |
|
1390 |
||
1391 |
@Override |
|
1392 |
public void checkClientTrusted(X509Certificate[] chain, String authType) |
|
1393 |
throws CertificateException { |
|
1394 |
tm.checkClientTrusted(chain, authType); |
|
1395 |
} |
|
1396 |
||
1397 |
@Override |
|
1398 |
public void checkServerTrusted(X509Certificate[] chain, String authType) |
|
1399 |
throws CertificateException { |
|
1400 |
tm.checkServerTrusted(chain, authType); |
|
1401 |
} |
|
1402 |
||
1403 |
@Override |
|
1404 |
public X509Certificate[] getAcceptedIssuers() { |
|
1405 |
return tm.getAcceptedIssuers(); |
|
1406 |
} |
|
1407 |
||
1408 |
@Override |
|
1409 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
1410 |
Socket socket) throws CertificateException { |
|
1411 |
tm.checkClientTrusted(chain, authType); |
|
1412 |
checkAdditionalTrust(chain, authType, socket, true); |
|
1413 |
} |
|
1414 |
||
1415 |
@Override |
|
1416 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
1417 |
Socket socket) throws CertificateException { |
|
1418 |
tm.checkServerTrusted(chain, authType); |
|
1419 |
checkAdditionalTrust(chain, authType, socket, false); |
|
1420 |
} |
|
1421 |
||
1422 |
@Override |
|
1423 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
1424 |
SSLEngine engine) throws CertificateException { |
|
1425 |
tm.checkClientTrusted(chain, authType); |
|
1426 |
checkAdditionalTrust(chain, authType, engine, true); |
|
1427 |
} |
|
1428 |
||
1429 |
@Override |
|
1430 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
1431 |
SSLEngine engine) throws CertificateException { |
|
1432 |
tm.checkServerTrusted(chain, authType); |
|
1433 |
checkAdditionalTrust(chain, authType, engine, false); |
|
1434 |
} |
|
1435 |
||
1436 |
private void checkAdditionalTrust(X509Certificate[] chain, String authType, |
|
1437 |
Socket socket, boolean isClient) throws CertificateException { |
|
1438 |
if (socket != null && socket.isConnected() && |
|
1439 |
socket instanceof SSLSocket) { |
|
1440 |
||
1441 |
SSLSocket sslSocket = (SSLSocket)socket; |
|
1442 |
SSLSession session = sslSocket.getHandshakeSession(); |
|
1443 |
if (session == null) { |
|
1444 |
throw new CertificateException("No handshake session"); |
|
1445 |
} |
|
1446 |
||
1447 |
// check endpoint identity |
|
1448 |
String identityAlg = sslSocket.getSSLParameters(). |
|
1449 |
getEndpointIdentificationAlgorithm(); |
|
1450 |
if (identityAlg != null && identityAlg.length() != 0) { |
|
1451 |
String hostname = session.getPeerHost(); |
|
1452 |
X509TrustManagerImpl.checkIdentity( |
|
1453 |
hostname, chain[0], identityAlg); |
|
1454 |
} |
|
1455 |
||
1456 |
// try the best to check the algorithm constraints |
|
56542 | 1457 |
AlgorithmConstraints constraints; |
1458 |
if (ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) { |
|
7043 | 1459 |
if (session instanceof ExtendedSSLSession) { |
1460 |
ExtendedSSLSession extSession = |
|
1461 |
(ExtendedSSLSession)session; |
|
1462 |
String[] peerSupportedSignAlgs = |
|
1463 |
extSession.getLocalSupportedSignatureAlgorithms(); |
|
1464 |
||
1465 |
constraints = new SSLAlgorithmConstraints( |
|
1466 |
sslSocket, peerSupportedSignAlgs, true); |
|
1467 |
} else { |
|
1468 |
constraints = |
|
1469 |
new SSLAlgorithmConstraints(sslSocket, true); |
|
1470 |
} |
|
1471 |
} else { |
|
1472 |
constraints = new SSLAlgorithmConstraints(sslSocket, true); |
|
1473 |
} |
|
1474 |
||
43701
fe8c324ba97c
8160655: Fix denyAfter and usage types for security properties
ascarpino
parents:
43009
diff
changeset
|
1475 |
checkAlgorithmConstraints(chain, constraints, isClient); |
7043 | 1476 |
} |
1477 |
} |
|
1478 |
||
1479 |
private void checkAdditionalTrust(X509Certificate[] chain, String authType, |
|
1480 |
SSLEngine engine, boolean isClient) throws CertificateException { |
|
1481 |
if (engine != null) { |
|
1482 |
SSLSession session = engine.getHandshakeSession(); |
|
1483 |
if (session == null) { |
|
1484 |
throw new CertificateException("No handshake session"); |
|
1485 |
} |
|
1486 |
||
1487 |
// check endpoint identity |
|
1488 |
String identityAlg = engine.getSSLParameters(). |
|
1489 |
getEndpointIdentificationAlgorithm(); |
|
1490 |
if (identityAlg != null && identityAlg.length() != 0) { |
|
1491 |
String hostname = session.getPeerHost(); |
|
1492 |
X509TrustManagerImpl.checkIdentity( |
|
1493 |
hostname, chain[0], identityAlg); |
|
1494 |
} |
|
1495 |
||
1496 |
// try the best to check the algorithm constraints |
|
56542 | 1497 |
AlgorithmConstraints constraints; |
1498 |
if (ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) { |
|
7043 | 1499 |
if (session instanceof ExtendedSSLSession) { |
1500 |
ExtendedSSLSession extSession = |
|
1501 |
(ExtendedSSLSession)session; |
|
1502 |
String[] peerSupportedSignAlgs = |
|
1503 |
extSession.getLocalSupportedSignatureAlgorithms(); |
|
1504 |
||
1505 |
constraints = new SSLAlgorithmConstraints( |
|
1506 |
engine, peerSupportedSignAlgs, true); |
|
1507 |
} else { |
|
1508 |
constraints = |
|
1509 |
new SSLAlgorithmConstraints(engine, true); |
|
1510 |
} |
|
1511 |
} else { |
|
1512 |
constraints = new SSLAlgorithmConstraints(engine, true); |
|
1513 |
} |
|
1514 |
||
43701
fe8c324ba97c
8160655: Fix denyAfter and usage types for security properties
ascarpino
parents:
43009
diff
changeset
|
1515 |
checkAlgorithmConstraints(chain, constraints, isClient); |
11037
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1516 |
} |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1517 |
} |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1518 |
|
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1519 |
private void checkAlgorithmConstraints(X509Certificate[] chain, |
56542 | 1520 |
AlgorithmConstraints constraints, |
1521 |
boolean isClient) throws CertificateException { |
|
11037
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1522 |
try { |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1523 |
// Does the certificate chain end with a trusted certificate? |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1524 |
int checkedLength = chain.length - 1; |
12302
0c8557ba0b8f
7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
11037
diff
changeset
|
1525 |
|
0c8557ba0b8f
7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
11037
diff
changeset
|
1526 |
Collection<X509Certificate> trustedCerts = new HashSet<>(); |
0c8557ba0b8f
7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
11037
diff
changeset
|
1527 |
X509Certificate[] certs = tm.getAcceptedIssuers(); |
0c8557ba0b8f
7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
11037
diff
changeset
|
1528 |
if ((certs != null) && (certs.length > 0)){ |
0c8557ba0b8f
7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
11037
diff
changeset
|
1529 |
Collections.addAll(trustedCerts, certs); |
0c8557ba0b8f
7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
11037
diff
changeset
|
1530 |
} |
0c8557ba0b8f
7142172: Custom TrustManagers that return null for getAcceptedIssuers will NPE
wetmore
parents:
11037
diff
changeset
|
1531 |
|
11037
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1532 |
if (trustedCerts.contains(chain[checkedLength])) { |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1533 |
checkedLength--; |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1534 |
} |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1535 |
|
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1536 |
// A forward checker, need to check from trust to target |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1537 |
if (checkedLength >= 0) { |
43701
fe8c324ba97c
8160655: Fix denyAfter and usage types for security properties
ascarpino
parents:
43009
diff
changeset
|
1538 |
AlgorithmChecker checker = |
56542 | 1539 |
new AlgorithmChecker(constraints, null, |
1540 |
(isClient ? Validator.VAR_TLS_CLIENT : |
|
1541 |
Validator.VAR_TLS_SERVER)); |
|
7043 | 1542 |
checker.init(false); |
11037
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1543 |
for (int i = checkedLength; i >= 0; i--) { |
56542 | 1544 |
X509Certificate cert = chain[i]; |
7043 | 1545 |
// We don't care about the unresolved critical extensions. |
1546 |
checker.check(cert, Collections.<String>emptySet()); |
|
1547 |
} |
|
1548 |
} |
|
11037
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1549 |
} catch (CertPathValidatorException cpve) { |
03c29eb4afa0
7113275: compatibility issue with MD2 trust anchor and old X509TrustManager
xuelei
parents:
10125
diff
changeset
|
1550 |
throw new CertificateException( |
40700
b75806acf716
8164846: CertificateException missing cause of underlying exception
coffeys
parents:
40275
diff
changeset
|
1551 |
"Certificates do not conform to algorithm constraints", cpve); |
7043 | 1552 |
} |
1553 |
} |
|
1554 |
} |
|
1555 |
||
2 | 1556 |
// Dummy X509TrustManager implementation, rejects all peer certificates. |
1557 |
// Used if the application did not specify a proper X509TrustManager. |
|
7043 | 1558 |
final class DummyX509TrustManager extends X509ExtendedTrustManager |
1559 |
implements X509TrustManager { |
|
2 | 1560 |
|
1561 |
static final X509TrustManager INSTANCE = new DummyX509TrustManager(); |
|
1562 |
||
1563 |
private DummyX509TrustManager() { |
|
1564 |
// empty |
|
1565 |
} |
|
1566 |
||
1567 |
/* |
|
1568 |
* Given the partial or complete certificate chain |
|
1569 |
* provided by the peer, build a certificate path |
|
1570 |
* to a trusted root and return if it can be |
|
1571 |
* validated and is trusted for client SSL authentication. |
|
1572 |
* If not, it throws an exception. |
|
1573 |
*/ |
|
7043 | 1574 |
@Override |
2 | 1575 |
public void checkClientTrusted(X509Certificate[] chain, String authType) |
1576 |
throws CertificateException { |
|
1577 |
throw new CertificateException( |
|
1578 |
"No X509TrustManager implementation avaiable"); |
|
1579 |
} |
|
1580 |
||
1581 |
/* |
|
1582 |
* Given the partial or complete certificate chain |
|
1583 |
* provided by the peer, build a certificate path |
|
1584 |
* to a trusted root and return if it can be |
|
1585 |
* validated and is trusted for server SSL authentication. |
|
1586 |
* If not, it throws an exception. |
|
1587 |
*/ |
|
7043 | 1588 |
@Override |
2 | 1589 |
public void checkServerTrusted(X509Certificate[] chain, String authType) |
1590 |
throws CertificateException { |
|
1591 |
throw new CertificateException( |
|
1592 |
"No X509TrustManager implementation available"); |
|
1593 |
} |
|
1594 |
||
1595 |
/* |
|
1596 |
* Return an array of issuer certificates which are trusted |
|
1597 |
* for authenticating peers. |
|
1598 |
*/ |
|
7043 | 1599 |
@Override |
2 | 1600 |
public X509Certificate[] getAcceptedIssuers() { |
1601 |
return new X509Certificate[0]; |
|
1602 |
} |
|
7043 | 1603 |
|
1604 |
@Override |
|
1605 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
1606 |
Socket socket) throws CertificateException { |
|
1607 |
throw new CertificateException( |
|
1608 |
"No X509TrustManager implementation available"); |
|
1609 |
} |
|
1610 |
||
1611 |
@Override |
|
1612 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
1613 |
Socket socket) throws CertificateException { |
|
1614 |
throw new CertificateException( |
|
1615 |
"No X509TrustManager implementation available"); |
|
1616 |
} |
|
1617 |
||
1618 |
@Override |
|
1619 |
public void checkClientTrusted(X509Certificate[] chain, String authType, |
|
1620 |
SSLEngine engine) throws CertificateException { |
|
1621 |
throw new CertificateException( |
|
1622 |
"No X509TrustManager implementation available"); |
|
1623 |
} |
|
1624 |
||
1625 |
@Override |
|
1626 |
public void checkServerTrusted(X509Certificate[] chain, String authType, |
|
1627 |
SSLEngine engine) throws CertificateException { |
|
1628 |
throw new CertificateException( |
|
1629 |
"No X509TrustManager implementation available"); |
|
1630 |
} |
|
2 | 1631 |
} |
1632 |
||
1633 |
/* |
|
1634 |
* A wrapper class to turn a X509KeyManager into an X509ExtendedKeyManager |
|
1635 |
*/ |
|
7043 | 1636 |
final class AbstractKeyManagerWrapper extends X509ExtendedKeyManager { |
2 | 1637 |
|
1638 |
private final X509KeyManager km; |
|
1639 |
||
7043 | 1640 |
AbstractKeyManagerWrapper(X509KeyManager km) { |
2 | 1641 |
this.km = km; |
1642 |
} |
|
1643 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1644 |
@Override |
2 | 1645 |
public String[] getClientAliases(String keyType, Principal[] issuers) { |
1646 |
return km.getClientAliases(keyType, issuers); |
|
1647 |
} |
|
1648 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1649 |
@Override |
2 | 1650 |
public String chooseClientAlias(String[] keyType, Principal[] issuers, |
1651 |
Socket socket) { |
|
1652 |
return km.chooseClientAlias(keyType, issuers, socket); |
|
1653 |
} |
|
1654 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1655 |
@Override |
2 | 1656 |
public String[] getServerAliases(String keyType, Principal[] issuers) { |
1657 |
return km.getServerAliases(keyType, issuers); |
|
1658 |
} |
|
1659 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1660 |
@Override |
2 | 1661 |
public String chooseServerAlias(String keyType, Principal[] issuers, |
1662 |
Socket socket) { |
|
1663 |
return km.chooseServerAlias(keyType, issuers, socket); |
|
1664 |
} |
|
1665 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1666 |
@Override |
2 | 1667 |
public X509Certificate[] getCertificateChain(String alias) { |
1668 |
return km.getCertificateChain(alias); |
|
1669 |
} |
|
1670 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1671 |
@Override |
2 | 1672 |
public PrivateKey getPrivateKey(String alias) { |
1673 |
return km.getPrivateKey(alias); |
|
1674 |
} |
|
1675 |
||
1676 |
// Inherit chooseEngineClientAlias() and chooseEngineServerAlias() from |
|
1677 |
// X509ExtendedKeymanager. It defines them to return null; |
|
1678 |
} |
|
1679 |
||
1680 |
||
1681 |
// Dummy X509KeyManager implementation, never returns any certificates/keys. |
|
1682 |
// Used if the application did not specify a proper X509TrustManager. |
|
1683 |
final class DummyX509KeyManager extends X509ExtendedKeyManager { |
|
1684 |
||
1685 |
static final X509ExtendedKeyManager INSTANCE = new DummyX509KeyManager(); |
|
1686 |
||
1687 |
private DummyX509KeyManager() { |
|
1688 |
// empty |
|
1689 |
} |
|
1690 |
||
1691 |
/* |
|
1692 |
* Get the matching aliases for authenticating the client side of a secure |
|
1693 |
* socket given the public key type and the list of |
|
1694 |
* certificate issuer authorities recognized by the peer (if any). |
|
1695 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1696 |
@Override |
2 | 1697 |
public String[] getClientAliases(String keyType, Principal[] issuers) { |
1698 |
return null; |
|
1699 |
} |
|
1700 |
||
1701 |
/* |
|
1702 |
* Choose an alias to authenticate the client side of a secure |
|
1703 |
* socket given the public key type and the list of |
|
1704 |
* certificate issuer authorities recognized by the peer (if any). |
|
1705 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1706 |
@Override |
2 | 1707 |
public String chooseClientAlias(String[] keyTypes, Principal[] issuers, |
1708 |
Socket socket) { |
|
1709 |
return null; |
|
1710 |
} |
|
1711 |
||
1712 |
/* |
|
1713 |
* Choose an alias to authenticate the client side of an |
|
1714 |
* engine given the public key type and the list of |
|
1715 |
* certificate issuer authorities recognized by the peer (if any). |
|
1716 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1717 |
@Override |
2 | 1718 |
public String chooseEngineClientAlias( |
1719 |
String[] keyTypes, Principal[] issuers, SSLEngine engine) { |
|
1720 |
return null; |
|
1721 |
} |
|
1722 |
||
1723 |
/* |
|
1724 |
* Get the matching aliases for authenticating the server side of a secure |
|
1725 |
* socket given the public key type and the list of |
|
1726 |
* certificate issuer authorities recognized by the peer (if any). |
|
1727 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1728 |
@Override |
2 | 1729 |
public String[] getServerAliases(String keyType, Principal[] issuers) { |
1730 |
return null; |
|
1731 |
} |
|
1732 |
||
1733 |
/* |
|
1734 |
* Choose an alias to authenticate the server side of a secure |
|
1735 |
* socket given the public key type and the list of |
|
1736 |
* certificate issuer authorities recognized by the peer (if any). |
|
1737 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1738 |
@Override |
2 | 1739 |
public String chooseServerAlias(String keyType, Principal[] issuers, |
1740 |
Socket socket) { |
|
1741 |
return null; |
|
1742 |
} |
|
1743 |
||
1744 |
/* |
|
1745 |
* Choose an alias to authenticate the server side of an engine |
|
1746 |
* given the public key type and the list of |
|
1747 |
* certificate issuer authorities recognized by the peer (if any). |
|
1748 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1749 |
@Override |
2 | 1750 |
public String chooseEngineServerAlias( |
1751 |
String keyType, Principal[] issuers, SSLEngine engine) { |
|
1752 |
return null; |
|
1753 |
} |
|
1754 |
||
1755 |
/** |
|
1756 |
* Returns the certificate chain associated with the given alias. |
|
1757 |
* |
|
1758 |
* @param alias the alias name |
|
1759 |
* |
|
1760 |
* @return the certificate chain (ordered with the user's certificate first |
|
1761 |
* and the root certificate authority last) |
|
1762 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1763 |
@Override |
2 | 1764 |
public X509Certificate[] getCertificateChain(String alias) { |
1765 |
return null; |
|
1766 |
} |
|
1767 |
||
1768 |
/* |
|
1769 |
* Returns the key associated with the given alias, using the given |
|
1770 |
* password to recover it. |
|
1771 |
* |
|
1772 |
* @param alias the alias name |
|
1773 |
* |
|
1774 |
* @return the requested key |
|
1775 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
13815
diff
changeset
|
1776 |
@Override |
2 | 1777 |
public PrivateKey getPrivateKey(String alias) { |
1778 |
return null; |
|
1779 |
} |
|
1780 |
} |