use of javax.net.ssl.KeyManagerFactory in project xDrip-plus by jamorham.
the class SSLServerSocketHelper method makeSSLSocketFactory.
static SSLServerSocketFactory makeSSLSocketFactory(InputStream keystoreStream, char[] passphrase) throws IOException {
try {
// bks should be supported - stream needs to be in this format
final KeyStore keystore = KeyStore.getInstance("BKS");
keystore.load(keystoreStream, passphrase);
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, passphrase);
return makeSSLSocketFactory(keystore, keyManagerFactory);
} catch (Exception e) {
// simplify exception handling
throw new IOException(e.getMessage());
}
}
use of javax.net.ssl.KeyManagerFactory in project iaf by ibissource.
the class AuthSSLProtocolSocketFactory method createKeyManagers.
private 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 BaseProject by fly803.
the class HttpsUtils method prepareKeyManager.
private static KeyManager[] prepareKeyManager(InputStream bksFile, String password) {
try {
if (bksFile == null || password == null)
return null;
KeyStore clientKeyStore = KeyStore.getInstance("BKS");
clientKeyStore.load(bksFile, password.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(clientKeyStore, password.toCharArray());
return keyManagerFactory.getKeyManagers();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
e.printStackTrace();
} catch (CertificateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of javax.net.ssl.KeyManagerFactory in project async-http-client by AsyncHttpClient.
the class TestUtils method createKeyManagers.
private static KeyManager[] createKeyManagers() throws GeneralSecurityException, IOException {
KeyStore ks = KeyStore.getInstance("JKS");
try (InputStream keyStoreStream = TestUtils.class.getClassLoader().getResourceAsStream("ssltest-cacerts.jks")) {
char[] keyStorePassword = "changeit".toCharArray();
ks.load(keyStoreStream, keyStorePassword);
}
assert (ks.size() > 0);
// Set up key manager factory to use our key store
char[] certificatePassword = "changeit".toCharArray();
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, certificatePassword);
// Initialize the SSLContext to work with our key managers.
return kmf.getKeyManagers();
}
use of javax.net.ssl.KeyManagerFactory in project ranger by apache.
the class NiFiRegistryConnectionMgr method createSslContext.
private static SSLContext createSslContext(final String keystore, final char[] keystorePasswd, final String keystoreType, final String truststore, final char[] truststorePasswd, final String truststoreType, final String protocol) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException {
// prepare the keystore
final KeyStore keyStore = KeyStore.getInstance(keystoreType);
try (final InputStream keyStoreStream = new FileInputStream(keystore)) {
keyStore.load(keyStoreStream, keystorePasswd);
}
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keystorePasswd);
// prepare the truststore
final KeyStore trustStore = KeyStore.getInstance(truststoreType);
try (final InputStream trustStoreStream = new FileInputStream(truststore)) {
trustStore.load(trustStoreStream, truststorePasswd);
}
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
// initialize the ssl context
final SSLContext sslContext = SSLContext.getInstance(protocol);
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
return sslContext;
}
Aggregations