From 16440a9c717a37c978b2ee6b917cab3763b204f8 Mon Sep 17 00:00:00 2001 From: marcelb Date: Wed, 29 Nov 2023 22:31:46 +0100 Subject: [PATCH] Add option to disable SSL validate --- lib/cppurl.hpp | 8 ++++++++ src/cppurl.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/cppurl.hpp b/lib/cppurl.hpp index 438eb54..1bd13ce 100644 --- a/lib/cppurl.hpp +++ b/lib/cppurl.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace marcelb { @@ -18,6 +19,7 @@ class Curl { struct curl_slist *headers = NULL; string _useragent; long _timeout = 0; + bool _sslvalidate = true; public: @@ -44,6 +46,12 @@ class Curl { Curl& timeout(const long _timeout); + /** + * Omogući/onemogući validaciju certifikata kod SSL veza + */ + + Curl& sslvalidate(const bool sslvalidate_); + /** * Izvršiv HTTP GET zahtjev * Vraća string HTTP tjela diff --git a/src/cppurl.cpp b/src/cppurl.cpp index b0ebfc7..5fad449 100644 --- a/src/cppurl.cpp +++ b/src/cppurl.cpp @@ -31,6 +31,10 @@ Curl& marcelb::Curl::timeout(const long timeout_) { return *this; } +Curl& marcelb::Curl::sslvalidate(const bool sslvalidate_) { + _sslvalidate = sslvalidate_; + return *this; +} string marcelb::Curl::get(const string& req){ curl = curl_easy_init(); @@ -48,6 +52,10 @@ string marcelb::Curl::get(const string& req){ if (_timeout > 0) { curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS , _timeout); } + if (!_sslvalidate) { + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, _sslvalidate ? 1 : 0); + curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, _sslvalidate ? 1 : 0); + } curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); res = curl_easy_perform(curl);