Skip to content

Commit d660201

Browse files
ztzgvlaci
authored andcommitted
http-binary-cache-store: Add 'ssl-cert' and 'ssl-key' settings
Those are set via the store's URI, e.g.: https://substituter.invalid?ssl-cert=/path/to/cert.pem&ssl-key=/path/to/key.pem
1 parent dc52764 commit d660201

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/libstore/http-binary-cache-store.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,28 @@ class HttpBinaryCacheStore :
152152

153153
FileTransferRequest makeRequest(const std::string & path)
154154
{
155-
return FileTransferRequest(
156-
hasPrefix(path, "https://") || hasPrefix(path, "http://") || hasPrefix(path, "file://")
155+
bool absolute = hasPrefix(path, "https://") || hasPrefix(path, "http://") || hasPrefix(path, "file://");
156+
157+
FileTransferRequest request(
158+
absolute
157159
? path
158160
: config->cacheUri + "/" + path);
159161

162+
if (!absolute) {
163+
Path sslCert = config->sslCert.get();
164+
if (!sslCert.empty()) {
165+
debug("configuring SSL client certificate '%s' for '%s'", sslCert, request.uri);
166+
request.sslCert = sslCert;
167+
}
168+
169+
Path sslKey = config->sslKey.get();
170+
if (!sslKey.empty()) {
171+
debug("configuring SSL client certificate key '%s' for '%s'", sslKey, request.uri);
172+
request.sslKey = sslKey;
173+
}
174+
}
175+
176+
return request;
160177
}
161178

162179
void getFile(const std::string & path, Sink & sink) override

src/libstore/include/nix/store/http-binary-cache-store.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this<HttpBinaryCache
1313

1414
Path cacheUri;
1515

16+
const Setting<std::string> sslCert{
17+
this, "", "ssl-cert", "An optional SSL client certificate in PEM format; see CURLOPT_SSLCERT."};
18+
19+
const Setting<std::string> sslKey{
20+
this, "", "ssl-key", "The SSL client certificate key in PEM format; see CURLOPT_SSLKEY."};
21+
1622
static const std::string name()
1723
{
1824
return "HTTP Binary Cache Store";

0 commit comments

Comments
 (0)