use of javax.net.ssl.X509TrustManager in project cdap by caskdata.
the class NettyRouterHttpsTest method getSocketFactory.
@Override
protected SocketFactory getSocketFactory() throws Exception {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new java.security.SecureRandom());
return sc.getSocketFactory();
}
use of javax.net.ssl.X509TrustManager in project oxTrust by GluuFederation.
the class LinktrackService method newLink.
public String newLink(@NotNull String login, @NotNull String password, @NotNull String link) {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust managers
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
}
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(String.format(CREATE_LINK_URL_PATTERN, login, password, link));
HttpResponse response;
try {
response = httpclient.execute(httpget);
} catch (Exception e) {
log.error(String.format("Exception happened during linktrack link " + "creation with username: %s, password: %s," + " link: %s.", login, password, link), e);
return null;
}
String trackedLink = null;
if (response.getStatusLine().getStatusCode() == 201) {
try {
trackedLink = IOUtils.toString(response.getEntity().getContent());
} catch (Exception e) {
e.printStackTrace();
}
}
return trackedLink;
}
use of javax.net.ssl.X509TrustManager in project midpoint by Evolveum.
the class AbstractLdapTest method ldapConnect.
protected LdapNetworkConnection ldapConnect(UserLdapConnectionConfig config) throws LdapException, IOException {
if (config == null) {
config = new UserLdapConnectionConfig();
config.setLdapHost(getLdapServerHost());
config.setLdapPort(getLdapServerPort());
config.setBindDn(getLdapBindDn());
config.setBindPassword(getLdapBindPassword());
}
LOGGER.trace("LDAP connect to {}:{} as {}", config.getLdapHost(), config.getLdapPort(), config.getBindDn());
if (useSsl()) {
config.setUseSsl(true);
TrustManager trustManager = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
};
config.setTrustManagers(trustManager);
}
config.setBinaryAttributeDetector(binaryAttributeDetector);
LdapNetworkConnection connection = new LdapNetworkConnection(config);
boolean connected = connection.connect();
if (!connected) {
AssertJUnit.fail("Cannot connect to LDAP server " + config.getLdapHost() + ":" + config.getLdapPort());
}
LOGGER.trace("LDAP connected to {}:{}, executing bind as {}", config.getLdapHost(), config.getLdapPort(), config.getBindDn());
BindRequest bindRequest = new BindRequestImpl();
bindRequest.setDn(new Dn(config.getBindDn()));
bindRequest.setCredentials(config.getBindPassword());
bindRequest.setSimple(true);
BindResponse bindResponse = connection.bind(bindRequest);
if (bindResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS) {
ldapDisconnect(connection);
throw new SecurityException("Bind as " + config.getBindDn() + " failed: " + bindResponse.getLdapResult().getDiagnosticMessage() + " (" + bindResponse.getLdapResult().getResultCode() + ")");
}
LOGGER.trace("LDAP connected to {}:{}, bound as {}", config.getLdapHost(), config.getLdapPort(), config.getBindDn());
return connection;
}
use of javax.net.ssl.X509TrustManager in project midpoint by Evolveum.
the class AbstractIntegrationTest method logTrustManagers.
protected void logTrustManagers() throws NoSuchAlgorithmException, KeyStoreException {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
for (TrustManager trustManager : trustManagerFactory.getTrustManagers()) {
if (trustManager instanceof X509TrustManager) {
X509TrustManager x509TrustManager = (X509TrustManager) trustManager;
LOGGER.debug("TrustManager(X509): {}", x509TrustManager);
X509Certificate[] acceptedIssuers = x509TrustManager.getAcceptedIssuers();
if (acceptedIssuers != null) {
for (X509Certificate acceptedIssuer : acceptedIssuers) {
LOGGER.debug(" acceptedIssuer: {}", acceptedIssuer);
}
}
} else {
LOGGER.debug("TrustManager: {}", trustManager);
}
}
}
use of javax.net.ssl.X509TrustManager in project BBS-Android by bdpqchen.
the class CollectionClient method getUnSaveBuilder.
private static OkHttpClient.Builder getUnSaveBuilder() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
// 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 javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory);
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return builder;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations