首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >cURL无法在本地服务器中使用客户端证书

cURL无法在本地服务器中使用客户端证书
EN

Stack Overflow用户
提问于 2013-01-23 07:58:12
回答 2查看 10K关注 0票数 2

我使用XAMPP设置了一个本地服务器。我有两个PHP脚本,一个发送者和一个接收者。我正在尝试使用HTTP over SSL (HTTPS)将XML文件从发送方发送到接收方。

我创建了一个自签名证书,配置了XAMPP,并且在我的发送者上使用了以下代码:

代码语言:javascript
复制
<?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 error: unable to use client certificate (no key found or wrong pass phrase?)

我还能做错什么呢?密码短语是单词pass

我通过执行以下操作创建了.crt:

代码语言:javascript
复制
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_VERIFYPEERSSL_VERIFYHOST设置为false。

EN

回答 2

Stack Overflow用户

发布于 2014-08-01 22:24:18

尝试交换文件,如下所示:

代码语言:javascript
复制
curl_setopt($ch, CURLOPT_CAINFO, getcwd().'ipm.pem');
curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'ipm.crt');

我怀疑你把他们弄错了。

票数 1
EN

Stack Overflow用户

发布于 2013-01-23 08:10:52

密钥必须是文件名,而不是密码。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14470225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档