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