List of usage examples for javax.net.ssl X509TrustManager X509TrustManager
X509TrustManager
From source file:info.semanticsoftware.semassist.android.encryption.CustomSSLSocketFactory.java
public CustomSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }/* w ww. j a v a2s .co m*/ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; try { sslContext.init(null, new TrustManager[] { tm }, null); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.odoo.core.rpc.http.OdooSafeClient.java
private static SSLSocketFactory getSecureConnectionSetting() { TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override//from w w w.j av a2 s .c o m public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[] {}; } } }; SSLSocketFactory ssf = null; try { SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, null); ssf = new OSSLSocketFactory(sc); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Exception ea) { ea.printStackTrace(); } return ssf; }
From source file:com.socialize.net.NaiveSSLSocketFactory.java
public NaiveSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }//from w ww . j a va 2 s . c o m public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { tm }, null); }
From source file:com.tmount.business.cloopen.util.CcopHttpClient.java
/** * SSL//from w w w .jav a 2 s . c o m * @param hostname ??IP?? * @param protocol ????TLS-?? * @param port ?? * @param scheme ???? * @return HttpClient * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public DefaultHttpClient registerSSL(String hostname, String protocol, int port, String scheme) throws NoSuchAlgorithmException, KeyManagementException { //HttpClient DefaultHttpClient httpclient = new DefaultHttpClient(); //SSL SSLContext ctx = SSLContext.getInstance(protocol); //??? X509TrustManager tm = new X509TrustManager() { /** * ?? */ @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { //? ? } /** * ??? * @param chain ? * @param authType ???authTypeRSA */ @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { if (chain == null || chain.length == 0) throw new IllegalArgumentException("null or zero-length certificate chain"); if (authType == null || authType.length() == 0) throw new IllegalArgumentException("null or zero-length authentication type"); boolean br = false; Principal principal = null; for (X509Certificate x509Certificate : chain) { principal = x509Certificate.getSubjectX500Principal(); if (principal != null) { br = true; return; } } if (!br) { throw new CertificateException("????"); } } /** * CA?? */ @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }; //?SSL ctx.init(null, new TrustManager[] { tm }, new java.security.SecureRandom()); //SSL SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme(scheme, port, socketFactory); //SSL httpclient.getConnectionManager().getSchemeRegistry().register(sch); return httpclient; }
From source file:org.ocsinventoryng.android.actions.CoolSSLSocketFactory.java
public CoolSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }//from w ww . ja v a 2 s. co m public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { for (X509Certificate aChain : chain) { Log.d("X509", aChain.getSubjectDN().toString()); } } public X509Certificate[] getAcceptedIssuers() { return null; } }; Log.d("X509", "CoolSSLSocketFactory"); sslContext.init(null, new TrustManager[] { tm }, null); setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }
From source file:com.ab.http.MySSLSocketFactory.java
/** * Instantiates a new my ssl socket factory. * * @param truststore the truststore//from w ww. j av a2s . c om * @throws NoSuchAlgorithmException the no such algorithm exception * @throws KeyManagementException the key management exception * @throws KeyStoreException the key store exception * @throws UnrecoverableKeyException the unrecoverable key exception */ public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } }; sslContext.init(null, new TrustManager[] { tm }, null); }
From source file:cn.geowind.takeout.verify.CcopHttpClient.java
/** * SSL//ww w . jav a 2s . c om * * @param hostname * ??IP?? * @param protocol * ????TLS-?? * @param port * ?? * @param scheme * ???? * @return HttpClient * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public DefaultHttpClient registerSSL(String hostname, String protocol, int port, String scheme) throws NoSuchAlgorithmException, KeyManagementException { // HttpClient DefaultHttpClient httpclient = new DefaultHttpClient(); // SSL SSLContext ctx = SSLContext.getInstance(protocol); // ??? X509TrustManager tm = new X509TrustManager() { /** * CA?? */ public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } /** * ??? * * @param chain * ? * @param authType * ???authTypeRSA */ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { if (chain == null || chain.length == 0) throw new IllegalArgumentException("null or zero-length certificate chain"); if (authType == null || authType.length() == 0) throw new IllegalArgumentException("null or zero-length authentication type"); boolean br = false; Principal principal = null; for (X509Certificate x509Certificate : chain) { principal = x509Certificate.getSubjectX500Principal(); if (principal != null) { br = true; return; } } if (!br) { throw new CertificateException("????"); } } /** * ?? */ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } }; // ?SSL ctx.init(null, new TrustManager[] { tm }, new java.security.SecureRandom()); // SSL SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme sch = new Scheme(scheme, port, socketFactory); // SSL httpclient.getConnectionManager().getSchemeRegistry().register(sch); return httpclient; }
From source file:ui.shared.FreebaseHelper.java
@SuppressWarnings("deprecation") public static HttpClient wrapClient(HttpClient base) { try {/* w ww. j a v a2s.com*/ 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; } }; X509HostnameVerifier verifier = new X509HostnameVerifier() { public void verify(String string, SSLSocket ssls) throws IOException { } public void verify(String string, X509Certificate xc) throws SSLException { } public void verify(String string, String[] strings, String[] strings1) throws SSLException { } public boolean verify(String string, SSLSession ssls) { return true; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(verifier); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:li.klass.fhem.fhem.CustomSSLSocketFactory.java
public CustomSSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { super(truststore); TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { }/*from w ww . ja v a2s. c om*/ 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.thali.utilities.universal.HttpKeySSLSocketFactory.java
public HttpKeySSLSocketFactory(final PublicKey serverPublicKey, final KeyStore clientKeyStore, final char[] clientPassPhrase) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { super((KeyStore) null); final ThaliPublicKeyComparer thaliPublicKeyComparer = serverPublicKey == null ? null : new ThaliPublicKeyComparer(serverPublicKey); TrustManager trustManager = new X509TrustManager() { @Override/* ww w. j a v a 2s. com*/ public void checkClientTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException { throw new RuntimeException( "We should not have gotten a client trusted call, authType was:" + authType); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException { //TODO: We actually need to restrict authTypes to known secure ones if (serverPublicKey == null) { return; } PublicKey rootPublicKey = x509Certificates[x509Certificates.length - 1].getPublicKey(); if (thaliPublicKeyComparer.KeysEqual(rootPublicKey) == false) { throw new RuntimeException("Presented server root key does not match expected server root key"); } } @Override public X509Certificate[] getAcceptedIssuers() { return null; } }; KeyManagerFactory keyManagerFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyManagerFactory.init(clientKeyStore, clientPassPhrase); sslContext = SSLContext.getInstance("TLS"); sslContext.init(keyManagerFactory.getKeyManagers(), new TrustManager[] { trustManager }, new SecureRandom()); this.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); }