I am trying to run below example with libcurl
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL* curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
#ifdef SKIP_PEER_VERIFICATION
/*
* If you want to connect to a site who is not using a certificate that is
* signed by one of the certs in the CA bundle you have, you can skip the
* verification of the server's certificate. This makes the connection
* A LOT LESS SECURE.
*
* If you have a CA cert for the server stored someplace else than in the
* default bundle, then the CURLOPT_CAPATH option might come handy for
* you.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif
#ifdef SKIP_HOSTNAME_VERIFICATION
/*
* If the site you are connecting to uses a different host name that what
* they have mentioned in their server certificate's commonName (or
* subjectAltName) fields, libcurl refuses to connect. You can skip this
* check, but it makes the connection insecure.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif
/* cache the CA cert bundle in memory for a week */
auto resultThree = curl_easy_setopt(curl, CURLOPT_CA_CACHE_TIMEOUT, 604800L);
/* Perform the request, res gets the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %sn",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
but I am getting the response as CURLE_UNSUPPORTED_PROTOCOL
for curl_easy_perform
. It looks like it can not process https
response where as http
response for "https://example.com/"
is all good.
I referred to
Unsupported Protocol using Curl in C
curl -V
does show me https
and my cmakelist
does show below (in block code)
, so I am sure it is built with SSL Library
if(WIN32)
cmake_dependent_option(CURL_USE_SCHANNEL "Enable Windows native SSL/TLS" OFF CURL_ENABLE_SSL OFF)
option(CURL_WINDOWS_SSPI "Enable SSPI on Windows" ${CURL_USE_SCHANNEL})
endif()
Next I have referred to How to Download the SSL Certificate From a Website in Windows and manually downloaded the server certificate as cacert.crt
Then I am trying to use curl_easy_setopt(curl, CURLOPT_CAINFO, cacert);
as suggested in
Certificate Verification and CURLOPT_CAINFO
and accordingly my code looks like
curl = curl_easy_init();
auto cacert = "C:\GauravK\CPP_17\CURL_CPP\CURL_CPP\cacert.crt";
if (curl) {
auto resultOne = curl_easy_setopt(curl, CURLOPT_CAINFO, const_cast<char*> (cacert));
auto resultTwo = curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
/* cache the CA cert bundle in memory for a week */
auto resultThree = curl_easy_setopt(curl, CURLOPT_CA_CACHE_TIMEOUT, 604800L);
/* Perform the request, res gets the return code */
res = curl_easy_perform(curl);
resultOne
, resultTwo
and resultThree
are all CURLE_OK
, but my res
is still CURLE_UNSUPPORTED_PROTOCOL
. I even tried to define SKIP_PEER_VERIFICATION
and SKIP_HOSTNAME_VERIFICATION
but no luck.
Can someone help please?