use of javax.net.ssl.TrustManagerFactory in project XobotOS by xamarin.
the class DefaultSSLContextImpl method getTrustManagers.
// TODO javax.net.ssl.trustStoreProvider system property
TrustManager[] getTrustManagers() throws GeneralSecurityException, IOException {
if (TRUST_MANAGERS != null) {
return TRUST_MANAGERS;
}
// find TrustStore, TrustManagers
String keystore = System.getProperty("javax.net.ssl.trustStore");
if (keystore == null) {
return null;
}
String keystorepwd = System.getProperty("javax.net.ssl.trustStorePassword");
char[] pwd = (keystorepwd == null) ? null : keystorepwd.toCharArray();
// TODO Defaults: jssecacerts; cacerts
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(keystore));
ks.load(is, pwd);
} finally {
if (is != null) {
is.close();
}
}
String tmfAlg = Security.getProperty("ssl.TrustManagerFactory.algorithm");
if (tmfAlg == null) {
tmfAlg = "PKIX";
}
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlg);
tmf.init(ks);
TRUST_MANAGERS = tmf.getTrustManagers();
return TRUST_MANAGERS;
}
use of javax.net.ssl.TrustManagerFactory in project camel by apache.
the class HttpsServerTestSupport method getSSLContext.
@Override
protected SSLContext getSSLContext() throws Exception {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(new FileInputStream(KEYSTORE), PASSWORD.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, PASSWORD.toCharArray());
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(new FileInputStream(KEYSTORE), PASSWORD.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
SSLContext sslcontext = SSLContext.getInstance(SECURE_SOCKET_PROTOCOL);
sslcontext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
return sslcontext;
}
use of javax.net.ssl.TrustManagerFactory in project camel by apache.
the class AbstractJsseParametersTest method createPropertiesPlaceholderAwareContext.
protected CamelContext createPropertiesPlaceholderAwareContext() throws Exception {
Properties supplementalProperties = new Properties();
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
SecureRandom sr = null;
try {
sr = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
// Ignore
}
SSLContext sslc = SSLContext.getInstance("TLS");
sslc.init(null, null, null);
SSLSocket socket = (SSLSocket) sslc.getSocketFactory().createSocket();
supplementalProperties.setProperty("keyStoreParameters.type", KeyStore.getDefaultType());
supplementalProperties.setProperty("keyStoreParameters.provider", ks.getProvider().getName());
supplementalProperties.setProperty("keyManagersParameters.algorithm", KeyManagerFactory.getDefaultAlgorithm());
supplementalProperties.setProperty("keyManagersParameters.provider", kmf.getProvider().getName());
supplementalProperties.setProperty("trustManagersParameters.algorithm", TrustManagerFactory.getDefaultAlgorithm());
supplementalProperties.setProperty("trustManagersParameters.provider", tmf.getProvider().getName());
if (sr != null) {
supplementalProperties.setProperty("secureRandomParameters.algorithm", "SHA1PRNG");
supplementalProperties.setProperty("secureRandomParameters.provider", sr.getProvider().getName());
}
supplementalProperties.setProperty("sslContextParameters.provider", sslc.getProvider().getName());
supplementalProperties.setProperty("cipherSuite.0", socket.getSupportedCipherSuites()[0]);
// Have to skip this guy because he doesn't work with TLS as the SSLContext protocol
String ssp = "";
for (String protocol : socket.getSupportedProtocols()) {
if (!"SSLv2Hello".equals(protocol)) {
ssp = protocol;
break;
}
}
supplementalProperties.setProperty("secureSocketProtocol.0", ssp);
return this.createPropertiesPlaceholderAwareContext(supplementalProperties);
}
use of javax.net.ssl.TrustManagerFactory in project robovm by robovm.
the class SSLSocketFactory method createTrustManagers.
private static TrustManager[] createTrustManagers(final KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException {
if (keystore == null) {
throw new IllegalArgumentException("Keystore may not be null");
}
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmfactory.init(keystore);
return tmfactory.getTrustManagers();
}
use of javax.net.ssl.TrustManagerFactory in project robovm by robovm.
the class DefaultSSLContextImpl method getTrustManagers.
// TODO javax.net.ssl.trustStoreProvider system property
TrustManager[] getTrustManagers() throws GeneralSecurityException, IOException {
if (TRUST_MANAGERS != null) {
return TRUST_MANAGERS;
}
// find TrustStore, TrustManagers
String keystore = System.getProperty("javax.net.ssl.trustStore");
if (keystore == null) {
return null;
}
String keystorepwd = System.getProperty("javax.net.ssl.trustStorePassword");
char[] pwd = (keystorepwd == null) ? null : keystorepwd.toCharArray();
// TODO Defaults: jssecacerts; cacerts
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(keystore));
ks.load(is, pwd);
} finally {
if (is != null) {
is.close();
}
}
String tmfAlg = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlg);
tmf.init(ks);
TRUST_MANAGERS = tmf.getTrustManagers();
return TRUST_MANAGERS;
}
Aggregations