Created
May 30, 2013 11:03
-
-
Save zjor/5677136 to your computer and use it in GitHub Desktop.
How to avoid "Exception : javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated"
Compliant with Apache Http Client 4.2.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; | |
DefaultHttpClient base = new DefaultHttpClient(); | |
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)); | |
DefaultHttpClient httpClient = new DefaultHttpClient(ccm, base.getParams()); |
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[] {}; }
Dose my code will recurrented this Exception ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this gist!!!