libcurl支持https SERVER对CLIENT认证
2016-05-04 08:55 flyfish163 阅读(2828) 评论(0) 编辑 收藏 举报
Easy curl增加以下代码
/*curl_easy_setopt(ptCurlItem->curl, CURLOPT_CAPATH, "/etc/pki/tls/private");*/
curl_easy_setopt(ptCurlItem->curl, CURLOPT_SSLCERT, "ca.crt");
curl_easy_setopt(ptCurlItem->curl, CURLOPT_SSLCERTPASSWD, "changeit");
curl_easy_setopt(ptCurlItem->curl, CURLOPT_SSLCERTTYPE, "PEM");
curl_easy_setopt(ptCurlItem->curl, CURLOPT_SSLKEY, "ca.key");
curl_easy_setopt(ptCurlItem->curl, CURLOPT_SSLKEYPASSWD, "changeit");
curl_easy_setopt(ptCurlItem->curl, CURLOPT_SSLKEYTYPE, "PEM");
注
1) 证书文件位置
ca.crt,ca.key存放在可执行文件相同目录下,否则提示文件打开失败
error 58, could not load PEM client certificate, OpenSSL error error:02001002:system library:fopen:No such file or directory, (no key found, wrong pass phrase, or wrong file format?)
2)需要使用自签名证书文件ca.crt作为客户端证书文件
3)需要同时提供ca.key文件,否则会提示
error 58, unable to set private key file: 'ca.crt' type PEM
附注:自签名证书文件制作命令
openssl genrsa -out ca.key 1024 ##生成证书私钥
openssl req -new -key ca.key -out ca.csr ##生成证书
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt ##生成自签名证书