0

I am trying to bypass certificate using the following code :

private static HttpClient wrapClient(HttpClient base) throws AGException { 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 (NoSuchAlgorithmException nsaex)
 {
   throw new AGException(nsaex, "Not able to get the SSL Context");
 }
 catch (KeyManagementException kmex) {
     throw new AGException(kmex, "Not able to get the SSL Context");
 }

}

but still getting the below error javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

Just to brief my assigment :

i am using putty to tunnel to a server and making SOAP over https call to connect to that server but receiving the same error even trying using above code.

Any help/suggesstions would be greatly appricates. Thanks in advance.

-Nitish

Nitish
  • 1
  • 2

1 Answers1

1

Don't use insecure TrustManagers.

The issue here is that the peer hasn't presented a certificate at all.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • when you say peer, that means client or server? In my case i am not using any certificate at my side and as I mentioned i want to ignore any use of certificate at my side. To summarize, i want to call a secured server(https call) ignoring handshake and for that i used above code. It would be very helpful if you can share right code or an tell where to change in my code. Thanks in advance. – Nitish Apr 22 '13 at 19:54
  • When I say 'peer' I mean the guy at the other end of the wire. – user207421 Apr 24 '13 at 10:31