0

I am using HttpClient-4.0.3 and already added certificate on server. The command is as below :

keytool -import -file "C:\Users\apex\Downloads\RootCABangladesh2016.cer" -keystore "C:\Program Files\Java\jdk1.8.0_131\jre\lib\security\cacerts" -alias "sds certificate"

But still I am getting below error.

I have read existing issue saying to add TrustManager (X509TrustManager) but as per my thinking this is not solution.

The exception is as follows :

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:431)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)   
    at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:399)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
    at jsonParser.JSONParser.makeHttpRequest(JSONParser.java:54)
    at powersms.SendSms.sendSms(SendSms.java:44)
    at powersms.SendSms.run(SendSms.java:32) 

I have tried this solution . But this is not working for me .

I have checked the expire date by this command.

keytool -list -v -alias "sds certificate" -keystore "C:\Program Files\Java\jdk1.8.0_131\jre\lib\security\cacerts" -storepass "changeit" | grep "Valid from:"

But this shows me :

Valid from: Wed Dec 21 16:43:56 BDT 2016 until: Mon Dec 21 16:43:56 BDT 2026

I have added jvm parameters .

-Djavax.net.debug=ssl:handshake

Then I go this output :

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
    at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:431)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
    at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:399)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
    at jsonParser.JSONParser.makeHttpRequest(JSONParser.java:54)
    at powersms.SendSms.sendSms(SendSms.java:44)
    at powersms.SendSms.run(SendSms.java:32)
%% Invalidated:  [Session-1, TLS_RSA_WITH_AES_128_CBC_SHA]
Thread-0, SEND TLSv1 ALERT:  fatal, description = certificate_unknown
Thread-0, WRITE: TLSv1 Alert, length = 2
Thread-0, called closeSocket()
Thread-0, handling exception: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Thread-0, IOException in getSession():  javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Buffer Error  Error converting result java.lang.NullPointerException
JSON ParserError parsing data org.json.JSONException: A JSONObject text must begin with '{' at character 0
Json is null
3
  • You are correct. It is not a solution. The solution is either to ensure the server's certificate is signed by a recognized CA or else to import it into your truststore. You seem to have done the former if the server's certificate was signed by a certificate with the alias "sds certificate". Commented May 9, 2017 at 6:25
  • What can I do ? Commented May 9, 2017 at 6:26
  • I have imported the certificate . Commented May 9, 2017 at 6:36

1 Answer 1

1

This has been an issue with HttpClient for a while when you try to connect to a secured(i.e. https) URL. There's this class EasySSLProtocolSocketFactory in HttpClient though, which lets you create sockets that accept self-signed certificates. You can try using that as described in the documentation- EasySSLProtocolSocketFactory

Not sure if it will solve your problem or not, and it's not very much encouraged to use in production. But you can definitely give it a try to see how it comes up!

Sign up to request clarification or add additional context in comments.

2 Comments

After trying , I will let you know . Thanks for answer .
Glad that it helped!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.