卷曲 - 无法使用p12证书连接

时间:2014-06-23 10:10:03

标签: 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)。

1 个答案:

答案 0 :(得分:25)

找到了解决方案。

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

例如(在linux上测试):

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

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

现在,使用它:

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文件的密码。

相关问题