我正在尝试使用Curl连接到某些外部公司提供的服务来收集一些数据.除了解决问题之外,他们还向我发送了p12建立连接所需的证书文件.
当我尝试使用它时curl,我收到以下错误:
#58: not supported file type 'P12' for certificate
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经尝试更新curl和php-curl.没有改变.
我的代码:
...
curl_setopt($ch, CURLOPT_SSLCERT, 'cert_path');
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'P12');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'my_pass');
...
Run Code Online (Sandbox Code Playgroud)
有趣的是,这段代码适用于我们的生产环境,而它不适用于我的本地机器(Linux Mint 16).
ex3*_*x3v 28
找到了解决方案.
最简单的方法是.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
Run Code Online (Sandbox Code Playgroud)
将在当前目录中创建密钥/证书对.
现在,使用它:
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');
Run Code Online (Sandbox Code Playgroud)
pass来自.p12文件的密码在哪里.
| 归档时间: |
|
| 查看次数: |
19241 次 |
| 最近记录: |