如何使用XAMPP将自签名证书用于使用cURL的HTTPS请求? [英] How to use a self signed certificate with XAMPP for HTTPS requests using cURL?
问题描述
我安装了XAMPP,我需要测试一些HTTPS请求。首先,我尝试配置XAMPP,以便我可以使用HTTPS请求。
I installed XAMPP and I need to test some HTTPS requests. First of all i tried to configure XAMPP so I can use the HTTPS requests.
这就是我所做的:
1)在php.ini文件中,我取消注释 openssl模块
。
1) In the php.ini file , I uncommented the openssl module
.
2)在httpd中.conf文件,我取消注释 LoadModule ssl_module modules / mod_ssl.so
2) In the httpd.conf file , I uncommented the LoadModule ssl_module modules/mod_ssl.so
3)在httpd-ssl中。 conf文件,我重定向
3) In the httpd-ssl.conf file , I redirected
SSLCertificateFileconf / ssl.crt / ipm.crt
和
SSLCertificateKeyFileconf / ssl.key / ipm.key
到我的.crt和.key文件。
SSLCertificateKeyFile "conf/ssl.key/ipm.key
" to my .crt and .key files.
4)我把我的ipm.crt和ipm.key文件放在apache文件夹 ssl.crt
和 XAMPP中的ssl.key
。
4) I put my ipm.crt and ipm.key files in the apache folders ssl.crt
and ssl.key
inside XAMPP.
5)我创建了自签名证书:
5) I created my self signed certificate by doing :
openssl req -config openssl.cnf -new -out ipm.csr -keyout ipm.pem
openssl rsa -in ipm.pem -out ipm.key
openssl x509 -in ipm.csr -out ipm.crt -req -signkey ipm.key -days 365
现在我我正在使用脚本发送XML文件。我正在使用cURL,我的代码是:
Now I am using a script to send an XML file. I am using cURL and my code is :
<?php
/*
* XML Sender/Client.
*/
// Get our XML. You can declare it here or even load a file.
$xml = file_get_contents("data.xml");
// We send XML via CURL using POST with a http header of text/xml.
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd().'/cert/ipm.crt');
curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'/cert/ipm.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD,'password');
//I use this line only for debugging through fiddler. Must delete after done with debugging.
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://ipv4.fiddler/iPM/receiver.php");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, 'https://ipv4.fiddler/iPM/receiver.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
echo "Result = ".$ch_result;
echo 'Curl error: ' . curl_error($ch);
curl_close($ch);
// Print CURL result.
?>
但我收到此错误:卷曲错误:无法使用客户端证书(没有找到密钥或错误的密码短语?)
但是当我创建证书时,我确实把密码设为:密码
However when I created my certificate I did put as a password the phrase: password
关于此事的任何想法?
推荐答案
我相信你还需要指定 CURLOPT_SSLKEYPASSWD
:
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'password');
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, 'password');
这篇关于如何使用XAMPP将自签名证书用于使用cURL的HTTPS请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!