From 1721141fd735f5ef7b20186c14e0d196d4d962c0 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 20 Jan 2022 19:15:37 +0800 Subject: [PATCH] Downloader: download file with cacert support --- core/network/CCDownloader-curl.cpp | 14 +++++++++++--- core/network/CCDownloader.cpp | 9 ++++++--- core/network/CCDownloader.h | 8 ++++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/core/network/CCDownloader-curl.cpp b/core/network/CCDownloader-curl.cpp index 5dc9b096b0..01f3070606 100644 --- a/core/network/CCDownloader-curl.cpp +++ b/core/network/CCDownloader-curl.cpp @@ -562,9 +562,17 @@ private: curl_easy_setopt(handle, CURLOPT_LOW_SPEED_LIMIT, 1L); curl_easy_setopt(handle, CURLOPT_LOW_SPEED_TIME, 10L); - - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); + + if(task->cacertPath.empty()) + { + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); + } + else { + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 1L); + curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 2L); + curl_easy_setopt(handle, CURLOPT_CAINFO, task->cacertPath.c_str()); + } curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 5L); diff --git a/core/network/CCDownloader.cpp b/core/network/CCDownloader.cpp index f53c222ead..634d2eb453 100644 --- a/core/network/CCDownloader.cpp +++ b/core/network/CCDownloader.cpp @@ -50,13 +50,15 @@ DownloadTask::DownloadTask(std::string_view srcUrl, std::string_view storagePath, std::string_view checksum, std::string_view identifier, - bool background) + bool background, + std::string_view cacertPath) { this->requestURL = srcUrl; this->storagePath = storagePath; this->checksum = checksum; this->identifier = identifier; this->background = background; + this->cacertPath = cacertPath; } DownloadTask::~DownloadTask() @@ -147,9 +149,10 @@ std::shared_ptr Downloader::createDownloadFileTask(std::string_vie std::string_view storagePath, std::string_view identifier, std::string_view md5checksum, - bool background) + bool background, + std::string_view cacertPath) { - auto task = std::make_shared(srcUrl, storagePath, md5checksum, identifier, background); + auto task = std::make_shared(srcUrl, storagePath, md5checksum, identifier, background, cacertPath); do { if (srcUrl.empty() || storagePath.empty()) diff --git a/core/network/CCDownloader.h b/core/network/CCDownloader.h index bbbfa5dbe6..4c0a5f5faa 100644 --- a/core/network/CCDownloader.h +++ b/core/network/CCDownloader.h @@ -60,6 +60,8 @@ public: std::string identifier; std::string requestURL; std::string storagePath; + + std::string cacertPath; struct { @@ -77,7 +79,8 @@ public: std::string_view storagePath, std::string_view checksum, // currently is MD5 std::string_view identifier, - bool background); + bool background, + std::string_view cacertPath); virtual ~DownloadTask(); @@ -140,7 +143,8 @@ public: std::string_view storagePath, std::string_view identifier = "", std::string_view checksum = "", - bool background = false); + bool background = false, + std::string_view cacertPath = ""); private: std::unique_ptr _impl;