Skip to content

Commit 1f5749c

Browse files
committed
Add support for SSL_CERT_FILE environment variable
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.
1 parent 5576c81 commit 1f5749c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/zsclient.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,23 @@ namespace zsync2 {
271271
// request so-called Instance Digest (RFC 3230, RFC 5843)
272272
session.SetHeader(cpr::Header{{"want-digest", "sha-512;q=1, sha-256;q=0.9, sha;q=0.2, md5;q=0.1"}});
273273

274+
// cURL hardcodes the current distro's CA bundle path
275+
// in order to use libzsync2 on other distributions (e.g., when used in an AppImage), the right path
276+
// must be passed to cURL
277+
// we could do this within the library, but it is probably easier to have the caller provide the right
278+
// path, since we can just pass one additional path
279+
// note that in upstream releases of AppImageUpdate and zsync2, we use cURL versions which search for
280+
// a CA bundle in multiple locations
281+
{
282+
char* caBundlePath = getenv("SSL_CERT_FILE");
283+
284+
if (caBundlePath != nullptr) {
285+
auto sslOptions = cpr::SslOptions{};
286+
sslOptions.SetOption({cpr::ssl::CaInfo{caBundlePath}});
287+
session.SetOption(sslOptions);
288+
}
289+
}
290+
274291
// if interested in headers only, download 1 kiB chunks until end of zsync header is found
275292
if (headersOnly && zSyncFileStoredLocallyAlready) {
276293
static const auto chunkSize = 1024;

0 commit comments

Comments
 (0)