[英]libcurl: curl_easy_perform fails with CURLE_SSL_CACERT_BADFILE after some time
我在我的 C++ 應用程序中使用 libcurl 7.26.0 通過 https 協議與服務器通信。 它工作正常,但大約 20 分鍾后連接失敗: curl_easy_perform
返回CURLE_SSL_CACERT_BADFILE
。 我使會話的curl_easy_cleanup
然后以相同的方式成功初始化它,但在curl_easy_perform
它失敗並出現相同的錯誤。 只有重新啟動應用程序才有幫助。 我已經檢查過 *.pem 文件存在於文件系統中,並且應用程序的訪問權限在其運行過程中沒有改變。
我正在使用 libcurl 7.26.0、Windows 7 x86、MSVC 2005。
任何幫助將不勝感激。
UPD:問題僅重現發布模式。
我正在使用 cURL 日志記錄。 它以這種方式打開: curl_easy_setopt(m_curl_session, CURLOPT_DEBUGFUNCTION, curl_debug_trace)
在函數 curl_debug_trace 的開頭,日志文件由fopen
,最后使用fclose
關閉。 在發布模式下由於某些原因它不會關閉文件並且進程運行到打開文件的限制並且無法打開 cacert 文件。
解決方案是打開日志文件一次並保持打開狀態,直到程序運行。
if (curl)
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_easy_setopt(curl, CURLOPT_CAINFO, certificate_file_path);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlErrorBuffer);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://ap....");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, ss.str().c_str());
...
}
我嘗試了以下方法:
curl-ca-bundle.crt
curl-ca-bundle-my-site.crt
curl-ca-bundle.pem
curl-ca-bundle-my-site.pem
ca-mysite.crt
ca-mysite.pem
但是:CURLE_SSL_CACERT_BADFILE...
路徑:/Users/user/Documents/Test test/CA/ca-any-version.pem/crt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.