use of javax.net.ssl.KeyManagerFactory in project iaf by ibissource.
the class PkiUtil method createKeyManagers.
public static KeyManager[] createKeyManagers(final KeyStore keystore, final String password, String algorithm) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
if (keystore == null) {
throw new IllegalArgumentException("Keystore may not be null");
}
log.debug("Initializing key manager");
if (StringUtils.isEmpty(algorithm)) {
algorithm = KeyManagerFactory.getDefaultAlgorithm();
log.debug("using default KeyManager algorithm [" + algorithm + "]");
} else {
log.debug("using configured KeyManager algorithm [" + algorithm + "]");
}
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(algorithm);
kmfactory.init(keystore, password != null ? password.toCharArray() : null);
return kmfactory.getKeyManagers();
}
use of javax.net.ssl.KeyManagerFactory in project keycloak by keycloak.
the class KeycloakServer method getKeyManagers.
private KeyManager[] getKeyManagers() throws Exception {
String keyStorePath = System.getProperty("keycloak.tls.keystore.path");
if (keyStorePath == null) {
return null;
}
log.infof("Loading keystore from file: %s", keyStorePath);
InputStream stream = Files.newInputStream(Paths.get(keyStorePath));
if (stream == null) {
throw new RuntimeException("Could not load keystore");
}
try (InputStream is = stream) {
KeyStore keyStore = KeyStore.getInstance("JKS");
char[] keyStorePassword = System.getProperty("keycloak.tls.keystore.password", "password").toCharArray();
keyStore.load(is, keyStorePassword);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStorePassword);
return keyManagerFactory.getKeyManagers();
}
}
use of javax.net.ssl.KeyManagerFactory in project samourai-wallet-android by Samourai-Wallet.
the class StrongSSLSocketFactory method createKeyManagers.
private KeyManager[] createKeyManagers(final KeyStore keystore, final String password) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
if (keystore == null) {
throw new IllegalArgumentException("Keystore may not be null");
}
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmfactory.init(keystore, password != null ? password.toCharArray() : null);
return kmfactory.getKeyManagers();
}
use of javax.net.ssl.KeyManagerFactory in project coprhd-controller by CoprHD.
the class RenderProxy method createClientConnectionManager.
private static ClientConnectionManager createClientConnectionManager() {
SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
SSLSocketFactory sf;
if (StorageOsPlugin.isEnabled()) {
try {
// initialize an SSLContext with the vipr keystore and trustmanager.
// This is basically a dup of most of the ViPRSSLSocketFactory constructor,
// and could be extracted
X509TrustManager[] trustManagers = { BourneUtil.getTrustManager() };
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(BourneUtil.getKeyStore(), "".toCharArray());
SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), trustManagers, new SecureRandom());
sf = new SSLSocketFactory(context, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} catch (Exception e) {
throw new RuntimeException("Unable to initialize the ViPRX509TrustManager for RenderProxy", e);
}
} else {
sf = new SSLSocketFactory(SSLUtil.getTrustAllContext(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
Scheme httpsScheme = new Scheme("https", 443, sf);
schemeRegistry.register(httpsScheme);
ClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
return connectionManager;
}
use of javax.net.ssl.KeyManagerFactory in project apache-kafka-on-k8s by banzaicloud.
the class SslFactory method createSSLContext.
// package access for testing
SSLContext createSSLContext(SecurityStore keystore) throws GeneralSecurityException, IOException {
SSLContext sslContext;
if (provider != null)
sslContext = SSLContext.getInstance(protocol, provider);
else
sslContext = SSLContext.getInstance(protocol);
KeyManager[] keyManagers = null;
if (keystore != null) {
String kmfAlgorithm = this.kmfAlgorithm != null ? this.kmfAlgorithm : KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
KeyStore ks = keystore.load();
Password keyPassword = keystore.keyPassword != null ? keystore.keyPassword : keystore.password;
kmf.init(ks, keyPassword.value().toCharArray());
keyManagers = kmf.getKeyManagers();
}
String tmfAlgorithm = this.tmfAlgorithm != null ? this.tmfAlgorithm : TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
KeyStore ts = truststore == null ? null : truststore.load();
tmf.init(ts);
sslContext.init(keyManagers, tmf.getTrustManagers(), this.secureRandomImplementation);
if (keystore != null && keystore != this.keystore) {
if (this.keystore == null)
throw new ConfigException("Cannot add SSL keystore to an existing listener for which no keystore was configured.");
if (keystoreVerifiableUsingTruststore)
SSLConfigValidatorEngine.validate(this, sslContext);
if (!CertificateEntries.create(this.keystore.load()).equals(CertificateEntries.create(keystore.load()))) {
throw new ConfigException("Keystore DistinguishedName or SubjectAltNames do not match");
}
}
return sslContext;
}
Aggregations