【发布时间】: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