use of javax.net.ssl.TrustManager in project robovm by robovm.
the class MyProvider method test_engineGetTrustManagers.
/**
* @throws NoSuchAlgorithmException
* javax.net.ssl.TrustManagerFactorySpi#engineGetTrustManagers()
*/
public void test_engineGetTrustManagers() throws NoSuchAlgorithmException {
factory.reset();
Provider provider = new MyProvider();
TrustManagerFactory tmf = TrustManagerFactory.getInstance("MyTMF", provider);
TrustManager[] tm = tmf.getTrustManagers();
assertTrue(factory.isEngineGetTrustManagersCalled());
factory.reset();
try {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
tmf.init(ks);
tm = tmf.getTrustManagers();
assertTrue(factory.isEngineGetTrustManagersCalled());
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
use of javax.net.ssl.TrustManager in project robovm by robovm.
the class myTrustManagerFactory method test_getTrustManagers.
/**
* Test for <code>geTrustManagers()</code>
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws NoSuchAlgorithmException
*/
public void test_getTrustManagers() {
try {
TrustManagerFactory trustMF = TrustManagerFactory.getInstance(getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
trustMF.init(ks);
TrustManager[] tm = trustMF.getTrustManagers();
assertNotNull("Result has not be null", tm);
assertTrue("Length of result TrustManager array should not be 0", (tm.length > 0));
} catch (Exception ex) {
fail("Unexpected exception " + ex.toString());
}
}
use of javax.net.ssl.TrustManager in project ddf by codice.
the class CometDClient method doTrustAllCertificates.
private void doTrustAllCertificates() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = 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 null;
}
} };
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HostnameVerifier hostnameVerifier = (s, sslSession) -> s.equalsIgnoreCase(sslSession.getPeerHost());
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
}
use of javax.net.ssl.TrustManager in project oxCore by GluuFederation.
the class SslDefaultHttpClient method newSslSocketFactory.
private SSLSocketFactory newSslSocketFactory() {
try {
TrustManager[] trustManagers = this.trustManagers;
if (useTrustManager) {
trustManagers = getTrustManagers();
}
KeyManager[] keyManagers = null;
if (useKeyManager) {
keyManagers = getKeyManagers();
}
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, trustManagers, new SecureRandom());
// Pass the keystore to the SSLSocketFactory
SSLSocketFactory sf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
return sf;
} catch (Exception ex) {
throw new IllegalArgumentException("Failed to load keystore", ex);
}
}
use of javax.net.ssl.TrustManager 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;
}
Aggregations