HTTPS & Purebasic

Just starting out? Need help? Post your questions and find answers here.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

HTTPS & Purebasic

Post by Lunasole »

Hi, pure gentlemen ^^

Does anyone know any external HTTPS library with ability to access received server certificate info, and of course allowing to reject connection if don't like it? Need this for one stuff and will translate it to PB if not already.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
infratec
Always Here
Always Here
Posts: 6869
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HTTPS & Purebasic

Post by infratec »

curl :?:

If you enable verbose output you can get the informations of the certificate

Commandline example:
https://forum.ivorde.com/using-curl-to- ... 16141.html
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: HTTPS & Purebasic

Post by Lunasole »

infratec wrote:curl :?:
Thanks for info, I was found your bindings already while googled, but was not sure that curl allows this.
Will try it, hope one built-in to PB has all the stuff for cert info ^^
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: HTTPS & Purebasic

Post by Lunasole »

Unfortunally it hasn't :/
Well should build own or seek for someone else binaries.

Code: Select all

#CURLOPT_CERTINFO = 172
        
; working with static libcurl
InitNetwork()
IncludeFile "libcurl.pbi"
EnableExplicit

Procedure wrfu(*ptr,  size,  nmemb,  *stream)
  ProcedureReturn size * nmemb
EndProcedure

Procedure Main ()
  curl_global_init(#CURL_GLOBAL_DEFAULT);
  Protected CURL = curl_easy_init()
	Protected res
	;Debug PeekS(curl_version(), -1, #PB_Ascii)

  If(curl)
    curl_easy_setopt(curl, #CURLOPT_URL, "https://www.example.com/")
 
    curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @wrfu())
 
    curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
    curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
 
    curl_easy_setopt(curl, #CURLOPT_VERBOSE, 0)
    
    Debug curl_easy_setopt(curl, #CURLOPT_CERTINFO, 1) ; = CURLE_NOT_BUILT_IN
 
    res = curl_easy_perform(curl)
 
;     If Not res
;       union {
;         struct curl_slist    *to_info;
;         struct curl_certinfo *to_certinfo;
;       } ptr;
;  
;       ptr.to_info = NULL;
;  
;       res = curl_easy_getinfo(curl, #CURLINFO_CERTINFO, &ptr.to_info);
;  
;       If Not res And ptr.to_info)
;         int i;
;  
;         printf("%d certs!\n", ptr.to_certinfo->num_of_certs);
;  
;         For(i = 0; i < ptr.to_certinfo->num_of_certs; i++) {
;           struct curl_slist *slist;
;  
;           For(slist = ptr.to_certinfo->certinfo[i]; slist; slist = slist->next)
;             printf("%s\n", slist->Data);
;  
;         }
;       EndIf
;  
;     EndIf
 
    curl_easy_cleanup(curl);
  EndIf
 
  curl_global_cleanup()
 
  ProcedureReturn 0
EndProcedure

Main()
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
firace
Addict
Addict
Posts: 902
Joined: Wed Nov 09, 2011 8:58 am

Re: HTTPS & Purebasic

Post by firace »

Lunasole wrote:Unfortunally it hasn't :/
Well should build own or seek for someone else binaries.

Code: Select all

#CURLOPT_CERTINFO = 172
        
; working with static libcurl
InitNetwork()
IncludeFile "libcurl.pbi"
EnableExplicit

Procedure wrfu(*ptr,  size,  nmemb,  *stream)
  ProcedureReturn size * nmemb
EndProcedure

Procedure Main ()
  curl_global_init(#CURL_GLOBAL_DEFAULT);
  Protected CURL = curl_easy_init()
	Protected res
	;Debug PeekS(curl_version(), -1, #PB_Ascii)

  If(curl)
    curl_easy_setopt(curl, #CURLOPT_URL, "https://www.example.com/")
 
    curl_easy_setopt(curl, #CURLOPT_WRITEFUNCTION, @wrfu())
 
    curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYPEER, 0)
    curl_easy_setopt(curl, #CURLOPT_SSL_VERIFYHOST, 0)
 
    curl_easy_setopt(curl, #CURLOPT_VERBOSE, 0)
    
    Debug curl_easy_setopt(curl, #CURLOPT_CERTINFO, 1) ; = CURLE_NOT_BUILT_IN
 
    res = curl_easy_perform(curl)
 
;     If Not res
;       union {
;         struct curl_slist    *to_info;
;         struct curl_certinfo *to_certinfo;
;       } ptr;
;  
;       ptr.to_info = NULL;
;  
;       res = curl_easy_getinfo(curl, #CURLINFO_CERTINFO, &ptr.to_info);
;  
;       If Not res And ptr.to_info)
;         int i;
;  
;         printf("%d certs!\n", ptr.to_certinfo->num_of_certs);
;  
;         For(i = 0; i < ptr.to_certinfo->num_of_certs; i++) {
;           struct curl_slist *slist;
;  
;           For(slist = ptr.to_certinfo->certinfo[i]; slist; slist = slist->next)
;             printf("%s\n", slist->Data);
;  
;         }
;       EndIf
;  
;     EndIf
 
    curl_easy_cleanup(curl);
  EndIf
 
  curl_global_cleanup()
 
  ProcedureReturn 0
EndProcedure

Main()
Would also love to see this work :)
uweb
User
User
Posts: 98
Joined: Wed Mar 15, 2006 9:40 am
Location: Germany

Re: HTTPS & Purebasic

Post by uweb »

Please pardon my English, my native tongue is German.
Post Reply