List of usage examples for javax.net.ssl X509TrustManager X509TrustManager
X509TrustManager
From source file:org.openremote.android.console.net.SelfCertificateSSLSocketFactory.java
/** * Creates a new SelfCertificateSSLSocket object. * /*from w w w. j a va2s .co m*/ * @return the SSL context * * @throws IOException Signals that an I/O exception has occurred. */ private static SSLContext createEasySSLContext(Context context) throws IOException { TrustManager easyTrustManager = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; try { ORKeyStore keystore = ORKeyStore.getInstance(context); KeyManager[] managers = null; //keystore.fillKeyStore(); //keystore.saveKeyStore(); if (!keystore.isEmpty()) { KeyManagerFactory keyManagerFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyManagerFactory.init(keystore.getKeyStore(), "password".toCharArray()); managers = keyManagerFactory.getKeyManagers(); } SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(managers, new TrustManager[] { easyTrustManager }, null); return sslcontext; } catch (Exception e) { throw new IOException(e.getMessage()); } }
From source file:org.wso2.carbon.membership.scheme.kubernetes.api.KubernetesHttpsApiEndpoint.java
private static void disableCertificateValidation() { TrustManager[] dummyTrustMgr = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }/*from ww w . j av a2 s . c om*/ public void checkClientTrusted(X509Certificate[] certs, String authType) { // do nothing } public void checkServerTrusted(X509Certificate[] certs, String authType) { // do nothing } } }; // Ignore differences between given hostname and certificate hostname HostnameVerifier dummyHostVerifier = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { // always true return true; } }; // Install the all-trusting trust manager try { SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, dummyTrustMgr, new SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(dummyHostVerifier); } catch (Exception ignored) { } }
From source file:com.androidinahurry.network.utils.FakeSSLSocketFactory.java
public FakeSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(null);// w ww . ja v a2 s.c o m try { SSLContext context = SSLContext.getInstance("TLS"); // Create a trust manager that does not validate certificate chains // and simply // accept all type of certificates 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 { } } }; // Initialize the socket factory context.init(null, trustAllCerts, new SecureRandom()); sslFactory = context.getSocketFactory(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jboss.as.test.http.util.HttpClientUtils.java
/** * Returns https ready client.//from w ww. j a v a 2 s . co m * * @param base * @return */ public static HttpClient wrapHttpsClient(HttpClient base) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:hu.balazsbakai.sq.util.CustomTrustedSSLSocketFactory.java
public CustomTrustedSSLSocketFactory(KeyStore truststore) throws Exception { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }//from w w w . ja v a 2 s . co m public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { tm }, null); }
From source file:com.strato.hidrive.api.utils.StubSSLSocketFactory.java
public StubSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }// ww w. j a v a 2 s .c o m public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { tm }, null); }
From source file:com.blackboard.TrustAllSSLSocketFactory.java
public TrustAllSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) { }// ww w . j av a2 s .c o m public void checkServerTrusted(X509Certificate[] chain, String authType) { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { tm }, null); }
From source file:com.androidinahurry.network.utils.UnsafeSslSocketFactory.java
public UnsafeSslSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }/*from w w w. j a v a 2s .c o m*/ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { tm }, null); }
From source file:com.msopentech.odatajclient.engine.client.http.TrustAllSSLSocketFactory.java
public TrustAllSSLSocketFactory(KeyStore truststore) throws GeneralSecurityException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }//w w w. j av a 2 s. c o m public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { tm }, null); }
From source file:com.wso2.mobile.mdm.utils.WSO2SSLSocketFactory.java
public WSO2SSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }//from w w w.j a va 2 s .com public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext.init(null, new TrustManager[] { tm }, null); }