* attempt to find another key.
*/
public String chooseServerAlias(
String keyType, Principal[] issuers, Socket socket)
{
X500PrivateCredential cred = null;
synchronized (credentialCache) {
Object val = credentialCache.get(keyType);
if (val instanceof X500PrivateCredential) {
cred = (X500PrivateCredential) val;
try {
checkCredentials(cred, null, "listen");
} catch (SecurityException e) {
if (logger.isLoggable(Levels.HANDLED)) {
logThrow(logger, Levels.HANDLED,
ServerAuthManager.class, "chooseServerAlias",
"choose server alias for key type {0}\n" +
"and issuers {1}\ncaught exception",
new Object[] { keyType, toString(issuers) },
e);
}
/*
* This credential is no longer present or we don't have
* permission to use it. Clear the cache and invalidate
* sessions with this key type.
*/
cred = null;
credentialCache.remove(keyType);
for (Enumeration en = sslSessionContext.getIds();
en.hasMoreElements(); )
{
SSLSession session =
sslSessionContext.getSession(
(byte[]) en.nextElement());
if (session != null) {
String suite = session.getCipherSuite();
if (keyType.equals(getKeyAlgorithm(suite))) {
session.invalidate();
}
}
}
}
}
if (cred == null) {
/* Try to select a new alias */
Exception exception = null;
try {
cred = chooseCredential(keyType, issuers);
if (cred != null) {
credentialCache.put(keyType, cred);
}
} catch (GeneralSecurityException e) {
exception = e;
} catch (SecurityException e) {
exception = e;
}
if (exception != null) {
credentialCache.put(keyType, exception.getMessage());
return null;
}
}
}
String result = (cred == null)
? null
: SubjectCredentials.getCertificateName(cred.getCertificate());
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"choose server alias for key type {0}\nissuers {1}\n" +
"returns {2}",
new Object[] { keyType, toString(issuers), result });