Skip to content

Commit

Permalink
Add support for SSL_CERT_FILE environment variable
Browse files Browse the repository at this point in the history
This environment variable is supported by the CLI curl tool, too. It allows using a custom CA bundle with the tool.

Reasons to use this environment variable include the use of self-signed or otherwise untrusted certificates on the server or setting a CA bundle path when using the tool on a distro whose path differs from the one used on the build system.
  • Loading branch information
TheAssassin committed May 17, 2022
1 parent 5576c81 commit 1f5749c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/zsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,23 @@ namespace zsync2 {
// request so-called Instance Digest (RFC 3230, RFC 5843)
session.SetHeader(cpr::Header{{"want-digest", "sha-512;q=1, sha-256;q=0.9, sha;q=0.2, md5;q=0.1"}});

// cURL hardcodes the current distro's CA bundle path
// in order to use libzsync2 on other distributions (e.g., when used in an AppImage), the right path
// must be passed to cURL
// we could do this within the library, but it is probably easier to have the caller provide the right
// path, since we can just pass one additional path
// note that in upstream releases of AppImageUpdate and zsync2, we use cURL versions which search for
// a CA bundle in multiple locations
{
char* caBundlePath = getenv("SSL_CERT_FILE");

if (caBundlePath != nullptr) {
auto sslOptions = cpr::SslOptions{};
sslOptions.SetOption({cpr::ssl::CaInfo{caBundlePath}});
session.SetOption(sslOptions);
}
}

// if interested in headers only, download 1 kiB chunks until end of zsync header is found
if (headersOnly && zSyncFileStoredLocallyAlready) {
static const auto chunkSize = 1024;
Expand Down

0 comments on commit 1f5749c

Please sign in to comment.