use of javax.net.ssl.TrustManager in project opennms by OpenNMS.
the class VmwareViJavaAccess method relax.
/**
* This method is used to "relax" the policies concerning self-signed certificates.
*/
protected void relax() {
TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
try {
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
} catch (Exception exception) {
logger.warn("Error setting relaxed SSL policy", exception);
}
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
}
use of javax.net.ssl.TrustManager in project zookeeper by apache.
the class X509Util method createSSLContext.
public static SSLContext createSSLContext(ZKConfig config) throws SSLContextException {
KeyManager[] keyManagers = null;
TrustManager[] trustManagers = null;
String keyStoreLocationProp = config.getProperty(ZKConfig.SSL_KEYSTORE_LOCATION);
String keyStorePasswordProp = config.getProperty(ZKConfig.SSL_KEYSTORE_PASSWD);
if (keyStoreLocationProp == null && keyStorePasswordProp == null) {
LOG.warn("keystore not specified for client connection");
} else {
if (keyStoreLocationProp == null) {
throw new SSLContextException("keystore location not specified for client connection");
}
if (keyStorePasswordProp == null) {
throw new SSLContextException("keystore password not specified for client connection");
}
try {
keyManagers = new KeyManager[] { createKeyManager(keyStoreLocationProp, keyStorePasswordProp) };
} catch (KeyManagerException e) {
throw new SSLContextException("Failed to create KeyManager", e);
}
}
String trustStoreLocationProp = config.getProperty(ZKConfig.SSL_TRUSTSTORE_LOCATION);
String trustStorePasswordProp = config.getProperty(ZKConfig.SSL_TRUSTSTORE_PASSWD);
if (trustStoreLocationProp == null && trustStorePasswordProp == null) {
LOG.warn("Truststore not specified for client connection");
} else {
if (trustStoreLocationProp == null) {
throw new SSLContextException("Truststore location not specified for client connection");
}
if (trustStorePasswordProp == null) {
throw new SSLContextException("Truststore password not specified for client connection");
}
try {
trustManagers = new TrustManager[] { createTrustManager(trustStoreLocationProp, trustStorePasswordProp) };
} catch (TrustManagerException e) {
throw new SSLContextException("Failed to create TrustManager", e);
}
}
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLSv1");
sslContext.init(keyManagers, trustManagers, null);
} catch (Exception e) {
throw new SSLContextException(e);
}
return sslContext;
}
use of javax.net.ssl.TrustManager in project geode by apache.
the class SocketCreator method createAndConfigureSSLContext.
/**
* Creates & configures the SSLContext when SSL is enabled.
*
* @return new SSLContext configured using the given protocols & properties
*
* @throws GeneralSecurityException if security information can not be found
* @throws IOException if information can not be loaded
*/
private SSLContext createAndConfigureSSLContext() throws GeneralSecurityException, IOException {
SSLContext newSSLContext = getSSLContextInstance();
KeyManager[] keyManagers = getKeyManagers();
TrustManager[] trustManagers = getTrustManagers();
newSSLContext.init(keyManagers, trustManagers, null);
return newSSLContext;
}
use of javax.net.ssl.TrustManager in project J2ME-Loader by nikita36078.
the class Connection method openConnection.
@Override
public javax.microedition.io.Connection openConnection(String name, int mode, boolean timeouts) throws IOException {
if (!org.microemu.cldc.http.Connection.isAllowNetworkConnection()) {
throw new IOException("No network");
}
int portSepIndex = name.lastIndexOf(':');
int port = Integer.parseInt(name.substring(portSepIndex + 1));
String host = name.substring("ssl://".length(), portSepIndex);
// TODO validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory factory = sc.getSocketFactory();
socket = factory.createSocket(host, port);
} catch (NoSuchAlgorithmException ex) {
throw new IOException(ex.toString());
} catch (KeyManagementException ex) {
throw new IOException(ex.toString());
}
return this;
}
use of javax.net.ssl.TrustManager in project syncany by syncany.
the class CipherUtil method createSSLContext.
/**
* Creates an SSL context, given a key store and a trust store.
*/
public static SSLContext createSSLContext(KeyStore keyStore, KeyStore trustStore) throws Exception {
try {
// Server key and certificate
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, new char[0]);
KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
// Trusted certificates
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
// Create SSL context
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, null);
return sslContext;
} catch (Exception e) {
throw new Exception("Unable to initialize SSL context", e);
}
}
Aggregations