Página 1 de 1

Libcurl - CURL_DEFAULT_PROTOCOL

Publicado: Vie Oct 30, 2020 7:33 pm
por ricardo arraes
Hey everybody!

First of all, this official forum is great! congratulations to the developer(os developers), thank you for all the effort in making our community bigger and stronger!

Well, I'm having some trouble with the libcurl, guys...

I'm trying to add a reCAPTCHA checkbox in my login page, and in reCAPTCHA's documentation it's required to use HTTPS as the default protocol...
So I first I decided to test it on postman and convert the request into code ( C - libcurl), that's the result:

Código: Seleccionar todo

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
  curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify?secret=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe&response=03AGdBq26ZH0xDDgpzMEBr_u910XhZdjG6LfL796y9x2aOUIBbzNNPDho3SqxsVkn2-8gsKGq4HOBf3Ef0UEa0w4zDw_Ic0z-QHP-d9SFgklfsCsgl1E-GRzNWHR_vT_W0RkVamvVwJ0_a7yjiCpnM_qbqDDYK7Z_tXK_rzem7lQ6E9zF_duLMLbECB8J7dQ4p3rz2je81T1dhBGQqBJZuiXlfYsWxdem7rIAhydCiHm-1qZa8S50BEImBW3Pl5QRaLLhac4PX1_5_cI_EZ_q820hRt9hD71BnR5V6QNDCYDAt0mPrPe1rLowmrM772LmzQ8tRMyxukEdtNEPSwohQ1K3HcUKltM80ThRFrAQDkw5MwPDkYb5xwXckUFgK1zottFdiiUR5qDpxCyd9TjFhMo48srSaWco1xW7GgketOQcTga2RzDP1aZOcS3aYPdyKNZ0jDqCqFB8H3MSHMeM9yw10pe8Hfoj3fA");
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
  struct curl_slist *headers = NULL;
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  const char *data = "";
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
  res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
As you can see it's pure C code, so I had to translate it to Harbour code like that:

Código: Seleccionar todo

curl_global_init()

  if ! empty( hCurl := curl_easy_init() )   
    
    curl_easy_setopt(hCurl, HB_CURLOPT_CUSTOMREQUEST, cHttp)
    curl_easy_setopt(hCurl, HB_CURLOPT_URL, cUrl+"?"+cUrlFields)
    curl_easy_setopt(hCurl, HB_CURLOPT_FOLLOWLOCATION, 1)
    curl_easy_setopt(hCurl, HB_CURLOPT_PROTOCOLS,HB_CURLPROTO_HTTPS)
    //curl_easy_setopt(hCurl, HB_CURLOPT_DEFAULT_PROTOCOL, "https")
    curl_easy_setopt(hCurl, HB_CURLOPT_HTTPHEADER, NIL)
    curl_easy_setopt(hCurl, HB_CURLOPT_POSTFIELDS, "")

    curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
    
    IF (nret:=curl_easy_perform( hCurl )) == 0
        uValue = curl_easy_dl_buff_get( hCurl )
    ENDIF

  ENDIF
  
  curl_global_cleanup()   
The problem here is that there's no equivalent to CURLOPT_DEFAULT_PROTOCOL in hbcurl.ch, I already tried HB_CURLOPT_DEFAULT_PROTOCOL as you can see and many other ways, but it didn't work... does anybody has some suggestion?

Re: Libcurl - CURL_DEFAULT_PROTOCOL

Publicado: Vie Oct 30, 2020 7:42 pm
por ricardo arraes
By the way...

this is my curl version:

ibcurl/7.70.0 OpenSSL/1.1.1g (Schannel) zlib/1.2.11 brotli/1.0.7 WinIDN libssh2/1.9.0 nghttp2/1.40.0

Re: Libcurl - CURL_DEFAULT_PROTOCOL

Publicado: Vie Oct 30, 2020 10:36 pm
por Cristobal
Hello
Not use

Código: Seleccionar todo

curl_easy_setopt(hCurl, HB_CURLOPT_PROTOCOLS,HB_CURLPROTO_HTTPS)
Try with

Código: Seleccionar todo

//         curl_easy_setopt( oCurl, HB_CURLOPT_URL, cUrl )
         //
         curl_easy_setopt( oCurl, HB_CURLOPT_SSL_VERIFYPEER, 0 )  
         curl_easy_setopt( oCurl, HB_CURLOPT_SSL_VERIFYHOST, 0 ) 
         curl_easy_setopt( oCurl, HB_CURLOPT_FAILONERROR, 1 ) 
         //
         curl_easy_setopt( oCurl, HB_CURLOPT_USE_SSL, 0 )
         curl_easy_setopt( oCurl, HB_CURLOPT_RETURNTRANSFER, 1 )

Re: Libcurl - CURL_DEFAULT_PROTOCOL

Publicado: Vie Oct 30, 2020 11:53 pm
por ricardo arraes
Thank you for the answer, Cristobal!

Ok, I got it, you are disabling the verification over the peer and host, but is it safe? In the libcurl documentation they make it clear that if we disable theses verifications anyone can intercept our package...

But, I already tried what you are saying and it worked, I'm just a little bit worried about the security, you know? My goal here is actually use HTTPS as the default protocol...

Re: Libcurl - CURL_DEFAULT_PROTOCOL

Publicado: Sab Oct 31, 2020 12:38 am
por Cristobal
Try with

Código: Seleccionar todo

curl_easy_setopt( oCurl, HB_CURLOPT_USE_SSL, 1 )
But, please, read this
https://stackoverflow.com/questions/637 ... -read-file

Re: Libcurl - CURL_DEFAULT_PROTOCOL

Publicado: Sab Oct 31, 2020 1:31 am
por ricardo arraes
Thank you Cristobal!
I'll read and try it!