php Curl - 无法使用 p12 证书连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24363317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Curl - cannot connect using p12 certificate
提问by ex3v
I'm trying to collect some data using Curl
, connecting to service that some external company provided. They, in addition to address itself, sent me p12
certificate file that is required to estabilish connection.
我正在尝试使用Curl
,连接到某些外部公司提供的服务来收集一些数据。除了地址本身,他们还向我发送了p12
建立连接所需的证书文件。
When I'm trying to use it with curl
, I get following error:
当我尝试将它与 一起使用时curl
,出现以下错误:
#58: not supported file type 'P12' for certificate
So far I've tried updating curl and php-curl. Nothing changed.
到目前为止,我已经尝试更新 curl 和 php-curl。没有改变。
My code:
我的代码:
...
curl_setopt($ch, CURLOPT_SSLCERT, 'cert_path');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'P12');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'my_pass');
...
Funny thing is that this code works on our production environment, while it doesn't work on my local machine (Linux Mint 16).
有趣的是,这段代码适用于我们的生产环境,而不适用于我的本地机器(Linux Mint 16)。
回答by ex3v
Found the solution.
找到了解决办法。
Easiest way to do this is to extract .pem
key and certificate from .p12
file.
最简单的方法是.pem
从.p12
文件中提取密钥和证书。
For example (tested on linux
):
例如(在 上测试linux
):
openssl pkcs12 -in file.p12 -out file.key.pem -nocerts -nodes
openssl pkcs12 -in file.p12 -out file.crt.pem -clcerts -nokeys
Will create key/cert pair in current directory.
将在当前目录中创建密钥/证书对。
Now, to use it:
现在,使用它:
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');
Where pass
is the password from .p12
file.
文件中pass
的密码在哪里.p12
。