[ZendTo] google, recaptcha, certificate verification error

Kyle Dippery kyle.dippery at uky.edu
Thu Oct 13 15:08:00 BST 2016

A few days ago I upgraded ports on the FreeBSD (9.3) system I have 
ZendTo (4.12-5) on.  Then I started getting errors when I tried to pick 
up files.  The log lines from apache:

     [Mon Oct 10 14:52:36 2016] [error] [client] PHP 
Warning:  fsockopen(): SSL operation failed with code 1. OpenSSL Error 
routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in 
/usr/local/www/apache22/data/ZendTo-4.12-5/www/recaptchalib.php on line 110
     [Mon Oct 10 14:52:36 2016] [error] [client] PHP 
Warning:  fsockopen(): Failed to enable crypto in 
/usr/local/www/apache22/data/ZendTo-4.12-5/www/recaptchalib.php on line 110
     [Mon Oct 10 14:52:36 2016] [error] [client] PHP 
Warning:  fsockopen(): unable to connect to ssl://www.google.com:443 
(Unknown error) in 
/usr/local/www/apache22/data/ZendTo-4.12-5/www/recaptchalib.php on line 110

It's possible that the new certificate bundle (one of the ports that got 
upgraded) left out Google's certificate, but I put the pre-upgrade 
bundle back in place and got the same errors.  So, apparently, something 
in the port upgrade turned on PHP's certificate verification, and it's 
failing on Google's certificate. I've poked around and found that by 
replacing fsockopen() in recaptchalib.php line 110 with 
stream_socket_client(), along with some appropriate stream context 
options (lots of new concepts for me, yesterday), I could get it to work 

     110                 //$fs = fsockopen("ssl://" . $hostname, 443, 
$errno, $errstr, 10);
     111                 /* new stuff 2016-10-10 */
     112                 $kd_contextOptions = array(
     113                         'ssl' => array(
     114                                 'verify_peer' => false,
     115                                 'verify_name' => false,
     116                                 'allow_self_signed' => true,
     117                         )
     118                 );
     119                 $kd_context = 
     120                 $fs = 
stream_socket_client("ssl://{$hostname}:443", $errno, $errstr, 20, 
     121                 /* end new stuff 2016-10-10 */
     122                 if( false == $fs ) {
     123                         // fsockopen failed
     124                 } else {
     125                         fwrite($fs, $http_request);
     126                         while (!feof($fs)) {
     127                                 $result .= fgets($fs, 4096);
     128                         }
     130                         $result = explode("\r\n\r\n", $result, 2);
     131                         $result = $result[1];
     132                 }
     133         }
     135         // Return the result.
     136         return $result;

but it was a bit of a fight getting there.

I don't know if this is a bug report, an FYI, or just a war story, but 
there it is.  It seems like, if I've run into this, someone else has, 
too, or will, so there's how I fixed it.  Has anyone else seen this?  Is 
there a better way around it?



(seems to imply that Google's certificate has been failing verification 
for a while)

https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting (in the "PHP 
5.6 certificate verification failure", for the stream context options)

(stream_socket_client notes; see down in the comments for using 'ssl://' 
instead of 'tcp://'; with 'tcp://' I successfully connected but never 
got any response, so all of my recaptcha tests failed)

Kyle Dippery
Engineering Computing Services
219 RMB

More information about the ZendTo mailing list