title: Apache HTTPClient SSLPeerUnverifiedException
body: <p>Using Apache HttpClient 4.2.1. Using code copied from the form based login example</p>
  
  <p><a href="http://hc.apache.org/httpcomponents-client-ga/examples.html" rel="nofollow noreferrer">http://hc.apache.org/httpcomponents-client-ga/examples.html</a></p>
  
  <p>I get an exception when accessing an SSL protected login form:</p>
  
  <pre><code>Getting library items from https://appserver.gtportalbase.com/agileBase/AppController.servlet?return=blank
  javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
  Closing http connection
  at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)
  at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
  at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572)
  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
  at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
  at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
  </code></pre>
  
  <p>The certificate as far as I can tell is fine (see the URL before the stack trace), not expired - browsers don't complain.</p>
  
  <p>I've tried importing the certificate into my keystore a la</p>
  
  <p><a href="https://stackoverflow.com/questions/1828775/how-to-handle-invalid-ssl-certificates-with-apache-httpclient">How to handle invalid SSL certificates with Apache HttpClient?</a></p>
  
  <p>with no change. I believe you can create a custom SSLContext to force Java to ignore the error but I'd rather fix the root cause as I don't want to open up any security holes.</p>
  
  <p>Any ideas?</p>