From 04364159dcceff04d4a374bda08ce258e8da92fb Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sun, 28 Jan 2024 13:09:50 +0100 Subject: [PATCH] Fixed non OpenSSl based builds --- CMakeLists.txt | 2 +- cpr/callback.cpp | 10 ++++++---- cpr/session.cpp | 5 ++++- include/cpr/callback.h | 2 ++ include/cpr/ssl_options.h | 6 ++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df9726312..9f5004840 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ cpr_option(CPR_ENABLE_SSL "Enables or disables the SSL backend. Required to perf cpr_option(CPR_FORCE_OPENSSL_BACKEND "Force to use the OpenSSL backend. If CPR_FORCE_OPENSSL_BACKEND, CPR_FORCE_DARWINSSL_BACKEND, CPR_FORCE_MBEDTLS_BACKEND, and CPR_FORCE_WINSSL_BACKEND are set to to OFF, cpr will try to automatically detect the best available SSL backend (WinSSL - Windows, OpenSSL - Linux, DarwinSSL - Mac ...)." OFF) cpr_option(CPR_FORCE_WINSSL_BACKEND "Force to use the WinSSL backend. If CPR_FORCE_OPENSSL_BACKEND, CPR_FORCE_DARWINSSL_BACKEND, CPR_FORCE_MBEDTLS_BACKEND, and CPR_FORCE_WINSSL_BACKEND are set to to OFF, cpr will try to automatically detect the best available SSL backend (WinSSL - Windows, OpenSSL - Linux, DarwinSSL - Mac ...)." OFF) cpr_option(CPR_FORCE_DARWINSSL_BACKEND "Force to use the DarwinSSL backend. If CPR_FORCE_OPENSSL_BACKEND, CPR_FORCE_DARWINSSL_BACKEND, CPR_FORCE_MBEDTLS_BACKEND, and CPR_FORCE_WINSSL_BACKEND are set to to OFF, cpr will try to automatically detect the best available SSL backend (WinSSL - Windows, OpenSSL - Linux, DarwinSSL - Mac ...)." OFF) -cpr_option(CPR_FORCE_MBEDTLS_BACKEND "Force to use the Mbed TLS backend. If CPR_FORCE_OPENSSL_BACKEND, CPR_FORCE_DARWINSSL_BACKEND, CPR_FORCE_MBEDTLS_BACKEND, and CPR_FORCE_WINSSL_BACKEND are set to to OFF, cpr will try to automatically detect the best available SSL backend (WinSSL - Windows, OpenSSL - Linux, DarwinSSL - Mac ...)." OFF) +cpr_option(CPR_FORCE_MBEDTLS_BACKEND "Force to use the Mbed TLS backend. If CPR_FORCE_OPENSSL_BACKEND, CPR_FORCE_DARWINSSL_BACKEND, CPR_FORCE_MBEDTLS_BACKEND, and CPR_FORCE_WINSSL_BACKEND are set to to OFF, cpr will try to automatically detect the best available SSL backend (WinSSL - Windows, OpenSSL - Linux, DarwinSSL - Mac ...)." ON) cpr_option(CPR_ENABLE_LINTING "Set to ON to enable clang linting." OFF) cpr_option(CPR_ENABLE_CPPCHECK "Set to ON to enable Cppcheck static analysis. Requires CPR_BUILD_TESTS and CPR_BUILD_TESTS_SSL to be OFF to prevent checking google tests source code." OFF) cpr_option(CPR_BUILD_TESTS "Set to ON to build cpr tests." OFF) diff --git a/cpr/callback.cpp b/cpr/callback.cpp index 3fb4e0b0c..2ba1e197c 100644 --- a/cpr/callback.cpp +++ b/cpr/callback.cpp @@ -1,11 +1,13 @@ #include +#ifdef OPENSSL_BACKEND_USED #include +#endif // OPENSSL_BACKEND_USED #include "cpr/callback.h" #include "cpr/cprtypes.h" #include -#if SUPPORT_CURLOPT_SSL_CTX_FUNCTION +#ifdef OPENSSL_BACKEND_USED #include #include #include @@ -21,7 +23,7 @@ #else #include #endif -#endif // SUPPORT_CURLOPT_SSL_CTX_FUNCTION +#endif // OPENSSL_BACKEND_USED namespace cpr { @@ -33,7 +35,7 @@ bool CancellationCallback::operator()(cpr_pf_arg_t dltotal, cpr_pf_arg_t dlnow, return user_cb ? (cont_operation && (*user_cb)(dltotal, dlnow, ultotal, ulnow)) : cont_operation; } -#if SUPPORT_CURLOPT_SSL_CTX_FUNCTION +#ifdef OPENSSL_BACKEND_USED namespace ssl { /** * The ssl_ctx parameter is actually a pointer to the SSL library's SSL_CTX for OpenSSL. @@ -87,5 +89,5 @@ CURLcode tryLoadCaCertFromBuffer(CURL* /*curl*/, void* sslctx, void* raw_cert_bu return CURLE_OK; } } // namespace ssl -#endif // SUPPORT_CURLOPT_SSL_CTX_FUNCTION +#endif // OPENSSL_BACKEND_USED } // namespace cpr diff --git a/cpr/session.cpp b/cpr/session.cpp index c9a8b6858..0d01f94cc 100644 --- a/cpr/session.cpp +++ b/cpr/session.cpp @@ -542,13 +542,16 @@ void Session::SetSslOptions(const SslOptions& options) { curl_easy_setopt(curl_->handle, CURLOPT_SSL_CTX_FUNCTION, ssl::tryLoadCaCertFromBuffer); curl_easy_setopt(curl_->handle, CURLOPT_SSL_CTX_DATA, options.ca_buffer.c_str()); } +#endif if (options.ssl_ctx_cb.callback) { cbs_->sslctxcb_ = options.ssl_ctx_cb; cbs_->sslctxcb_.SetCurlHolder(curl_); curl_easy_setopt(curl_->handle, CURLOPT_SSL_CTX_FUNCTION, cpr::util::sslCtxUserFunction); curl_easy_setopt(curl_->handle, CURLOPT_SSL_CTX_DATA, &cbs_->sslctxcb_); - } else if (options.ca_buffer.empty()) { + } +#ifdef OPENSSL_BACKEND_USED + else if (options.ca_buffer.empty()) { curl_easy_setopt(curl_->handle, CURLOPT_SSL_CTX_FUNCTION, nullptr); } #endif diff --git a/include/cpr/callback.h b/include/cpr/callback.h index 5e4800641..9319a352e 100644 --- a/include/cpr/callback.h +++ b/include/cpr/callback.h @@ -153,7 +153,9 @@ class SslCtxCallback { } }; +#ifdef OPENSSL_BACKEND_USED CURLcode tryLoadCaCertFromBuffer(CURL* curl, void* sslctx, void* raw_cert_buf); +#endif } // namespace ssl #endif } // namespace cpr diff --git a/include/cpr/ssl_options.h b/include/cpr/ssl_options.h index 8ab3f4d26..19368e82d 100644 --- a/include/cpr/ssl_options.h +++ b/include/cpr/ssl_options.h @@ -320,6 +320,7 @@ class CaPath { }; #if SUPPORT_CURLOPT_SSL_CTX_FUNCTION +#ifdef OPENSSL_BACKEND_USED class CaBuffer { public: // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) @@ -327,6 +328,7 @@ class CaBuffer { const std::string buffer; }; +#endif // OPENSSL_BACKEND_USED #endif // specify a Certificate Revocation List file @@ -436,7 +438,9 @@ struct SslOptions { // We don't use fs::path here, as this leads to problems using windows std::string ca_path; #if SUPPORT_CURLOPT_SSL_CTX_FUNCTION +#ifdef OPENSSL_BACKEND_USED std::string ca_buffer; +#endif // OPENSSL_BACKEND_USED #endif // We don't use fs::path here, as this leads to problems using windows std::string crl_file; @@ -568,9 +572,11 @@ struct SslOptions { ca_path = opt.filename.string(); } #if SUPPORT_CURLOPT_SSL_CTX_FUNCTION +#ifdef OPENSSL_BACKEND_USED void SetOption(const ssl::CaBuffer& opt) { ca_buffer = opt.buffer; } +#endif // OPENSSL_BACKEND_USED #endif void SetOption(const ssl::Crl& opt) { crl_file = opt.filename.string();