Solution to : OpenSSL Error messages: SSL routines:SSL3_GET_SERVER_CERTIFICATE

I have spent over a day to solve the issue. Hence I think it is worth posting it here for everyone’s benefit.

Problem :

I am using http://www.question2answer.org/ software and standard plugin there for captcha that uses google recaptcha. After update of software, I got the error below. I have setup autoSSL in Cpanel in the past that applies to this website as well.  Below is the error that I keep getting.

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /qa/qa-plugin/recaptcha-captcha/recaptchalib.php on line 128

Warning: file_get_contents(): Failed to enable crypto in /qa/qa-plugin/recaptcha-captcha/recaptchalib.php on line 128

Warning: file_get_contents( https://www.google.com/recaptcha/api/siteverify?secret=abc6LcMwv8SAAAAAN9QOkIlVKRQZzHS3DeZ8ZLxwxxcdsd-cs&response=03AOmkcwJV_JkhxK8hGJTIVKEDcPrNH5Y0wLwndp7v20Ipqd4HMO21LWHSyPsLFsdfdsfsdsdfsdA6FZ1LiFJZpl6-CmppsTAWc8Qzft_RXLvlzunzQtZWNDp0Kw8T-drMvHiOZf909v4ScysiPmaMrxkq_SSlJaOE_Q6sdfsdfdsfdsh5X7xLqvoFDFbV16BJBTkJ5Pot5ZDwmSGZSD_0pygTdEzh8j-tGuSpZLSDVJmQ7Xq6HR70Dd2idtKz_gfcIAZQisdfsdfdsfJHH1LyY3FAG_x9zHemy3tXF6oE7rWuBZ8JoHehkWhYYChe-cBbdSX1ZqPioNNaSvkREbooI7esdfsdfd3JkynEKlqnUBl3t__qpDMu&remoteip=12.102.238.217&version=php_1.1.2): failed to open stream: operation failed in /qa/qa-plugin/recaptcha-captcha/recaptchalib.php on line 128

 

I went to line 128 and this is what I see there. I see this line.

return file_get_contents(self::SITE_VERIFY_URL . $params->

The entire function for this before change is like below. The error line below in orange.

/**
 * Sends GET requests to the reCAPTCHA service.
 */
class ReCaptchaGetRequestMethod implements ReCaptchaRequestMethod{

const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify?';

/**
 * Submit the request with the specified parameters.
 *
 * @param ReCaptchaRequestParameters $params Request parameters
 * @return string Body of the reCAPTCHA response
 */
 public function submit(ReCaptchaRequestParameters $params){
 return file_get_contents(self::SITE_VERIFY_URL . $params->toQueryString());
 }
}

Why is this error occurring ? Solution ?

The error is occuring because of the usage of file_get_contents that has issues with SSL in PHP and it has to be replaced with CURL based commands in PHP.  I paid about $15 USD to get the solution from a freelancer. It took 2 minutes to solve it.  Here is the solution

Solution for the above SSL Error fixed with CURL

You will need to replace the line with below commands. Need to declare a variable and move the one inside the file_get_contents to that .The updated code. You can compare the above before and below after to get an idea.

/**
 * Sends GET requests to the reCAPTCHA service.
 */
class ReCaptchaGetRequestMethod implements ReCaptchaRequestMethod{

const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify?';

/**
 * Submit the request with the specified parameters.
 *
 * @param ReCaptchaRequestParameters $params Request parameters
 * @return string Body of the reCAPTCHA response
 */
 public function submit(ReCaptchaRequestParameters $params){

$url = self::SITE_VERIFY_URL . $params->toQueryString();
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 $data = curl_exec($ch);
 curl_close($ch);
 return $data;

}
}

There was other solution suggested  like adding certificate in php.ini and it did not work. I had to remove it. The above solution works well.

Did you face the same error ?  What did you do ?

1 Comment

Leave a Comment