use of javax.net.ssl.TrustManager in project Conversations by siacs.
the class MemorizingTrustManager method getTrustManager.
X509TrustManager getTrustManager(KeyStore ks) {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(ks);
for (TrustManager t : tmf.getTrustManagers()) {
if (t instanceof X509TrustManager) {
return (X509TrustManager) t;
}
}
} catch (Exception e) {
// Here, we are covering up errors. It might be more useful
// however to throw them out of the constructor so the
// embedding app knows something went wrong.
LOGGER.log(Level.SEVERE, "getTrustManager(" + ks + ")", e);
}
return null;
}
use of javax.net.ssl.TrustManager in project platform_frameworks_base by android.
the class X509TrustManagerExtensionsTest method testNormalUseCase.
public void testNormalUseCase() throws Exception {
String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
String defaultKeystoreType = KeyStore.getDefaultType();
tmf.init(KeyStore.getInstance(defaultKeystoreType));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
new X509TrustManagerExtensions((X509TrustManager) tm);
return;
}
}
fail();
}
use of javax.net.ssl.TrustManager in project camel by apache.
the class RabbitMQComponent method createEndpoint.
@Override
protected RabbitMQEndpoint createEndpoint(String uri, String remaining, Map<String, Object> params) throws Exception {
URI host = new URI("http://" + remaining);
String hostname = host.getHost();
int portNumber = host.getPort();
// We need to support the exchange to be "" the path is empty
String exchangeName = "";
if (host.getPath().trim().length() > 1) {
exchangeName = host.getPath().substring(1);
}
// ConnectionFactory reference
ConnectionFactory connectionFactory = resolveAndRemoveReferenceParameter(params, "connectionFactory", ConnectionFactory.class);
@SuppressWarnings("unchecked") Map<String, Object> clientProperties = resolveAndRemoveReferenceParameter(params, "clientProperties", Map.class);
TrustManager trustManager = resolveAndRemoveReferenceParameter(params, "trustManager", TrustManager.class);
RabbitMQEndpoint endpoint;
if (connectionFactory == null) {
endpoint = new RabbitMQEndpoint(uri, this);
} else {
endpoint = new RabbitMQEndpoint(uri, this, connectionFactory);
}
endpoint.setHostname(hostname);
endpoint.setPortNumber(portNumber);
endpoint.setExchangeName(exchangeName);
endpoint.setClientProperties(clientProperties);
endpoint.setTrustManager(trustManager);
setProperties(endpoint, params);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating RabbitMQEndpoint with host {}:{} and exchangeName: {}", new Object[] { endpoint.getHostname(), endpoint.getPortNumber(), endpoint.getExchangeName() });
}
HashMap<String, Object> args = new HashMap<>();
args.putAll(IntrospectionSupport.extractProperties(params, ARG_PREFIX));
endpoint.setArgs(args);
HashMap<String, Object> argsCopy = new HashMap<>(args);
// Combine the three types of rabbit arguments with their individual endpoint properties
endpoint.getExchangeArgs().putAll(IntrospectionSupport.extractProperties(argsCopy, EXCHANGE_ARG_PREFIX));
endpoint.getQueueArgs().putAll(IntrospectionSupport.extractProperties(argsCopy, QUEUE_ARG_PREFIX));
endpoint.getBindingArgs().putAll(IntrospectionSupport.extractProperties(argsCopy, BINDING_ARG_PREFIX));
return endpoint;
}
use of javax.net.ssl.TrustManager in project cassandra by apache.
the class SSLFactory method createSSLContext.
@SuppressWarnings("resource")
public static SSLContext createSSLContext(EncryptionOptions options, boolean buildTruststore) throws IOException {
FileInputStream tsf = null;
FileInputStream ksf = null;
SSLContext ctx;
try {
ctx = SSLContext.getInstance(options.protocol);
TrustManager[] trustManagers = null;
if (buildTruststore) {
tsf = new FileInputStream(options.truststore);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(options.algorithm);
KeyStore ts = KeyStore.getInstance(options.store_type);
ts.load(tsf, options.truststore_password.toCharArray());
tmf.init(ts);
trustManagers = tmf.getTrustManagers();
}
ksf = new FileInputStream(options.keystore);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(options.algorithm);
KeyStore ks = KeyStore.getInstance(options.store_type);
ks.load(ksf, options.keystore_password.toCharArray());
if (!checkedExpiry) {
for (Enumeration<String> aliases = ks.aliases(); aliases.hasMoreElements(); ) {
String alias = aliases.nextElement();
if (ks.getCertificate(alias).getType().equals("X.509")) {
Date expires = ((X509Certificate) ks.getCertificate(alias)).getNotAfter();
if (expires.before(new Date()))
logger.warn("Certificate for {} expired on {}", alias, expires);
}
}
checkedExpiry = true;
}
kmf.init(ks, options.keystore_password.toCharArray());
ctx.init(kmf.getKeyManagers(), trustManagers, null);
} catch (Exception e) {
throw new IOException("Error creating the initializing the SSL Context", e);
} finally {
FileUtils.closeQuietly(tsf);
FileUtils.closeQuietly(ksf);
}
return ctx;
}
use of javax.net.ssl.TrustManager in project camel by apache.
the class JettySolrFactory method installAllTrustingClientSsl.
private static void installAllTrustingClientSsl() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
// // Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
SSLContext.setDefault(sslContext);
// // Install the all-trusting trust manager
// final SSLContext sslContext = SSLContext.getInstance( "SSL" );
// sslContext.init( null, trustAllCerts, new
// java.security.SecureRandom() );
// // Create an ssl socket factory with our all-trusting manager
// final SSLSocketFactory sslSocketFactory =
// sslContext.getSocketFactory();
// HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
}
Aggregations