use of javax.net.ssl.KeyManagerFactory in project cxf by apache.
the class STSTokenOutInterceptorTest method prepareTLSParams.
private TLSClientParameters prepareTLSParams() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException {
TLSClientParameters tlsParams = new TLSClientParameters();
tlsParams.setDisableCNCheck(true);
KeyStore trustStore = loadClientKeystore();
TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(trustStore);
TrustManager[] tm = trustFactory.getTrustManagers();
tlsParams.setTrustManagers(tm);
KeyStore keyStore = loadClientKeystore();
KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyFactory.init(keyStore, KEY_PASS.toCharArray());
KeyManager[] km = keyFactory.getKeyManagers();
tlsParams.setKeyManagers(km);
return tlsParams;
}
use of javax.net.ssl.KeyManagerFactory in project cxf by apache.
the class STSTokenRetrieverTest method prepareTLSParams.
private TLSClientParameters prepareTLSParams() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException {
TLSClientParameters tlsParams = new TLSClientParameters();
tlsParams.setDisableCNCheck(true);
KeyStore trustStore = loadClientKeystore();
TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(trustStore);
TrustManager[] tm = trustFactory.getTrustManagers();
tlsParams.setTrustManagers(tm);
KeyStore keyStore = loadClientKeystore();
KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyFactory.init(keyStore, KEY_PASS.toCharArray());
KeyManager[] km = keyFactory.getKeyManagers();
tlsParams.setKeyManagers(km);
return tlsParams;
}
use of javax.net.ssl.KeyManagerFactory in project atlasmap by atlasmap.
the class AtlasItestsConfiguration method createSslContext.
private SSLContext createSslContext() throws Exception {
SSLContext context = SSLContext.getInstance("TLS");
KeyStore keyStore = KeyStore.getInstance("JKS");
String keyStoreFilename = properties.getProperty("https.keystore", "ssl.keystore");
char[] keyStorePassword = properties.getProperty("https.keystore.password", "atlasmap").toCharArray();
keyStore.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(keyStoreFilename), keyStorePassword);
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmfactory.init(keyStore, keyStorePassword);
context.init(kmfactory.getKeyManagers(), new TrustManager[] { new DummyTrustManager() }, null);
return context;
}
use of javax.net.ssl.KeyManagerFactory in project oap by oaplatform.
the class SecureHttpListener method createSocket.
@SneakyThrows
@Override
protected ServerSocket createSocket() {
if (Files.exists(keystoreLocation)) {
try (val inputStream = IoStreams.in(keystoreLocation, PLAIN)) {
log.info("Keystore {} exists, trying to initialize", keystoreLocation);
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(inputStream, keystorePassword.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keystorePassword.toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
ServerSocket serverSocket = sslContext.getServerSocketFactory().createServerSocket();
serverSocket.setReuseAddress(true);
serverSocket.setSoTimeout(timeout);
serverSocket.bind(new InetSocketAddress(port));
log.info("Successfully initialized secure http listener");
return serverSocket;
} catch (BindException e) {
log.error("Cannot bind to port [{}]", port);
throw e;
}
} else {
throw new CertificateException(keystoreLocation + " not found");
}
}
use of javax.net.ssl.KeyManagerFactory in project baseio by generallycloud.
the class SslContextBuilder method buildKeyManagerFactory.
private KeyManagerFactory buildKeyManagerFactory(KeyStore ks, char[] keyPasswordChars) throws SSLException {
String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
if (algorithm == null) {
algorithm = "SunX509";
}
// Set up key manager factory to use our key store
try {
KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
kmf.init(ks, keyPasswordChars);
return kmf;
} catch (Exception e) {
throw new SSLException(e);
}
}
Aggregations