by
0
5
61k
1,623
Top 1% !
Popular
Famous
Pearl of Wisdom
Specified
Popularity: 35th place
Created
Modified Jan 30, 2014

Published on:

No tags for this snippet yet.
LanguageJava
LicenseMIT_X11
MethodNamegetAcceptedIssuers
OutputTypejava.security.cert.X509Certificate[]
SourceGithub

Get OkHttpClient which ignores all SSL errors.

Get OkHttpClient which ignores all SSL errors.: 
GagSsl.java
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/25364/Get-OkHttpClient-which-ignores-all-SSL-e?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
private static OkHttpClient getUnsafeOkHttpClient() { try { // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; // Install the all-trusting trust manager final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setSslSocketFactory(sslSocketFactory); okHttpClient.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); return okHttpClient; } catch (Exception e) { throw new RuntimeException(e); } }
If you want to be updated about similar snippets, Sign in and follow our Channels
Originally posted on https://gist.github.com/8706740