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