use of javax.net.ssl.KeyManagerFactory in project UltimateAndroid by cymcsg.
the class HttpsUtils method getKeyManagerFactory.
private static KeyManagerFactory getKeyManagerFactory(InputStream key, String keyPassword) {
KeyManagerFactory kmf = null;
try {
String keyStoreType = "BKS";
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(key, keyPassword.toCharArray());
String kmfAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
kmf.init(keyStore, keyPassword.toCharArray());
} catch (Exception e) {
e.printStackTrace();
}
return kmf;
}
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 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 ribbon by Netflix.
the class AbstractSslContextFactory method createKeyManagers.
/**
* Creates the key managers to be used by the factory from the associated key store and password.
*
* @return the newly created array of key managers
* @throws ClientSslSocketFactoryException if an exception is detected in loading the key store
*/
private KeyManager[] createKeyManagers() throws ClientSslSocketFactoryException {
final KeyManagerFactory factory;
try {
factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
factory.init(this.keyStore, this.keyStorePassword.toCharArray());
} catch (NoSuchAlgorithmException e) {
throw new ClientSslSocketFactoryException(String.format("Failed to create the key store because the algorithm %s is not supported. ", KeyManagerFactory.getDefaultAlgorithm()), e);
} catch (UnrecoverableKeyException e) {
throw new ClientSslSocketFactoryException("Unrecoverable Key Exception initializing key manager factory; this is probably fatal", e);
} catch (KeyStoreException e) {
throw new ClientSslSocketFactoryException("KeyStore exception initializing key manager factory; this is probably fatal", e);
}
KeyManager[] managers = factory.getKeyManagers();
LOGGER.debug("Key managers are initialized. Total {} managers. ", managers.length);
return managers;
}
use of javax.net.ssl.KeyManagerFactory in project ribbon by Netflix.
the class MockHttpServer method before.
public void before(final Description description) throws Exception {
this.service = Executors.newFixedThreadPool(threadCount, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("TestHttpServer-%d").build());
InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 0);
if (hasSsl) {
byte[] sampleTruststore1 = Base64.decode(TEST_TS1);
byte[] sampleKeystore1 = Base64.decode(TEST_KS1);
keystore = File.createTempFile("SecureAcceptAllGetTest", ".keystore");
truststore = File.createTempFile("SecureAcceptAllGetTest", ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(keystore);
try {
keystoreFileOut.write(sampleKeystore1);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(truststore);
try {
truststoreFileOut.write(sampleTruststore1);
} finally {
truststoreFileOut.close();
}
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keystore), PASSWORD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, PASSWORD.toCharArray());
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(new FileInputStream(truststore), PASSWORD.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
HttpsServer secureServer = HttpsServer.create(inetSocketAddress, 0);
secureServer.setHttpsConfigurator(new HttpsConfigurator(sc) {
public void configure(HttpsParameters params) {
SSLContext c = getSSLContext();
SSLParameters sslparams = c.getDefaultSSLParameters();
params.setSSLParameters(sslparams);
}
});
server = secureServer;
} else {
server = HttpServer.create(inetSocketAddress, 0);
}
server.setExecutor(service);
for (Entry<String, HttpHandler> handler : handlers.entrySet()) {
server.createContext(handler.getKey(), handler.getValue());
}
server.start();
localHttpServerPort = server.getAddress().getPort();
System.out.println(description.getClassName() + " TestServer is started: " + getServerUrl());
}
Aggregations