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