curl-and-php
HTTPS + Certificate
Date: Tue, 23 Sep 2003 16:03:16 +0200
Hello,
I want to convert cURL command line into PHP program.
My cURL command line is :
curl --cacert CAROOT.pem --cert MYCERT.pem --key MYKEY.pem
https://thewebsite/
the result of this command line is ok : I have the right page.
I try to transform this command line in PHP :
$website = "https://thewebsite/";
$url = $website.$_SERVER["PATH_INFO"];
$MyCert = "MYCERT.pem"; // my private certificate
$keyfile = "MYKEY.pem"; // your private key file
$certroot = "CAROOT.pem"; // root certificate
$certsite = "CAHOMO.pem"; // website certificate
$passwd = "0b14b67f"; // my password string
$file = "./result.html";
$ch = curl_init ($url);
$fp = fopen ($file, "w") or die("Unable to open $file for writing.\n");
if (!$ch) {
die ("Couldn't Initialize cURL handle\n");
}
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_CAINFO, $certsite);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $MyCert);
curl_setopt($ch, CURLOPT_SSLKEY, $keyfile);
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $passwd);
$code = curl_exec ($ch);
if ($code != CURLE_OK) {
die ("cURL error: " . curl_error ($ch) . "\n");
}
echo "<pre>";
print_r(curl_getinfo($ch));
echo "\n\ncURL error number:" .curl_errno($ch);
echo "\n\ncURL error:" . curl_error($ch);
echo "</pre>";
curl_close ($ch);
fclose ($fp);
?>
the result is :
Array
(
[url] => https://thewebsite/
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0.013
[connect_time] => 0.037
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0
)
cURL error number:58
cURL error:unable to set certificate file (wrong password?)
Someone can help me, i don't see where is my error... :-(
Thank you for your answer !
-- Frédéric ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sfReceived on 2003-09-23