[英]Using LibCurl in C++ and self signed certificate
我在使用 libcurl 和 ssl 時遇到問題。
如果我嘗試使用以下 curl 命令連接到我的站點:
curl -q --cert client-2048.crt --key client-2048.key https://****** -d "username= &password= " -H "X-Application: curlCommandLineTest"
一切正常(順便說一下,證書是自簽名的)
我怎樣才能做同樣的使用 libcurl?
我試圖遵循 libcurl ssl 示例,但證書和私鑰具有不同的擴展名,所以我不知道從哪里開始。
到目前為止,我嘗試了以下(以及許多其他組合):
static const char *pCertFile = "client-2048.crt";
static const char *pCACertFile = "client-2048.pem";
static const char *pKeyName = "client-2048.key";
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
/* what call to write: */
curl_easy_setopt(curl, CURLOPT_URL, "https://*****");
curl_easy_setopt(curl, CURLOPT_HEADERDATA, headerfile);
/* cert is stored PEM coded in file... */
/* since PEM is default, we needn't set it for PEM */
curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
/* set the cert for client authentication */
curl_easy_setopt(curl, CURLOPT_SSLCERT, pCertFile);
/* set the private key (file or ID in engine) */
curl_easy_setopt(curl, CURLOPT_SSLKEY, pKeyName);
/* disconnect if we can't validate server's cert */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* we are done... */
} while (0);
/* always cleanup */
curl_easy_cleanup(curl);
return 0;
但我收到消息:
curl_easy_perform() failed: Peer certificate cannot be authenticated with
given CA certificates
那么反映成功調用的 Libcurl 代碼是什么?
謝謝
自簽名證書:
curl_easy_setopt(卷曲,CURLOPT_SSL_VERIFYPEER,0L);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.