From b1441366f449652a3d1182e715127eb1d4792424 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 25 Aug 2022 05:16:23 +0200 Subject: [PATCH] add Http::verify_ssl(bool verify) method --- winixd/utils/http.cpp | 8 ++++++++ winixd/utils/http.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/winixd/utils/http.cpp b/winixd/utils/http.cpp index 1be5b39..fd083df 100644 --- a/winixd/utils/http.cpp +++ b/winixd/utils/http.cpp @@ -72,6 +72,7 @@ Http & Http::begin() debug_mode = 0; debug_info = nullptr; follow_location = true; + verify_ssl_cert = true; return *this; } @@ -414,6 +415,11 @@ void Http::allow_redirects(bool allow_redirects) } +void Http::verify_ssl(bool verify) +{ + this->verify_ssl_cert = verify; +} + void Http::initialize_curl_if_needed() @@ -498,6 +504,8 @@ bool Http::fetch_internal(const char * url, const std::string * in, pt::TextStre curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, (follow_location) ? 1 : 0); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 20); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, (verify_ssl_cert) ? 1 : 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, (verify_ssl_cert) ? 2 : 0); // set to 2: https://curl.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html if( debug_mode == 1 ) { diff --git a/winixd/utils/http.h b/winixd/utils/http.h index a9c3dbd..4234622 100644 --- a/winixd/utils/http.h +++ b/winixd/utils/http.h @@ -151,6 +151,12 @@ public: */ void allow_redirects(bool allow_redirects); + /* + * verify the peer's SSL certificate + * default is true + */ + void verify_ssl(bool verify); + bool get(const wchar_t * url, std::wstring & out, bool clear_str = true); bool get(const std::wstring & url, std::wstring & out, bool clear_str = true); bool get(const pt::WTextStream & url, std::wstring & out, bool clear_str = true); @@ -189,6 +195,7 @@ private: long debug_mode; pt::Space * debug_info; bool follow_location; + bool verify_ssl_cert; std::wstring temp_header; std::string temp_header_ascii;