Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception : javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

public HttpClientVM() {      BasicHttpParams params = new BasicHttpParams();     ConnManagerParams.setMaxTotalConnections(params, 10);     HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);     HttpProtocolParams.setUseExpectContinue(params, false);     HttpConnectionParams.setStaleCheckingEnabled(params, true);     HttpConnectionParams.setConnectionTimeout(params, 30000);     HostnameVerifier hostnameVerifier=           org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;     HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);     SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();     socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);     SchemeRegistry schemeRegistry = new SchemeRegistry();     schemeRegistry.register(new Scheme("http",socketFactory, 80));     schemeRegistry.register(new Scheme("https",socketFactory, 443));         ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);         // Set verifier              client = new DefaultHttpClient(manager, params);         } 

Problem:

When executing client.accessURL(url), the following error occurs:

Exception in thread "main" javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated     at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352)     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)     at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:397)     at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:495)     at org.apache.http.conn.scheme.SchemeSocketFactoryAdaptor.connectSocket(SchemeSocketFactoryAdaptor.java:62)     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:150)     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)     at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:575)     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732) 

Additional information:

  • Window 7
  • HttpClient 4
like image 688
Liu Avatar asked Mar 06 '12 04:03

Liu


People also ask

How do you fix peer not authenticated?

Resolving the problem The workaround is to extract the WebSphere Application Server certificate and add the extracted certificate to a new certificate store. Then, point the JVM that is running the Data Import command line to the new certificate store.

What is SSL peer unverified exception?

This exception indicates that the Java application's truststore was unable to validate the certificate chain. This can occur when the external target's certificates have not been imported into the truststore or one or more of the certificates have expired.


1 Answers

Expired certificate was the cause of our "javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated".

keytool -list -v -keystore filetruststore.ts

    Enter keystore password:     Keystore type: JKS     Keystore provider: SUN     Your keystore contains 1 entry     Alias name: somealias     Creation date: Jul 26, 2012     Entry type: PrivateKeyEntry     Certificate chain length: 1     Certificate[1]:     Owner: CN=Unknown, OU=SomeOU, O="Some Company, Inc.", L=SomeCity, ST=GA, C=US     Issuer: CN=Unknown, OU=SomeOU, O=Some Company, Inc.", L=SomeCity, ST=GA, C=US     Serial number: 5011a47b     Valid from: Thu Jul 26 16:11:39 EDT 2012 until: Wed Oct 24 16:11:39 EDT 2012 
like image 187
buzz3791 Avatar answered Sep 26 '22 08:09

buzz3791