我想在c++中使用libcurl和openssl进行https测试。我有以下代码:
curl_easy_setopt(mEasyHandle, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(mEasyHandle, CURLOPT_SSL_VERIFYHOST, 2L);
result = curl_easy_setopt(mEasyHandle, CURLOPT_CAINFO , "ca.pem");
我有一个监听192.168.0.101:4443
的Windows服务器。当从Visual Studio运行程序时,证书验证工作,但在Linux上我得到错误 server certificate verification failed. CAfile: ca.pem CRLfile: none
。
在ca.pem
中,我已经将生成的内容放在服务器的证书中(在windows上测试工作,在Linux上不)。
* Trying 192.168.0.101...
* Connected to 192.168.0.101 (192.168.0.101) port 4443 (#0)
* found 1 certificates in ca.pem
* server certificate verification failed. CAfile: ca.pem CRLfile: none
* Closing connection 0
更新:
我有一个文件夹/etc/ssl/certs
,其中包含很多ca证书文件。我将ca.pem
复制到/etc/ssl/certs
并运行 update-ca-certificates
,产生输出:
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d....done.
我已经解决了这个问题。实际上是一个证书问题。代码可以工作,但是机器上的时间戳是在生成证书之前。