libucrl无法检查服务器证书

问题描述 投票:0回答:1

我正在使用libcurl(在C中)登录到安全站点(https)。到目前为止,一切正常。从昨天开始,它无法登录。代码如下。

bool login(char *user, char *password)
{
    bool result = false;
    CURL * curl = NULL;
    char errbuf[CURL_ERROR_SIZE];
    char status_text[1024];
    CURLcode res;
    long resp_code = 0;
    int index;

    /* These fields should be collected from license file */
    char *user_field = "name";
    char *password_field = "pass";

    char *form_id_field = "form_id";
    char *form_id = "user_login";

    char *link = "https://example.com/user/login";

    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();
    if(curl == NULL) goto on_error;

    curl_easy_reset(curl);

    curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0");
    curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_callback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)NULL);

    curl_easy_setopt(curl, CURLOPT_URL, link);
    res = curl_easy_perform(curl);

    if(res == CURLE_OK)
    {
        curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1);
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_easy_setopt(curl, CURLOPT_REFERER, link);

        /* Data should be "name=user&pass=password&form_id=user-login" */
        index = sprintf(status_text, "%s=%s&%s=%s&%s=%s",
            user_field, user, password_field,
            password, form_id_field, form_id);

        *(status_text + index) = 0x0;

        resp_code = 0;
        res = CURLE_ABORTED_BY_CALLBACK;

        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, status_text);
        res = curl_easy_perform(curl);
        curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &resp_code);

        if((resp_code == 200) && (res != CURLE_ABORTED_BY_CALLBACK))
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }

on_error:
    if(curl)
    {
        curl_easy_cleanup(curl);
        curl_global_cleanup();
        curl_global_cleanup();
    }

    return result;
} 

执行curl_easy_perform时失败。 errbuf显示诸如“服务器证书验证失败。cafile/etc/ssl/certs/ca-certificates.crt crlfile none”之类的错误。我了解到/etc/ssl/certs/ca-certificates.crt文件有些问题,但我没有做任何更改。

这里可能是什么问题,解决此问题的任何提示,深表感谢。

ssl libcurl
1个回答
2
投票

它不是一个提示,而是一个答案,但我没有足够的代表意见。

自昨天起无法登录

这可能与Sectigo的旧版AddTrust外部CA Root证书已在2020年5月30日https://support.sectigo.com/articles/Knowledge/Sectigo-AddTrust-External-CA-Root-Expiring-May-30-2020到期的事实有关>

从上面的链接

您的站点的证书是从颁发或“中间” CA的“链”中颁发的,CA完成了返回这些受信任根证书的路径。

如果我正确理解了上面的陈述,AddTrust外部CA根证书可能是链中的证书之一,因此验证失败-至少对于某些客户端而言。

编辑

https://www.agwa.name/blog/post/fixing_the_addtrust_root_expiration对我也有用的是>

  1. 编辑/etc/ca-certificates.conf并在mozilla / AddTrust_External_Root.crt之前加上一个感叹号(!)
  2. 运行update-ca-certificates
© www.soinside.com 2019 - 2024. All rights reserved.