Skip to content

Commit

Permalink
Added explicit cacert.pem location for Windows platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Feb 15, 2025
1 parent d116ade commit 7f1592d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
40 changes: 32 additions & 8 deletions src/quoneq/ftp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::upload(
std::streampos fileSize = file.tellg();
file.seekg(0, std::ios::beg);

curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_READDATA, &file);
Expand All @@ -237,6 +236,10 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::upload(
static_cast<curl_off_t>(fileSize)
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());

Expand Down Expand Up @@ -280,7 +283,6 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::download_file(
return response;
}

curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &outfile);
curl_easy_setopt(
Expand All @@ -289,6 +291,10 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::download_file(
quoneq_ftp_client::write_file_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());

Expand Down Expand Up @@ -325,14 +331,17 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::read(

std::string data;
curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
curl_easy_setopt(
curl,
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());

Expand Down Expand Up @@ -365,9 +374,12 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::remove(
}

curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

std::string path = quoneq_ftp_client::extract_ftp_path(ftp_url);
std::string deleCmd = "DELE " + path;

Expand Down Expand Up @@ -411,7 +423,6 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::list(

std::string data;
curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
curl_easy_setopt(curl, CURLOPT_DIRLISTONLY, 1L);
curl_easy_setopt(
Expand All @@ -420,6 +431,10 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::list(
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());

Expand Down Expand Up @@ -510,9 +525,12 @@ bool quoneq_ftp_client::exists(
return false;

curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());

Expand Down Expand Up @@ -603,14 +621,17 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::file_info(

std::string data;
curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
curl_easy_setopt(
curl,
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());

Expand Down Expand Up @@ -644,14 +665,17 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::folder_info(

std::string data;
curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
curl_easy_setopt(
curl,
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());

Expand Down
20 changes: 16 additions & 4 deletions src/quoneq/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,16 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::get(
std::string response_string;

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, quoneq_http_client::write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, quoneq_http_client::header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, response.get());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

struct curl_slist* curl_headers = quoneq_http_client::prepare_headers(headers);
if(curl_headers)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers);
Expand Down Expand Up @@ -205,14 +208,17 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::post(
std::string response_string;

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, quoneq_http_client::write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, quoneq_http_client::header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, response.get());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

curl_mime* mime = curl_mime_init(curl);
for(const auto& field : form) {
curl_mimepart* part = curl_mime_addpart(mime);
Expand Down Expand Up @@ -286,7 +292,6 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::ping(
std::string response_string;

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, quoneq_http_client::write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
Expand All @@ -297,6 +302,10 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::ping(
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!proxy.empty())
curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());

Expand Down Expand Up @@ -355,13 +364,16 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::download_file(
}

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, quoneq_http_client::write_file_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &output_file);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, quoneq_http_client::header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, response.get());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

struct curl_slist* header_list = quoneq_http_client::prepare_headers(headers);
if(header_list)
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
Expand Down
2 changes: 1 addition & 1 deletion src/quoneq/smtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool quoneq_smtp_client::send_email(
upload_context upload_ctx{0, ""};

curl_easy_setopt(curl, CURLOPT_URL, smtp_server.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
curl_easy_setopt(curl, CURLOPT_USERNAME, email.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str());
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, email.c_str());
Expand Down
10 changes: 8 additions & 2 deletions src/quoneq/telnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ std::unique_ptr<quoneq_telnet_response> quoneq_telnet_client::command(
quoneq_telnet_client::write_callback
);

curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!proxy.empty())
curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());

Expand Down Expand Up @@ -186,11 +189,14 @@ std::unique_ptr<quoneq_telnet_response> quoneq_telnet_client::exec_with_options(
quoneq_telnet_client::write_callback
);

curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif

if(!proxy.empty())
curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());

Expand Down

0 comments on commit 7f1592d

Please sign in to comment.