卷曲 - 无法使用p12证书连接 [英] Curl - cannot connect using p12 certificate

查看:271
本文介绍了卷曲 - 无法使用p12证书连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 Curl 收集一些数据,连接到一些外部公司提供的服务。除了地址本身,他们还发送了 p12 证书文件,用于建立连接。

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 使用它,我得到以下错误:

When I'm trying to use it with curl, I get following error:

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

和php卷曲。没有更改。

So far I've tried updating curl and php-curl. Nothing changed.

我的代码:

...
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).

推荐答案

找到解决方案。

最简单的方法是从 .p12 中提取 .pem 档案。

Easiest way to do this is to extract .pem key and certificate from .p12 file.

例如(在 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.

现在,使用它:

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 文件。

这篇关于卷曲 - 无法使用p12证书连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆