use of javax.net.ssl.X509TrustManager in project languagetool by languagetool-org.
the class HTTPTools method disableCertChecks.
/**
* For testing, we disable all checks because we use a self-signed certificate on the server
* side and we want this test to run everywhere without importing the certificate into the JVM's trust store.
*
* See http://stackoverflow.com/questions/2893819/telling-java-to-accept-self-signed-ssl-certificate
*/
static void disableCertChecks() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
use of javax.net.ssl.X509TrustManager in project c-geo by just-radovan.
the class cgBase method trustAllHosts.
public static void trustAllHosts() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
Log.e(cgSettings.tag, "cgBase.trustAllHosts: " + e.toString());
}
}
use of javax.net.ssl.X509TrustManager in project k-9 by k9mail.
the class TrustManagerFactoryTest method testLocallyTrustedCertificateChain.
@Test
public void testLocallyTrustedCertificateChain() throws Exception {
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert3);
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
trustManager.checkServerTrusted(new X509Certificate[] { mCert3, mCaCert }, "authType");
}
use of javax.net.ssl.X509TrustManager in project k-9 by k9mail.
the class TrustManagerFactoryTest method testCertificateOfOtherHost.
@Test
public void testCertificateOfOtherHost() throws Exception {
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert1);
mKeyStore.addCertificate(MATCHING_HOST, PORT2, mCert2);
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
assertCertificateRejection(trustManager, new X509Certificate[] { mCert2 });
}
use of javax.net.ssl.X509TrustManager in project k-9 by k9mail.
the class TrustManagerFactoryTest method testLocallyTrustedCertificateChainNotMatchingHost.
@Test
public void testLocallyTrustedCertificateChainNotMatchingHost() throws Exception {
mKeyStore.addCertificate(NOT_MATCHING_HOST, PORT1, mCert3);
X509TrustManager trustManager = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT1);
trustManager.checkServerTrusted(new X509Certificate[] { mCert3, mCaCert }, "authType");
}
Aggregations