php - Curl - 无法使用 p12 证书连接

标签 php curl ssl

我正在尝试使用 Curl 收集一些数据,连接到一些外部公司提供的服务。他们除了解决自身问题外,还向我发送了建立连接所需的 p12 证书文件。

当我尝试将它与 curl 一起使用时,出现以下错误:

#58: not supported file type 'P12' for certificate

到目前为止,我已经尝试更新 curl 和 php-curl。什么都没有改变。

我的代码:

...
curl_setopt($ch, CURLOPT_SSLCERT, 'cert_path');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'P12');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'my_pass');
...

有趣的是,这段代码可以在我们的生产环境中运行,但在我的本地机器 (Linux Mint 16) 上却无法运行。

最佳答案

找到解决方案。

最简单的方法是从 .p12 文件中提取 .pem key 和证书。

例如(在linux上测试):

openssl pkcs12 -in file.p12 -out file.key.pem -nocerts -nodes
openssl pkcs12 -in file.p12 -out file.crt.pem -clcerts -nokeys

将在当前目录中创建 key /证书对。

现在,使用它:

curl_setopt($ch, CURLOPT_SSLCERT, 'file.crt.pem');
curl_setopt($ch, CURLOPT_SSLKEY, 'file.key.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'pass');
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, 'pass');

其中 pass 是来自 .p12 文件的密码。

关于php - Curl - 无法使用 p12 证书连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24363317/

相关文章:

curl keep-alive 在收到错误 404 时不起作用

http - OpenStack Swift 无法使用批量操作自动提取 tar 文件

curl - 如何使用 cURL -XGET -d' {"query": "aaa"}' 之类的正文触发 Postman GET 请求

java - 调用 web 服务 : javax.net.ssl.SSLException:收到致命警报:protocol_version

ssl - NSURLSession 的不受信任证书错误不适用于 iOS 10 中的自定义协议(protocol)

php - Web 应用程序基准测试

php - 了解 Twitter API 的 "Cursor"参数

php - 将数组样式数据保存到mysql数据库(JSON)

amazon-web-services - 让我们在 AWS Elastic Beanstalk 上加密

c# - 有没有办法拥有一个不会被继承的公共(public)方法?