• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes

Problem :

Experiencing bellow error
javax.net.ssl.sslpeerunverifiedexception: peer not authenticated
by (6.9k points)  

1 Answer

0 votes

Solution :

You are experiencing this error because the server does not have a valid SSL certificate. So we must tell the client to use a different TrustManager. 

Bellow is the sample code:

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));

client = new DefaultHttpClient(ccm, base.getParams());
by (20.3k points)