I have a script that uses cURL to access a remote HTTPS server. It was working fine for a long time but apparently something has changed. I in this function the curl_exec call is returning false:
function fetchPage($url, $truncateCookieFile=TRUE, $verifySSL=TRUE) {
// create a new cURL resource
$ch = curl_init($url);
// set URL and other appropriate options
//curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return the results of the curl exec
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14');
if (!$verifySSL) {
/* this is added in v2 of this function */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}
/* because the remote site may use sessions, we need a cookie jar*/
$cookieFile = SERVER_PATH . DIRECTORY_SEPARATOR . 'cookies.txt';
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
/* grab URL and put it in $result */
$result = curl_exec($ch);
if ($result === false) {
throw new Exception('CURL failed to fetch page:' . curl_error($ch));
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code != 200) throw new Exception('CURL returned non-OK code:' . $code);
/* close cURL resource, and free up system resources */
curl_close($ch);
/* if $truncateCookieFile is true, blank the cookie file and eliminate any sessions */
if ($truncateCookieFile) {
if (!($fp = fopen($cookieFile, 'w'))) {
throw new Exception('Could not truncate cookie file');
}
fclose($fp);
}
/* return the result */
return $result;
}
As you might have noticed, I have written my function so you can ignore SSL problems but I'd rather fix the cert issue so that I can be sure my connection is encrypted properly and that all the certs check out as they should (or i fail because there's an imposter).
The exception that's getting thrown says CURL failed to fetch page:SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
I have googled this and found a page that seems pretty informative here:
http://curl.haxx.se/docs/sslcerts.html
However, I don't really follow what needs to be done. As I understand it, a given site hosting https requires a certificate. This certificate must be 'signed' by a certificate authority. This is where my understanding gets kinda fuzzy. Any given browser (or cURL or other means of accessing https) must compare the CA signature on a given cert to some bundle of 'trusted' CAs. Or something like that.
Basically, I am essentially at a loss as to how to proceed here. I'm guessing (I can visit that site using a browser and find out which certificate authority has signed the SSL cert for this troublesome remote server, but I'm not sure how to do that. I'm even less sure how to find out if that CA cert is valid. I'd really appreciate it if someone could walk me through this.