use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class J2EEKeyManager method getPrivateKey.
/**
* Return the private key for the specified alias.
*
* @param the alias.
* @return the private key.
*/
@Override
public PrivateKey getPrivateKey(String alias) {
LOGGER.log(FINE, "Getting private key for alias:{0}", alias);
X509KeyManager keyMgr = getManagerFromToken(alias);
if (keyMgr != null) {
String aliasName = alias.substring(alias.indexOf(':') + 1);
return keyMgr.getPrivateKey(aliasName);
}
return x509KeyManager.getPrivateKey(alias);
}
use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class J2EEKeyManager method getManagerFromToken.
/**
* Find the corresponding X509KeyManager associated to token in alias. It returns null if there is n
*
* @param tokenAlias of the form <tokenName>:<aliasName>
*/
private X509KeyManager getManagerFromToken(String tokenAlias) {
X509KeyManager keyMgr = null;
int ind = -1;
if (supportTokenAlias && tokenAlias != null && (ind = tokenAlias.indexOf(':')) != -1) {
String tokenName = alias.substring(0, ind);
keyMgr = tokenName2MgrMap.get(tokenName);
}
return keyMgr;
}
use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class SSLUtils method getAdminSSLContext.
/*
* @param alias the admin key alias
*
* @param protocol the protocol or null, uses "TLS" if this argument is null.
*
* @return the initialized SSLContext
*/
public SSLContext getAdminSSLContext(String alias, String protocol) {
try {
if (protocol == null) {
protocol = "TLS";
}
SSLContext adminSSLContextxt = SSLContext.getInstance(protocol);
KeyManager[] keyManagers = getKeyManagers();
if (alias != null && alias.length() > 0 && keyManagers != null) {
for (int i = 0; i < keyManagers.length; i++) {
keyManagers[i] = new J2EEKeyManager((X509KeyManager) keyManagers[i], alias);
}
}
adminSSLContextxt.init(keyManagers, getTrustManagers(), null);
return adminSSLContextxt;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.net.ssl.X509KeyManager in project Payara by payara.
the class RestClientSslContextAliasListener method buildSSlContext.
/**
* This method evaluate the alias on the global keystore and return the corresponding SSLContext based on the alias
* if not available the SSLContext should be the default that Jersey implementation set
*
* @param alias name of the certificate
* @return the SSLContext with the corresponding certificate and alias name
*/
protected SSLContext buildSSlContext(String alias) {
logger.log(Level.FINE, "Building the SSLContext for the alias");
try {
KeyManager[] managers = getKeyManagers();
Optional<X509KeyManager> optionalKeyManager = null;
optionalKeyManager = Arrays.stream(managers).filter(m -> (m instanceof X509KeyManager)).map(m -> ((X509KeyManager) m)).findFirst();
KeyStore[] keyStores = getKeyStores();
for (KeyStore ks : keyStores) {
if (ks.containsAlias(alias) && optionalKeyManager.isPresent()) {
X509KeyManager customKeyManager = new SingleCertificateKeyManager(alias, optionalKeyManager.get());
SSLContext customSSLContext = SSLContext.getInstance("TLS");
customSSLContext.init(new KeyManager[] { customKeyManager }, null, null);
return customSSLContext;
}
}
} catch (IOException e) {
logger.severe("An IOException was thrown with the following message" + e.getMessage());
} catch (KeyStoreException e) {
logger.severe("A KeyStoreException was thrown with the following message" + e.getMessage());
} catch (Exception e) {
logger.severe("An Exception was thrown with the following message" + e.getMessage());
}
return null;
}
use of javax.net.ssl.X509KeyManager in project cxf by apache.
the class HttpConduitConfigurationTest method verifyConduit.
private void verifyConduit(HTTPConduit conduit) {
AuthorizationPolicy authp = conduit.getAuthorization();
assertNotNull(authp);
assertEquals("Betty", authp.getUserName());
assertEquals("password", authp.getPassword());
TLSClientParameters tlscps = conduit.getTlsClientParameters();
assertNotNull(tlscps);
assertTrue(tlscps.isDisableCNCheck());
assertEquals(3600000, tlscps.getSslCacheTimeout());
KeyManager[] kms = tlscps.getKeyManagers();
assertTrue(kms != null && kms.length == 1);
assertTrue(kms[0] instanceof X509KeyManager);
TrustManager[] tms = tlscps.getTrustManagers();
assertTrue(tms != null && tms.length == 1);
assertTrue(tms[0] instanceof X509TrustManager);
FiltersType csfs = tlscps.getCipherSuitesFilter();
assertNotNull(csfs);
assertEquals(1, csfs.getInclude().size());
assertEquals(1, csfs.getExclude().size());
HTTPClientPolicy clientPolicy = conduit.getClient();
assertEquals(10240, clientPolicy.getChunkLength());
}
Aggregations