【问题标题】:simplereenroll for EST client using libCurl使用 libCurl 的 EST 客户端的 simpleeenroll
【发布时间】:2021-02-11 19:23:54
【问题描述】:

我正在尝试使用 libcurl 在 C 中开发一个 EST 客户端程序,以执行 simpleenroll 和 simpleeenroll。到目前为止,我能够使用 ./well-known/est/simpleenroll. 检索证书,但我在执行 ./well-known/est/simplereenroll 时遇到了问题

url = self.url_prefix + '/simplereenroll'
        auth = (self.username, self.password)
        headers = {'Content-Type': 'application/pkcs10'}
        content = est.request.post(url, csr, auth=auth, headers=headers,
            verify=self.implicit_trust_anchor_cert_path,
            cert=cert)
        pem = self.pkcs7_to_pem(content)

我指的是这个 python 代码,我可以在其中看到证书被传递以进行更简单的操作。我不知道如何使用 libcurl 来实现。

下面提到的是我用来执行 simpleenroll 的部分 libcurl 代码。

/*SIMPLEENROLL
 *
 */

if (res = curl_easy_setopt(curl,CURLOPT_URL,"https://localhost:4443/.well-known/est/simpleenroll")!=CURLE_OK)
    {
        fprintf(stderr,"curl_easy_setopt() failed: %s\n",curl_easy_strerror(res));
        return 1;
    }
    struct curl_slist* slist = NULL;
    slist = curl_slist_append(slist, "Content-Type: application/pkcs10");
    curl_easy_setopt(curl,CURLOPT_USERPWD,"estuser:estpwd")
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, CSR); 
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, CSR_LEN); 
    if((res = curl_easy_perform(curl))!=CURLE_OK)
    {
        fprintf(stderr,"curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
        return 1;       
    }

以上代码将从服务器返回一个客户端证书。现在我需要在需要提供此证书的地方执行 simpleeenroll。

【问题讨论】:

    标签: c linux security curl libcurl


    【解决方案1】:
    curl_easy_setopt(curl, CURLOPT_SSLKEY, client_key);
    curl_easy_setopt(curl, CURLOPT_SSLCERT, client_cert);
    curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
    

    【讨论】:

    • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助、质量更好,并且更有可能吸引投票。
    猜你喜欢
    • 1970-01-01
    • 2011-12-10
    • 1970-01-01
    • 2011-01-16
    • 2011-10-13
    • 2014-07-15
    • 2011-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多