【问题标题】:libcurl: curl_easy_perform fails with CURLE_SSL_CACERT_BADFILE after some timelibcurl:curl_easy_perform 在一段时间后因 CURLE_SSL_CACERT_BADFILE 失败
【发布时间】:2012-09-05 10:42:09
【问题描述】:

我在我的 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:问题仅重现发布模式。

【问题讨论】:

    标签: c++ visual-c++ curl https libcurl


    【解决方案1】:
    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

    【讨论】:

      【解决方案2】:

      我正在使用 cURL 日志记录。它是这样开启的: curl_easy_setopt(m_curl_session, CURLOPT_DEBUGFUNCTION, curl_debug_trace) 在函数 curl_debug_trace 的开头,日志文件由fopen 打开,最后使用fclose 关闭。在发布模式下由于某些原因它不会关闭文件并且进程运行到打开文件的限制并且无法打开 cacert 文件。

      解决方案是打开日志文件一次,直到程序运行为止。

      【讨论】:

      • --with-ca-path=/system/etc/security/cacerts to ./configure ??
      猜你喜欢
      • 2022-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多