Skip to content

Commit 039e569

Browse files
committed
libstore/filetransfer: add support for MTLS authentication
Certificate/private-key pair can be configured globally and it will be handled by libcurl.
1 parent 99a16c5 commit 039e569

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/libstore/filetransfer.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ struct curlFileTransfer : public FileTransfer
371371
curl_easy_setopt(req, CURLOPT_SSL_VERIFYHOST, 0);
372372
}
373373

374+
if (settings.clientCertFile != "" && settings.clientKeyFile != "") {
375+
curl_easy_setopt(req, CURLOPT_SSLCERT, settings.clientCertFile.get().c_str());
376+
curl_easy_setopt(req, CURLOPT_SSLKEY, settings.clientKeyFile.get().c_str());
377+
}
378+
374379
#if !defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x071000
375380
curl_easy_setopt(req, CURLOPT_SOCKOPTFUNCTION, cloexec_callback);
376381
#endif

src/libstore/include/nix/store/globals.hh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,26 @@ public:
10661066
// Don't document the machine-specific default value
10671067
false};
10681068

1069+
Setting<Path> clientCertFile{
1070+
this,
1071+
"",
1072+
"client-ssl-cert-file",
1073+
R"(
1074+
The path of a file containing a client TLS certificate used
1075+
to authenticate Nix to servers when using `https://`
1076+
downloads.
1077+
)"};
1078+
1079+
Setting<Path> clientKeyFile{
1080+
this,
1081+
"",
1082+
"client-ssl-key-file",
1083+
R"(
1084+
The path of a file containing a client TLS private key used
1085+
to authenticate Nix to servers when using `https://`
1086+
downloads.
1087+
)",};
1088+
10691089
#ifdef __linux__
10701090
Setting<bool> filterSyscalls{
10711091
this, true, "filter-syscalls",

0 commit comments

Comments
 (0)