use of javax.net.ssl.TrustManager in project useful-java-links by Vedenin.
the class GithubDownLoadTests method initHTTPSDownload.
private static void initHTTPSDownload() throws Exception {
// Create a new trust manager that trust all certificates
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) {
}
} };
// Activate the new trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
System.out.print(e.getMessage());
}
}
use of javax.net.ssl.TrustManager in project OpenAttestation by OpenAttestation.
the class SslUtil method createX509TrustManagerWithCertificates.
public static X509TrustManager createX509TrustManagerWithCertificates(X509Certificate[] certificates) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(createTrustedSslKeystore(certificates));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (IOException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (CertificateException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (UnrecoverableEntryException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
} catch (KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
use of javax.net.ssl.TrustManager in project OpenAttestation by OpenAttestation.
the class X509Util method createX509TrustManagerWithKeystore.
/**
* @deprecated use TlsPolicy instead
* @param keystore
* @return
* @throws KeyManagementException
*/
public static X509TrustManager createX509TrustManagerWithKeystore(SimpleKeystore keystore) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(KeyStoreUtil.createTrustedSslKeystore(keystore));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException | IOException | CertificateException | UnrecoverableEntryException | KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
use of javax.net.ssl.TrustManager in project OpenAttestation by OpenAttestation.
the class X509Util method createX509TrustManagerWithCertificates.
/**
*
* @deprecated use TlsPolicy instead
* @param certificates
* @return
* @throws KeyManagementException
*/
public static X509TrustManager createX509TrustManagerWithCertificates(X509Certificate[] certificates) throws KeyManagementException {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(KeyStoreUtil.createTrustedSslKeystore(certificates));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
return (X509TrustManager) tm;
}
}
} catch (NoSuchAlgorithmException | IOException | CertificateException | UnrecoverableEntryException | KeyStoreException e) {
throw new KeyManagementException("Cannot create X509TrustManager", e);
}
throw new IllegalArgumentException("TrustManagerFactory did not return an X509TrustManager instance");
}
use of javax.net.ssl.TrustManager in project OpenGrok by OpenGrok.
the class Query method createHttpsUrlConnection.
private HttpsURLConnection createHttpsUrlConnection(URL url) {
try {
System.setProperty("jsse.enableSNIExtension", "false");
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
return (HttpsURLConnection) url.openConnection();
} catch (Exception ex) {
handleException(ex);
}
return null;
}
Aggregations