我使用下面的片段来设置客户端身份验证的证书和密钥。
curl_easy_setopt(curl,CURLOPT_SSLCERT,"clientCert.pem");
curl_easy_setopt(curl,CURLOPT_SSLCERTPASSWD,"changeit");
curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
curl_easy_setopt(curl,CURLOPT_SSLKEY,"privateKey.pem");
curl_easy_setopt(curl,CURLOPT_SSLKEYPASSWD,"changeit");
curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,"PEM");
该证书没有密码,我不知道为什么存在 SSLCERTPASSWD 选项,我只是提供了一个虚拟值。
当我在 Linux 上运行该程序时,我收到错误代码 58 和错误消息
无法设置私钥文件:“privateKey.pem”类型 PEM
但在 Windows 上我得到
无法使用客户端证书(未找到密钥或密码短语错误?)
似乎表明证书和密钥不匹配,但我不知道如何。我已使用 openssl 命令从 p12 文件中提取了证书和密钥。
我用来提取密钥的命令是
openssl.exe pkcs12 -in client.p12 -nocerts -out privateKey.pem
用于提取证书的命令是
openssl.exe pkcs12 -in client.p12 -nokeys -out clientCert.pem
已成功在浏览器中使用p12文件访问客户端认证url。
在我开枪自杀之前请帮忙。
编辑:
这是私钥和证书相互对应的证明:
[debugbld@nagara ~/curlm]$ openssl x509 -noout -modulus -in clientCert.pem | openssl md5
d7207cf82b771251471672dd54c59927
[debugbld@nagara ~/curlm]$ openssl rsa -noout -modulus -in privateKey.pem | openssl md5
Enter pass phrase for privateKey.pem:
d7207cf82b771251471672dd54c59927
那么为什么行不通呢?