2
|
1 |
/*
|
7043
|
2 |
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.security.ssl;
|
|
27 |
|
|
28 |
import java.net.Socket;
|
|
29 |
|
7043
|
30 |
import java.util.*;
|
2
|
31 |
import java.security.*;
|
|
32 |
import java.security.cert.*;
|
7043
|
33 |
import java.security.cert.Certificate;
|
2
|
34 |
|
|
35 |
import javax.net.ssl.*;
|
|
36 |
|
7043
|
37 |
import sun.security.provider.certpath.AlgorithmChecker;
|
|
38 |
|
2
|
39 |
public class SSLContextImpl extends SSLContextSpi {
|
|
40 |
|
|
41 |
private static final Debug debug = Debug.getInstance("ssl");
|
|
42 |
|
|
43 |
private final EphemeralKeyManager ephemeralKeyManager;
|
|
44 |
private final SSLSessionContextImpl clientCache;
|
|
45 |
private final SSLSessionContextImpl serverCache;
|
|
46 |
|
|
47 |
private boolean isInitialized;
|
|
48 |
|
|
49 |
private X509ExtendedKeyManager keyManager;
|
|
50 |
private X509TrustManager trustManager;
|
|
51 |
private SecureRandom secureRandom;
|
|
52 |
|
|
53 |
public SSLContextImpl() {
|
|
54 |
this(null);
|
|
55 |
}
|
|
56 |
|
|
57 |
SSLContextImpl(SSLContextImpl other) {
|
|
58 |
if (other == null) {
|
|
59 |
ephemeralKeyManager = new EphemeralKeyManager();
|
|
60 |
clientCache = new SSLSessionContextImpl();
|
|
61 |
serverCache = new SSLSessionContextImpl();
|
|
62 |
} else {
|
|
63 |
ephemeralKeyManager = other.ephemeralKeyManager;
|
|
64 |
clientCache = other.clientCache;
|
|
65 |
serverCache = other.serverCache;
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|
|
69 |
protected void engineInit(KeyManager[] km, TrustManager[] tm,
|
|
70 |
SecureRandom sr) throws KeyManagementException {
|
|
71 |
isInitialized = false;
|
|
72 |
keyManager = chooseKeyManager(km);
|
|
73 |
|
|
74 |
if (tm == null) {
|
|
75 |
try {
|
|
76 |
TrustManagerFactory tmf = TrustManagerFactory.getInstance(
|
|
77 |
TrustManagerFactory.getDefaultAlgorithm());
|
|
78 |
tmf.init((KeyStore)null);
|
|
79 |
tm = tmf.getTrustManagers();
|
|
80 |
} catch (Exception e) {
|
|
81 |
// eat
|
|
82 |
}
|
|
83 |
}
|
|
84 |
trustManager = chooseTrustManager(tm);
|
|
85 |
|
|
86 |
if (sr == null) {
|
|
87 |
secureRandom = JsseJce.getSecureRandom();
|
|
88 |
} else {
|
7043
|
89 |
if (SunJSSE.isFIPS() &&
|
|
90 |
(sr.getProvider() != SunJSSE.cryptoProvider)) {
|
2
|
91 |
throw new KeyManagementException
|
|
92 |
("FIPS mode: SecureRandom must be from provider "
|
|
93 |
+ SunJSSE.cryptoProvider.getName());
|
|
94 |
}
|
|
95 |
secureRandom = sr;
|
|
96 |
}
|
|
97 |
|
|
98 |
/*
|
|
99 |
* The initial delay of seeding the random number generator
|
|
100 |
* could be long enough to cause the initial handshake on our
|
|
101 |
* first connection to timeout and fail. Make sure it is
|
|
102 |
* primed and ready by getting some initial output from it.
|
|
103 |
*/
|
|
104 |
if (debug != null && Debug.isOn("sslctx")) {
|
|
105 |
System.out.println("trigger seeding of SecureRandom");
|
|
106 |
}
|
|
107 |
secureRandom.nextInt();
|
|
108 |
if (debug != null && Debug.isOn("sslctx")) {
|
|
109 |
System.out.println("done seeding SecureRandom");
|
|
110 |
}
|
|
111 |
isInitialized = true;
|
|
112 |
}
|
|
113 |
|
|
114 |
private X509TrustManager chooseTrustManager(TrustManager[] tm)
|
|
115 |
throws KeyManagementException {
|
|
116 |
// We only use the first instance of X509TrustManager passed to us.
|
|
117 |
for (int i = 0; tm != null && i < tm.length; i++) {
|
|
118 |
if (tm[i] instanceof X509TrustManager) {
|
7043
|
119 |
if (SunJSSE.isFIPS() &&
|
|
120 |
!(tm[i] instanceof X509TrustManagerImpl)) {
|
2
|
121 |
throw new KeyManagementException
|
|
122 |
("FIPS mode: only SunJSSE TrustManagers may be used");
|
|
123 |
}
|
7043
|
124 |
|
|
125 |
if (tm[i] instanceof X509ExtendedTrustManager) {
|
|
126 |
return (X509TrustManager)tm[i];
|
|
127 |
} else {
|
|
128 |
return new AbstractTrustManagerWrapper(
|
|
129 |
(X509TrustManager)tm[i]);
|
|
130 |
}
|
2
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
// nothing found, return a dummy X509TrustManager.
|
|
135 |
return DummyX509TrustManager.INSTANCE;
|
|
136 |
}
|
|
137 |
|
|
138 |
private X509ExtendedKeyManager chooseKeyManager(KeyManager[] kms)
|
|
139 |
throws KeyManagementException {
|
|
140 |
for (int i = 0; kms != null && i < kms.length; i++) {
|
|
141 |
KeyManager km = kms[i];
|
|
142 |
if (km instanceof X509KeyManager == false) {
|
|
143 |
continue;
|
|
144 |
}
|
|
145 |
if (SunJSSE.isFIPS()) {
|
|
146 |
// In FIPS mode, require that one of SunJSSE's own keymanagers
|
|
147 |
// is used. Otherwise, we cannot be sure that only keys from
|
|
148 |
// the FIPS token are used.
|
|
149 |
if ((km instanceof X509KeyManagerImpl)
|
|
150 |
|| (km instanceof SunX509KeyManagerImpl)) {
|
|
151 |
return (X509ExtendedKeyManager)km;
|
|
152 |
} else {
|
|
153 |
// throw exception, we don't want to silently use the
|
|
154 |
// dummy keymanager without telling the user.
|
|
155 |
throw new KeyManagementException
|
|
156 |
("FIPS mode: only SunJSSE KeyManagers may be used");
|
|
157 |
}
|
|
158 |
}
|
|
159 |
if (km instanceof X509ExtendedKeyManager) {
|
|
160 |
return (X509ExtendedKeyManager)km;
|
|
161 |
}
|
|
162 |
if (debug != null && Debug.isOn("sslctx")) {
|
|
163 |
System.out.println(
|
|
164 |
"X509KeyManager passed to " +
|
|
165 |
"SSLContext.init(): need an " +
|
|
166 |
"X509ExtendedKeyManager for SSLEngine use");
|
|
167 |
}
|
7043
|
168 |
return new AbstractKeyManagerWrapper((X509KeyManager)km);
|
2
|
169 |
}
|
|
170 |
|
|
171 |
// nothing found, return a dummy X509ExtendedKeyManager
|
|
172 |
return DummyX509KeyManager.INSTANCE;
|
|
173 |
}
|
|
174 |
|
|
175 |
protected SSLSocketFactory engineGetSocketFactory() {
|
|
176 |
if (!isInitialized) {
|
|
177 |
throw new IllegalStateException(
|
|
178 |
"SSLContextImpl is not initialized");
|
|
179 |
}
|
|
180 |
return new SSLSocketFactoryImpl(this);
|
|
181 |
}
|
|
182 |
|
|
183 |
protected SSLServerSocketFactory engineGetServerSocketFactory() {
|
|
184 |
if (!isInitialized) {
|
|
185 |
throw new IllegalStateException("SSLContext is not initialized");
|
|
186 |
}
|
|
187 |
return new SSLServerSocketFactoryImpl(this);
|
|
188 |
}
|
|
189 |
|
|
190 |
protected SSLEngine engineCreateSSLEngine() {
|
|
191 |
if (!isInitialized) {
|
|
192 |
throw new IllegalStateException(
|
|
193 |
"SSLContextImpl is not initialized");
|
|
194 |
}
|
|
195 |
return new SSLEngineImpl(this);
|
|
196 |
}
|
|
197 |
|
|
198 |
protected SSLEngine engineCreateSSLEngine(String host, int port) {
|
|
199 |
if (!isInitialized) {
|
|
200 |
throw new IllegalStateException(
|
|
201 |
"SSLContextImpl is not initialized");
|
|
202 |
}
|
|
203 |
return new SSLEngineImpl(this, host, port);
|
|
204 |
}
|
|
205 |
|
|
206 |
protected SSLSessionContext engineGetClientSessionContext() {
|
|
207 |
return clientCache;
|
|
208 |
}
|
|
209 |
|
|
210 |
protected SSLSessionContext engineGetServerSessionContext() {
|
|
211 |
return serverCache;
|
|
212 |
}
|
|
213 |
|
|
214 |
SecureRandom getSecureRandom() {
|
|
215 |
return secureRandom;
|
|
216 |
}
|
|
217 |
|
|
218 |
X509ExtendedKeyManager getX509KeyManager() {
|
|
219 |
return keyManager;
|
|
220 |
}
|
|
221 |
|
|
222 |
X509TrustManager getX509TrustManager() {
|
|
223 |
return trustManager;
|
|
224 |
}
|
|
225 |
|
|
226 |
EphemeralKeyManager getEphemeralKeyManager() {
|
|
227 |
return ephemeralKeyManager;
|
|
228 |
}
|
|
229 |
|
|
230 |
}
|
|
231 |
|
7043
|
232 |
|
|
233 |
final class AbstractTrustManagerWrapper extends X509ExtendedTrustManager
|
|
234 |
implements X509TrustManager {
|
|
235 |
|
|
236 |
private final X509TrustManager tm;
|
|
237 |
|
|
238 |
AbstractTrustManagerWrapper(X509TrustManager tm) {
|
|
239 |
this.tm = tm;
|
|
240 |
}
|
|
241 |
|
|
242 |
@Override
|
|
243 |
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
|
244 |
throws CertificateException {
|
|
245 |
tm.checkClientTrusted(chain, authType);
|
|
246 |
}
|
|
247 |
|
|
248 |
@Override
|
|
249 |
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
|
250 |
throws CertificateException {
|
|
251 |
tm.checkServerTrusted(chain, authType);
|
|
252 |
}
|
|
253 |
|
|
254 |
@Override
|
|
255 |
public X509Certificate[] getAcceptedIssuers() {
|
|
256 |
return tm.getAcceptedIssuers();
|
|
257 |
}
|
|
258 |
|
|
259 |
@Override
|
|
260 |
public void checkClientTrusted(X509Certificate[] chain, String authType,
|
|
261 |
Socket socket) throws CertificateException {
|
|
262 |
tm.checkClientTrusted(chain, authType);
|
|
263 |
checkAdditionalTrust(chain, authType, socket, true);
|
|
264 |
}
|
|
265 |
|
|
266 |
@Override
|
|
267 |
public void checkServerTrusted(X509Certificate[] chain, String authType,
|
|
268 |
Socket socket) throws CertificateException {
|
|
269 |
tm.checkServerTrusted(chain, authType);
|
|
270 |
checkAdditionalTrust(chain, authType, socket, false);
|
|
271 |
}
|
|
272 |
|
|
273 |
@Override
|
|
274 |
public void checkClientTrusted(X509Certificate[] chain, String authType,
|
|
275 |
SSLEngine engine) throws CertificateException {
|
|
276 |
tm.checkClientTrusted(chain, authType);
|
|
277 |
checkAdditionalTrust(chain, authType, engine, true);
|
|
278 |
}
|
|
279 |
|
|
280 |
@Override
|
|
281 |
public void checkServerTrusted(X509Certificate[] chain, String authType,
|
|
282 |
SSLEngine engine) throws CertificateException {
|
|
283 |
tm.checkServerTrusted(chain, authType);
|
|
284 |
checkAdditionalTrust(chain, authType, engine, false);
|
|
285 |
}
|
|
286 |
|
|
287 |
private void checkAdditionalTrust(X509Certificate[] chain, String authType,
|
|
288 |
Socket socket, boolean isClient) throws CertificateException {
|
|
289 |
if (socket != null && socket.isConnected() &&
|
|
290 |
socket instanceof SSLSocket) {
|
|
291 |
|
|
292 |
SSLSocket sslSocket = (SSLSocket)socket;
|
|
293 |
SSLSession session = sslSocket.getHandshakeSession();
|
|
294 |
if (session == null) {
|
|
295 |
throw new CertificateException("No handshake session");
|
|
296 |
}
|
|
297 |
|
|
298 |
// check endpoint identity
|
|
299 |
String identityAlg = sslSocket.getSSLParameters().
|
|
300 |
getEndpointIdentificationAlgorithm();
|
|
301 |
if (identityAlg != null && identityAlg.length() != 0) {
|
|
302 |
String hostname = session.getPeerHost();
|
|
303 |
X509TrustManagerImpl.checkIdentity(
|
|
304 |
hostname, chain[0], identityAlg);
|
|
305 |
}
|
|
306 |
|
|
307 |
// try the best to check the algorithm constraints
|
|
308 |
ProtocolVersion protocolVersion =
|
|
309 |
ProtocolVersion.valueOf(session.getProtocol());
|
|
310 |
AlgorithmConstraints constraints = null;
|
|
311 |
if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
|
|
312 |
if (session instanceof ExtendedSSLSession) {
|
|
313 |
ExtendedSSLSession extSession =
|
|
314 |
(ExtendedSSLSession)session;
|
|
315 |
String[] peerSupportedSignAlgs =
|
|
316 |
extSession.getLocalSupportedSignatureAlgorithms();
|
|
317 |
|
|
318 |
constraints = new SSLAlgorithmConstraints(
|
|
319 |
sslSocket, peerSupportedSignAlgs, true);
|
|
320 |
} else {
|
|
321 |
constraints =
|
|
322 |
new SSLAlgorithmConstraints(sslSocket, true);
|
|
323 |
}
|
|
324 |
} else {
|
|
325 |
constraints = new SSLAlgorithmConstraints(sslSocket, true);
|
|
326 |
}
|
|
327 |
|
|
328 |
AlgorithmChecker checker = new AlgorithmChecker(constraints);
|
|
329 |
try {
|
|
330 |
checker.init(false);
|
|
331 |
|
|
332 |
// a forward checker, need to check from trust to target
|
|
333 |
for (int i = chain.length - 1; i >= 0; i--) {
|
|
334 |
Certificate cert = chain[i];
|
|
335 |
// We don't care about the unresolved critical extensions.
|
|
336 |
checker.check(cert, Collections.<String>emptySet());
|
|
337 |
}
|
|
338 |
} catch (CertPathValidatorException cpve) {
|
|
339 |
throw new CertificateException(
|
|
340 |
"Certificates does not conform to algorithm constraints");
|
|
341 |
}
|
|
342 |
}
|
|
343 |
}
|
|
344 |
|
|
345 |
private void checkAdditionalTrust(X509Certificate[] chain, String authType,
|
|
346 |
SSLEngine engine, boolean isClient) throws CertificateException {
|
|
347 |
if (engine != null) {
|
|
348 |
SSLSession session = engine.getHandshakeSession();
|
|
349 |
if (session == null) {
|
|
350 |
throw new CertificateException("No handshake session");
|
|
351 |
}
|
|
352 |
|
|
353 |
// check endpoint identity
|
|
354 |
String identityAlg = engine.getSSLParameters().
|
|
355 |
getEndpointIdentificationAlgorithm();
|
|
356 |
if (identityAlg != null && identityAlg.length() != 0) {
|
|
357 |
String hostname = session.getPeerHost();
|
|
358 |
X509TrustManagerImpl.checkIdentity(
|
|
359 |
hostname, chain[0], identityAlg);
|
|
360 |
}
|
|
361 |
|
|
362 |
// try the best to check the algorithm constraints
|
|
363 |
ProtocolVersion protocolVersion =
|
|
364 |
ProtocolVersion.valueOf(session.getProtocol());
|
|
365 |
AlgorithmConstraints constraints = null;
|
|
366 |
if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
|
|
367 |
if (session instanceof ExtendedSSLSession) {
|
|
368 |
ExtendedSSLSession extSession =
|
|
369 |
(ExtendedSSLSession)session;
|
|
370 |
String[] peerSupportedSignAlgs =
|
|
371 |
extSession.getLocalSupportedSignatureAlgorithms();
|
|
372 |
|
|
373 |
constraints = new SSLAlgorithmConstraints(
|
|
374 |
engine, peerSupportedSignAlgs, true);
|
|
375 |
} else {
|
|
376 |
constraints =
|
|
377 |
new SSLAlgorithmConstraints(engine, true);
|
|
378 |
}
|
|
379 |
} else {
|
|
380 |
constraints = new SSLAlgorithmConstraints(engine, true);
|
|
381 |
}
|
|
382 |
|
|
383 |
AlgorithmChecker checker = new AlgorithmChecker(constraints);
|
|
384 |
try {
|
|
385 |
checker.init(false);
|
|
386 |
|
|
387 |
// A forward checker, need to check from trust to target
|
|
388 |
for (int i = chain.length - 1; i >= 0; i--) {
|
|
389 |
Certificate cert = chain[i];
|
|
390 |
// We don't care about the unresolved critical extensions.
|
|
391 |
checker.check(cert, Collections.<String>emptySet());
|
|
392 |
}
|
|
393 |
} catch (CertPathValidatorException cpve) {
|
|
394 |
throw new CertificateException(
|
|
395 |
"Certificates does not conform to algorithm constraints");
|
|
396 |
}
|
|
397 |
}
|
|
398 |
}
|
|
399 |
}
|
|
400 |
|
2
|
401 |
// Dummy X509TrustManager implementation, rejects all peer certificates.
|
|
402 |
// Used if the application did not specify a proper X509TrustManager.
|
7043
|
403 |
final class DummyX509TrustManager extends X509ExtendedTrustManager
|
|
404 |
implements X509TrustManager {
|
2
|
405 |
|
|
406 |
static final X509TrustManager INSTANCE = new DummyX509TrustManager();
|
|
407 |
|
|
408 |
private DummyX509TrustManager() {
|
|
409 |
// empty
|
|
410 |
}
|
|
411 |
|
|
412 |
/*
|
|
413 |
* Given the partial or complete certificate chain
|
|
414 |
* provided by the peer, build a certificate path
|
|
415 |
* to a trusted root and return if it can be
|
|
416 |
* validated and is trusted for client SSL authentication.
|
|
417 |
* If not, it throws an exception.
|
|
418 |
*/
|
7043
|
419 |
@Override
|
2
|
420 |
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
|
421 |
throws CertificateException {
|
|
422 |
throw new CertificateException(
|
|
423 |
"No X509TrustManager implementation avaiable");
|
|
424 |
}
|
|
425 |
|
|
426 |
/*
|
|
427 |
* Given the partial or complete certificate chain
|
|
428 |
* provided by the peer, build a certificate path
|
|
429 |
* to a trusted root and return if it can be
|
|
430 |
* validated and is trusted for server SSL authentication.
|
|
431 |
* If not, it throws an exception.
|
|
432 |
*/
|
7043
|
433 |
@Override
|
2
|
434 |
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
|
435 |
throws CertificateException {
|
|
436 |
throw new CertificateException(
|
|
437 |
"No X509TrustManager implementation available");
|
|
438 |
}
|
|
439 |
|
|
440 |
/*
|
|
441 |
* Return an array of issuer certificates which are trusted
|
|
442 |
* for authenticating peers.
|
|
443 |
*/
|
7043
|
444 |
@Override
|
2
|
445 |
public X509Certificate[] getAcceptedIssuers() {
|
|
446 |
return new X509Certificate[0];
|
|
447 |
}
|
7043
|
448 |
|
|
449 |
@Override
|
|
450 |
public void checkClientTrusted(X509Certificate[] chain, String authType,
|
|
451 |
Socket socket) throws CertificateException {
|
|
452 |
throw new CertificateException(
|
|
453 |
"No X509TrustManager implementation available");
|
|
454 |
}
|
|
455 |
|
|
456 |
@Override
|
|
457 |
public void checkServerTrusted(X509Certificate[] chain, String authType,
|
|
458 |
Socket socket) throws CertificateException {
|
|
459 |
throw new CertificateException(
|
|
460 |
"No X509TrustManager implementation available");
|
|
461 |
}
|
|
462 |
|
|
463 |
@Override
|
|
464 |
public void checkClientTrusted(X509Certificate[] chain, String authType,
|
|
465 |
SSLEngine engine) throws CertificateException {
|
|
466 |
throw new CertificateException(
|
|
467 |
"No X509TrustManager implementation available");
|
|
468 |
}
|
|
469 |
|
|
470 |
@Override
|
|
471 |
public void checkServerTrusted(X509Certificate[] chain, String authType,
|
|
472 |
SSLEngine engine) throws CertificateException {
|
|
473 |
throw new CertificateException(
|
|
474 |
"No X509TrustManager implementation available");
|
|
475 |
}
|
2
|
476 |
}
|
|
477 |
|
|
478 |
/*
|
|
479 |
* A wrapper class to turn a X509KeyManager into an X509ExtendedKeyManager
|
|
480 |
*/
|
7043
|
481 |
final class AbstractKeyManagerWrapper extends X509ExtendedKeyManager {
|
2
|
482 |
|
|
483 |
private final X509KeyManager km;
|
|
484 |
|
7043
|
485 |
AbstractKeyManagerWrapper(X509KeyManager km) {
|
2
|
486 |
this.km = km;
|
|
487 |
}
|
|
488 |
|
|
489 |
public String[] getClientAliases(String keyType, Principal[] issuers) {
|
|
490 |
return km.getClientAliases(keyType, issuers);
|
|
491 |
}
|
|
492 |
|
|
493 |
public String chooseClientAlias(String[] keyType, Principal[] issuers,
|
|
494 |
Socket socket) {
|
|
495 |
return km.chooseClientAlias(keyType, issuers, socket);
|
|
496 |
}
|
|
497 |
|
|
498 |
public String[] getServerAliases(String keyType, Principal[] issuers) {
|
|
499 |
return km.getServerAliases(keyType, issuers);
|
|
500 |
}
|
|
501 |
|
|
502 |
public String chooseServerAlias(String keyType, Principal[] issuers,
|
|
503 |
Socket socket) {
|
|
504 |
return km.chooseServerAlias(keyType, issuers, socket);
|
|
505 |
}
|
|
506 |
|
|
507 |
public X509Certificate[] getCertificateChain(String alias) {
|
|
508 |
return km.getCertificateChain(alias);
|
|
509 |
}
|
|
510 |
|
|
511 |
public PrivateKey getPrivateKey(String alias) {
|
|
512 |
return km.getPrivateKey(alias);
|
|
513 |
}
|
|
514 |
|
|
515 |
// Inherit chooseEngineClientAlias() and chooseEngineServerAlias() from
|
|
516 |
// X509ExtendedKeymanager. It defines them to return null;
|
|
517 |
}
|
|
518 |
|
|
519 |
|
|
520 |
// Dummy X509KeyManager implementation, never returns any certificates/keys.
|
|
521 |
// Used if the application did not specify a proper X509TrustManager.
|
|
522 |
final class DummyX509KeyManager extends X509ExtendedKeyManager {
|
|
523 |
|
|
524 |
static final X509ExtendedKeyManager INSTANCE = new DummyX509KeyManager();
|
|
525 |
|
|
526 |
private DummyX509KeyManager() {
|
|
527 |
// empty
|
|
528 |
}
|
|
529 |
|
|
530 |
/*
|
|
531 |
* Get the matching aliases for authenticating the client side of a secure
|
|
532 |
* socket given the public key type and the list of
|
|
533 |
* certificate issuer authorities recognized by the peer (if any).
|
|
534 |
*/
|
|
535 |
public String[] getClientAliases(String keyType, Principal[] issuers) {
|
|
536 |
return null;
|
|
537 |
}
|
|
538 |
|
|
539 |
/*
|
|
540 |
* Choose an alias to authenticate the client side of a secure
|
|
541 |
* socket given the public key type and the list of
|
|
542 |
* certificate issuer authorities recognized by the peer (if any).
|
|
543 |
*/
|
|
544 |
public String chooseClientAlias(String[] keyTypes, Principal[] issuers,
|
|
545 |
Socket socket) {
|
|
546 |
return null;
|
|
547 |
}
|
|
548 |
|
|
549 |
/*
|
|
550 |
* Choose an alias to authenticate the client side of an
|
|
551 |
* engine given the public key type and the list of
|
|
552 |
* certificate issuer authorities recognized by the peer (if any).
|
|
553 |
*/
|
|
554 |
public String chooseEngineClientAlias(
|
|
555 |
String[] keyTypes, Principal[] issuers, SSLEngine engine) {
|
|
556 |
return null;
|
|
557 |
}
|
|
558 |
|
|
559 |
/*
|
|
560 |
* Get the matching aliases for authenticating the server side of a secure
|
|
561 |
* socket given the public key type and the list of
|
|
562 |
* certificate issuer authorities recognized by the peer (if any).
|
|
563 |
*/
|
|
564 |
public String[] getServerAliases(String keyType, Principal[] issuers) {
|
|
565 |
return null;
|
|
566 |
}
|
|
567 |
|
|
568 |
/*
|
|
569 |
* Choose an alias to authenticate the server side of a secure
|
|
570 |
* socket given the public key type and the list of
|
|
571 |
* certificate issuer authorities recognized by the peer (if any).
|
|
572 |
*/
|
|
573 |
public String chooseServerAlias(String keyType, Principal[] issuers,
|
|
574 |
Socket socket) {
|
|
575 |
return null;
|
|
576 |
}
|
|
577 |
|
|
578 |
/*
|
|
579 |
* Choose an alias to authenticate the server side of an engine
|
|
580 |
* given the public key type and the list of
|
|
581 |
* certificate issuer authorities recognized by the peer (if any).
|
|
582 |
*/
|
|
583 |
public String chooseEngineServerAlias(
|
|
584 |
String keyType, Principal[] issuers, SSLEngine engine) {
|
|
585 |
return null;
|
|
586 |
}
|
|
587 |
|
|
588 |
/**
|
|
589 |
* Returns the certificate chain associated with the given alias.
|
|
590 |
*
|
|
591 |
* @param alias the alias name
|
|
592 |
*
|
|
593 |
* @return the certificate chain (ordered with the user's certificate first
|
|
594 |
* and the root certificate authority last)
|
|
595 |
*/
|
|
596 |
public X509Certificate[] getCertificateChain(String alias) {
|
|
597 |
return null;
|
|
598 |
}
|
|
599 |
|
|
600 |
/*
|
|
601 |
* Returns the key associated with the given alias, using the given
|
|
602 |
* password to recover it.
|
|
603 |
*
|
|
604 |
* @param alias the alias name
|
|
605 |
*
|
|
606 |
* @return the requested key
|
|
607 |
*/
|
|
608 |
public PrivateKey getPrivateKey(String alias) {
|
|
609 |
return null;
|
|
610 |
}
|
|
611 |
}
|