use of javax.net.ssl.KeyManagerFactory in project vert.x by eclipse.
the class KeyStoreHelper method getKeyMgrFactory.
public KeyManagerFactory getKeyMgrFactory(VertxInternal vertx) throws Exception {
KeyManagerFactory fact = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
fact.getProvider();
KeyStore ks = loadStore(vertx);
fact.init(ks, password != null ? password.toCharArray() : null);
return fact;
}
use of javax.net.ssl.KeyManagerFactory in project elasticsearch by elastic.
the class GceDiscoverTests method getSSLContext.
private static SSLContext getSSLContext() throws Exception {
char[] passphrase = "keypass".toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream stream = GceDiscoverTests.class.getResourceAsStream("/test-node.jks")) {
assertNotNull("can't find keystore file", stream);
ks.load(stream, passphrase);
}
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, passphrase);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);
SSLContext ssl = SSLContext.getInstance("TLS");
ssl.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
return ssl;
}
use of javax.net.ssl.KeyManagerFactory in project cas by apereo.
the class FileTrustStoreSslSocketFactory method getKeyManager.
/**
* Gets key manager.
*
* @param algorithm the algorithm
* @param keystore the keystore
* @param password the password
* @return the key manager
* @throws Exception the exception
*/
private static X509KeyManager getKeyManager(final String algorithm, final KeyStore keystore, final char[] password) throws Exception {
final KeyManagerFactory factory = KeyManagerFactory.getInstance(algorithm);
factory.init(keystore, password);
return (X509KeyManager) factory.getKeyManagers()[0];
}
use of javax.net.ssl.KeyManagerFactory in project flink by apache.
the class SSLUtils method createSSLServerContext.
/**
* Creates the SSL Context for the server if SSL is configured
*
* @param sslConfig
* The application configuration
* @return The SSLContext object which can be used by the ssl transport server
* Returns null if SSL is disabled
* @throws Exception
* Thrown if there is any misconfiguration
*/
public static SSLContext createSSLServerContext(Configuration sslConfig) throws Exception {
Preconditions.checkNotNull(sslConfig);
SSLContext serverSSLContext = null;
if (getSSLEnabled(sslConfig)) {
LOG.debug("Creating server SSL context from configuration");
String keystoreFilePath = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEYSTORE, null);
String keystorePassword = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEYSTORE_PASSWORD, null);
String certPassword = sslConfig.getString(ConfigConstants.SECURITY_SSL_KEY_PASSWORD, null);
String sslProtocolVersion = sslConfig.getString(ConfigConstants.SECURITY_SSL_PROTOCOL, ConfigConstants.DEFAULT_SECURITY_SSL_PROTOCOL);
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream keyStoreFile = null;
try {
keyStoreFile = new FileInputStream(new File(keystoreFilePath));
ks.load(keyStoreFile, keystorePassword.toCharArray());
} finally {
if (keyStoreFile != null) {
keyStoreFile.close();
}
}
// Set up key manager factory to use the server key store
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, certPassword.toCharArray());
// Initialize the SSLContext
serverSSLContext = SSLContext.getInstance(sslProtocolVersion);
serverSSLContext.init(kmf.getKeyManagers(), null, null);
}
return serverSSLContext;
}
use of javax.net.ssl.KeyManagerFactory in project OpenAM by OpenRock.
the class Client method initializeJSSE.
/**
* Initializes JSSE enviroment.
*
* @throws Exception if an error occurs while initializing JSSE
*/
private static void initializeJSSE() throws Exception {
// put SunJSSE at fisrt place, so that JSSE will work
Provider provider = Security.getProvider("SunJSSE");
if (provider != null) {
Security.removeProvider("SunJSSE");
Security.insertProviderAt(provider, 1);
}
String algorithm = SystemPropertiesManager.get(SOAP_TRUST_SECMNGR_ALGO_PROP);
if (algorithm == null || algorithm.length() <= 0) {
algorithm = "SunX509";
}
JKSKeyProvider jkskp = createKeyProvider();
KeyStore trustStore = jkskp.getKeyStore();
KeyManagerFactory kf = KeyManagerFactory.getInstance(algorithm);
kf.init(trustStore, jkskp.getPrivateKeyPass().toCharArray());
kms = kf.getKeyManagers();
defaultX509km = (X509KeyManager) kms[0];
defineTrustManager(trustStore, algorithm);
}
Aggregations