cURL is unable to use client certificate , in local server(cURL 无法在本地服务器中使用客户端证书)
问题描述
我使用 XAMPP 设置了本地服务器.我有两个 PHP 脚本,一个发送者和一个接收者.我正在尝试使用 HTTP over SSL (HTTPS) 将 XML 文件从发送方发送到接收方.
I set up a local server using XAMPP. I have two PHP scripts , a sender and a receiver. I am trying to send an XML file from the sender to the receiver using HTTP over SSL (HTTPS).
我创建了一个自签名证书,配置了 XAMPP,并且我在我的发件人上使用了这个代码:
I created a self signed certificate, configured XAMPP, and I am using this code on my sender :
<?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_SSLVERSION,3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd().'ipm.crt');
curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'ipm.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD,'pass');
//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.
?>
但是我总是收到此错误:Curl 错误:无法使用客户端证书(未找到密钥或密码错误?)
However i always get this error : Curl error: unable to use client certificate (no key found or wrong pass phrase?)
我可能会做错什么?密码是pass
这个词.
What can i possibly do wrong? The passphrase IS the word pass
.
我通过以下方式创建了我的 .crt:
I created my .crt 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
我不想将 SSL_VERIFYPEER
和 SSL_VERIFYHOST
设置为 false.
I don't want to put the SSL_VERIFYPEER
and SSL_VERIFYHOST
to false.
推荐答案
尝试像这样交换文件:
curl_setopt($ch, CURLOPT_CAINFO, getcwd().'ipm.pem');
curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'ipm.crt');
我怀疑你把它们弄错了.
I suspect you have them the wrong way round.
这篇关于cURL 无法在本地服务器中使用客户端证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cURL 无法在本地服务器中使用客户端证书
基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01