Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.7
2.0.8
57 changes: 57 additions & 0 deletions src/eckit/io/EasyCURL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "eckit/io/EasyCURL.h"

#include <unistd.h>
#include <cstdlib>
#include <memory>

#include <curl/curl.h>
Expand Down Expand Up @@ -449,6 +450,62 @@ class CURLHandle : public eckit::Counted {
pthread_once(&once, init);
curl_ = curl_easy_init();
ASSERT(curl_);

// set an alternate CA bundle path:
// - if none of CA-related env variables are defined
// - if built-in default CA bundle path does not exist
static const auto cainfo = []() -> std::string {
const char* vars[] = {
"SSL_CERT_FILE",
"SSL_CERT_DIR",
"CURL_CA_BUNDLE",
"CURL_CA_PATH",
};

const char* bases[]{
"ca-bundle.crt", "cert.pem", "ca-certificates.crt", "curl-ca-bundle.crt",
"tls-ca-bundle.pem", "ca-root-nss.crt", "ca-bundle.pem",
};

const char* dirs[]{
"/etc/pki/tls/certs",
"/etc/ssl",
"/etc/ssl/certs",
"/etc/pki/ca-trust/extracted/pem",
"/usr/local/share/certs",
"/usr/local/etc/openssl@3",
"/opt/homebrew/etc/openssl@3",
Comment on lines +465 to +477
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ca-certs form the base of trust for TLS secured communication and thus the paths are set by the distribution. By picking up certs from additional locations we increase the possible attack surface.

Additionally this is a problem with a "well known" solution, i.e. setting the above mentioned env variables.

};

for (const auto* var : vars) {
if (std::getenv(var) != nullptr) {
return {};
}
}

#if CURL_AT_LEAST_VERSION(7, 84, 0)
if (const auto* info = curl_version_info(CURLVERSION_NOW); info != nullptr) {
if (info->cainfo != nullptr && PathName(info->cainfo).exists()) {
return {};
}
}
#endif

for (const auto* dirname : dirs) {
for (const auto* basename : bases) {
if (const auto path = PathName(dirname) / basename; path.exists()) {
Log::info() << "EasyCURL: using CA certificates from '" << path << "'" << std::endl;
return path.asString();
}
}
}

return {};
}();

if (!cainfo.empty()) {
_(curl_easy_setopt(curl_, CURLOPT_CAINFO, cainfo.c_str()));
}
}

~CURLHandle() {
Expand Down
Loading