SSLHandshakeException for captcha v2

6,952 views
Skip to first unread message

tejas2...@gmail.com

unread,
Jul 23, 2015, 12:01:32 PM7/23/15
to reCAPTCHA
getting SSL handshake exception while contacting google server for verifying response.

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



            URL verifyURL = new URL(null , "https://www.google.com/recaptcha/api/siteverify", new sun.net.www.protocol.https.Handler());

            HttpsURLConnection connection = (HttpsURLConnection) verifyURL.openConnection();
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setInstanceFollowRedirects(true);
            connection.setUseCaches(false);
            connection.setReadTimeout(readTimeout_);
            connection.setConnectTimeout(connectionTimeout_);
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded; charset=US-ASCII");
            connection.setRequestProperty("Content-Length",
                    Integer.toString(post.length));
            
            // do the post
            OutputStream out = connection.getOutputStream();  // <-- This line throws exception. 
            out.write(post);
            out.flush();

any suggetions guys ?

Amit Sanon

unread,
Aug 5, 2015, 2:10:34 AM8/5/15
to reCAPTCHA
I am facing the similar problem. Have not found the solution as yet...

Tejas Rajpura

unread,
Aug 13, 2015, 2:17:56 AM8/13/15
to reca...@googlegroups.com
found the problem. 

issue was with the internet network we use. we have proxy in network. try using network without any proxy. it will work. 

if you want to use network then make necessary changes to network to allow captcha response url to pass through proxy.

Hope it helps.

Tejas

--
You received this message because you are subscribed to a topic in the Google Groups "reCAPTCHA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/recaptcha/xC3OWE5gdpU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to recaptcha+...@googlegroups.com.
To post to this group, send email to reca...@googlegroups.com.
Visit this group at http://groups.google.com/group/recaptcha.
For more options, visit https://groups.google.com/d/optout.

Sathyadas M. Thottoram

unread,
Mar 1, 2017, 10:46:32 PM3/1/17
to reCAPTCHA

This may be a little late, but will be useful for anyone facing similar issues.



In  order to resolve the SSL Handshake exception when using recaptcha, follow the below steps.

 

1.       Navigate to your JAVA\JRE\lib\security folder.

 

 

2.       Get the google certificate hierarchy from the internet using keytool as below and store it in a file called recaptcha.pem.

Note: You cannot use the browser directly as it is disabled in modern browsers.

 

JAVA_HOME\jre1.8.0_91\lib\security> keytool -printcert -rfc -sslserver www.google.com/recaptcha/api/siteverify > recaptcha.pem

  

3.       You can verify if the certificate is imported properly by issuing the type command.

JAVA_HOME\jre1.8.0_91\lib\security>type recaptcha.pem

 

4.       Import the downloaded certificate to your JRE certificate store using the command below:

JAVA_HOME\jre1.8.0_91\lib\security> keytool -importcert -file ./recaptcha.pem –keystore cacerts

When prompted for the keystore password, please enter “changeit”. It is the default password.

When prompted for Trust this Certification, type “Y”

 

 

The above steps will ensure that the certificate is imported in your JRE and enable SSL Handshake between the servers.

Reply all
Reply to author
Forward
0 new messages