Skip to content

Commit 903a2aa

Browse files
committed
secretKeyFiles - move to JSON
Using a JSON string array. It does not work super great without modifying more of the parsing logic: +(signing.sh:115) nix copy --to 'file:///tmp/nix-shell.9u6yin/nix-test/main/signing/storemultisig?secret-keys=["/tmp/nix-shell.9u6yin/nix-test/main/signing/sk1","/tmp/nix-shell.9u6yin/nix-test/main/signing/sk2"]' /tmp/nix-shell.9u6yin/nix-test/main/signing/store/v6vdfqbxk9q56m6gcvk4h7hyq842y18q-dependencies-top error: Cannot parse Nix store 'file:///tmp/nix-shell.9u6yin/nix-test/main/signing/storemultisig?secret-keys=["/tmp/nix-shell.9u6yin/nix-test/main/signing/sk1","/tmp/nix-shell.9u6yin/nix-test/main/signing/sk2"]' Try 'nix --help' for more information. ++(signing.sh:115) onError ++(/home/ninjatrappeur/code-root/github.com/NixOS/nix/tests/functional/common/functions.sh:241) set +x signing.sh: test failed at: main in signing.sh:115 Besides, the syntax is not great from the CLI: we need to escape the double quotes provided we want to do some sort of variable substitution. nix copy --to \ "file://$TEST_ROOT/storemultisig?secret-keys=[\"$TEST_ROOT/sk1\",\"$TEST_ROOT/sk2\"]" \ "$outPath" :/
1 parent e12369a commit 903a2aa

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/libstore/binary-cache-store.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "nix/store/binary-cache-store.hh"
33
#include "nix/util/compression.hh"
44
#include "nix/store/derivations.hh"
5+
#include "nix/util/logging.hh"
6+
#include "nix/util/signature/local-keys.hh"
57
#include "nix/util/source-accessor.hh"
68
#include "nix/store/globals.hh"
79
#include "nix/store/nar-info.hh"
@@ -16,6 +18,7 @@
1618

1719
#include <chrono>
1820
#include <future>
21+
#include <memory>
1922
#include <regex>
2023
#include <fstream>
2124
#include <sstream>
@@ -33,11 +36,21 @@ BinaryCacheStore::BinaryCacheStore(const Params & params)
3336
SecretKey { readFile(secretKeyFile) }));
3437

3538
if (secretKeyFiles != "") {
36-
std::stringstream ss(secretKeyFiles);
37-
Path keyPath;
38-
while (std::getline(ss, keyPath, ',')) {
39+
// secretKeyFiles should be a JSON list of strings.
40+
nlohmann::json j = nlohmann::json::parse(secretKeyFiles.get());
41+
if (!j.is_array()) {
42+
logger->warn("Not an array!!!");
43+
throw std::runtime_error("secretKeyFiles is not a JSON array");
44+
}
45+
for (const auto& keyPath : j) {
46+
logger->warn("Parsing keypath!!!");
47+
if (!keyPath.is_string()) {
48+
logger->warn("Not a string!!!!");
49+
throw std::runtime_error("Array contains non-string elements");
50+
}
3951
signers.push_back(std::make_unique<LocalSigner>(
40-
SecretKey { readFile(keyPath) }));
52+
SecretKey { readFile(keyPath.get<std::string>())}
53+
));
4154
}
4255
}
4356

tests/functional/signing.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ nix store verify --store "$TEST_ROOT"/store0 -r "$outPath2" --trusted-public-key
112112
nix copy --to "$TEST_ROOT"/store0 "$outPathCA"
113113

114114
# Test multiple signing keys
115-
nix copy --to "file://$TEST_ROOT/storemultisig?secret-keys=$TEST_ROOT/sk1,$TEST_ROOT/sk2" "$outPath"
115+
nix copy --to "file://$TEST_ROOT/storemultisig?secret-keys=[\"$TEST_ROOT/sk1\",\"$TEST_ROOT/sk2\"]" "$outPath"
116116
for file in "$TEST_ROOT/storemultisig/"*.narinfo; do
117117
if [[ "$(grep -cE '^Sig: cache[1,2]\.example.org' "$file")" -ne 2 ]]; then
118118
echo "ERROR: Cannot find cache1.example.org and cache2.example.org signatures in ${file}"

0 commit comments

Comments
 (0)