use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class IIOPSSLUtilImpl method getKeyManagers.
@Override
public KeyManager[] getKeyManagers(String alias) {
KeyManager[] mgrs = null;
try {
if (alias != null && !sslUtils.isTokenKeyAlias(alias)) {
throw new IllegalStateException(getFormatMessage("iiop.cannot_find_keyalias", new Object[] { alias }));
}
mgrs = sslUtils.getKeyManagers();
if (alias != null && mgrs != null && mgrs.length > 0) {
KeyManager[] newMgrs = new KeyManager[mgrs.length];
for (int i = 0; i < mgrs.length; i++) {
if (_logger.isLoggable(Level.FINE)) {
StringBuffer msg = new StringBuffer("Setting J2EEKeyManager for ");
msg.append(" alias : " + alias);
_logger.log(Level.FINE, msg.toString());
}
newMgrs[i] = new J2EEKeyManager((X509KeyManager) mgrs[i], alias);
}
mgrs = newMgrs;
}
} catch (Exception e) {
// TODO: log here
throw new RuntimeException(e);
}
return mgrs;
}
use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class SSLSocketFactory method initStoresAtStartup.
// V3: to break dependency of SSLUtils on this class
// public static void setManagers(KeyManager[] kmgrs, TrustManager[] tmgrs) {
// keyManagers = kmgrs;
// trustManagers = tmgrs;
// }
// V3: Copied from SSLUtils to break dependency of SSLUtils on this class
public static synchronized void initStoresAtStartup() throws Exception {
if (initialized) {
return;
}
ServiceLocator habitat = Globals.getDefaultHabitat();
SSLUtils sslUtils = habitat.getService(SSLUtils.class);
keyManagers = sslUtils.getKeyManagers();
trustManagers = sslUtils.getTrustManagers();
// Creating a default SSLContext and HttpsURLConnection for clients
// that use Https
SSLContext ctx = SSLContext.getInstance("TLS");
String keyAlias = System.getProperty(SSLUtils.HTTPS_OUTBOUND_KEY_ALIAS);
KeyManager[] kMgrs = sslUtils.getKeyManagers();
if (keyAlias != null && keyAlias.length() > 0 && kMgrs != null) {
for (int i = 0; i < kMgrs.length; i++) {
kMgrs[i] = new J2EEKeyManager((X509KeyManager) kMgrs[i], keyAlias);
}
}
ctx.init(kMgrs, sslUtils.getTrustManagers(), null);
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
initialized = true;
}
use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class GlassfishServerSocketFactory method getKeyManagers.
@Override
protected KeyManager[] getKeyManagers(String algorithm, String keyAlias) throws Exception {
if (sslUtils == null) {
initSSLUtils();
}
String keystoreFile = (String) attributes.get("keystore");
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Keystore file= {0}", keystoreFile);
}
String keystoreType = (String) attributes.get("keystoreType");
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Keystore type= {0}", keystoreType);
}
// validate that the alias is in one of the keystores otherwise emit warning
boolean aliasFound = false;
for (KeyStore keyStore : sslUtils.getKeyStores()) {
if (keyStore.isKeyEntry(keyAlias)) {
aliasFound = true;
break;
}
}
if (!aliasFound) {
logger.log(Level.WARNING, "Unable to find key pair alias {0} in any of the configured key stores, therefore the server may not be able to present a valid SSL Certificate", keyAlias);
}
KeyManager[] kMgrs = sslUtils.getKeyManagers(algorithm);
if (keyAlias != null && keyAlias.length() > 0 && kMgrs != null) {
for (int i = 0; i < kMgrs.length; i++) {
kMgrs[i] = new J2EEKeyManager((X509KeyManager) kMgrs[i], keyAlias);
}
}
return kMgrs;
}
use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class SecuritySupportImpl method getKeyManagers.
public KeyManager[] getKeyManagers(String algorithm) throws IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
KeyStore[] kstores = getKeyStores();
ArrayList<KeyManager> keyManagers = new ArrayList<KeyManager>();
for (int i = 0; i < kstores.length; i++) {
checkCertificateDates(kstores[i]);
KeyManagerFactory kmf = KeyManagerFactory.getInstance((algorithm != null) ? algorithm : KeyManagerFactory.getDefaultAlgorithm());
kmf.init(kstores[i], keyStorePasswords.get(i));
KeyManager[] kmgrs = kmf.getKeyManagers();
if (kmgrs != null) {
keyManagers.addAll(Arrays.asList(kmgrs));
}
}
KeyManager keyManager = new UnifiedX509KeyManager(keyManagers.toArray(new X509KeyManager[keyManagers.size()]), getTokenNames());
return new KeyManager[] { keyManager };
}
Aggregations