2017-11-14 17:24:20 +00:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
clearCache
|
|
|
|
|
|
|
|
nix-store --generate-binary-cache-key cache1.example.org $TEST_ROOT/sk1 $TEST_ROOT/pk1
|
|
|
|
pk1=$(cat $TEST_ROOT/pk1)
|
|
|
|
nix-store --generate-binary-cache-key cache2.example.org $TEST_ROOT/sk2 $TEST_ROOT/pk2
|
|
|
|
pk2=$(cat $TEST_ROOT/pk2)
|
|
|
|
|
|
|
|
# Build a path.
|
|
|
|
outPath=$(nix-build dependencies.nix --no-out-link --secret-key-files "$TEST_ROOT/sk1 $TEST_ROOT/sk2")
|
|
|
|
|
|
|
|
# Verify that the path got signed.
|
|
|
|
info=$(nix path-info --json $outPath)
|
|
|
|
[[ $info =~ '"ultimate":true' ]]
|
|
|
|
[[ $info =~ 'cache1.example.org' ]]
|
|
|
|
[[ $info =~ 'cache2.example.org' ]]
|
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
# Test "nix store verify".
|
|
|
|
nix store verify -r $outPath
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
expect 2 nix store verify -r $outPath --sigs-needed 1
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify -r $outPath --sigs-needed 1 --trusted-public-keys $pk1
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
expect 2 nix store verify -r $outPath --sigs-needed 2 --trusted-public-keys $pk1
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify -r $outPath --sigs-needed 2 --trusted-public-keys "$pk1 $pk2"
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify --all --sigs-needed 2 --trusted-public-keys "$pk1 $pk2"
|
2017-11-14 17:24:20 +00:00
|
|
|
|
|
|
|
# Build something unsigned.
|
|
|
|
outPath2=$(nix-build simple.nix --no-out-link)
|
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify -r $outPath
|
2017-11-14 17:24:20 +00:00
|
|
|
|
|
|
|
# Verify that the path did not get signed but does have the ultimate bit.
|
|
|
|
info=$(nix path-info --json $outPath2)
|
|
|
|
[[ $info =~ '"ultimate":true' ]]
|
|
|
|
(! [[ $info =~ 'signatures' ]])
|
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
# Test "nix store verify".
|
|
|
|
nix store verify -r $outPath2
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
expect 2 nix store verify -r $outPath2 --sigs-needed 1
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
expect 2 nix store verify -r $outPath2 --sigs-needed 1 --trusted-public-keys $pk1
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
# Test "nix store sign-paths".
|
|
|
|
nix store sign-paths --key-file $TEST_ROOT/sk1 $outPath2
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify -r $outPath2 --sigs-needed 1 --trusted-public-keys $pk1
|
2017-11-14 17:24:20 +00:00
|
|
|
|
2017-11-20 18:11:02 +00:00
|
|
|
# Build something content-addressed.
|
2017-12-07 00:06:56 +00:00
|
|
|
outPathCA=$(IMPURE_VAR1=foo IMPURE_VAR2=bar nix-build ./fixed.nix -A good.0 --no-out-link)
|
2017-11-20 18:11:02 +00:00
|
|
|
|
|
|
|
[[ $(nix path-info --json $outPathCA) =~ '"ca":"fixed:md5:' ]]
|
|
|
|
|
|
|
|
# Content-addressed paths don't need signatures, so they verify
|
|
|
|
# regardless of --sigs-needed.
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify $outPathCA
|
|
|
|
nix store verify $outPathCA --sigs-needed 1000
|
2017-11-20 18:11:02 +00:00
|
|
|
|
2018-09-26 02:18:52 +00:00
|
|
|
# Check that signing a content-addressed path doesn't overflow validSigs
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store sign-paths --key-file $TEST_ROOT/sk1 $outPathCA
|
|
|
|
nix store verify -r $outPathCA --sigs-needed 1000 --trusted-public-keys $pk1
|
2018-09-26 02:18:52 +00:00
|
|
|
|
2017-11-14 17:24:20 +00:00
|
|
|
# Copy to a binary cache.
|
|
|
|
nix copy --to file://$cacheDir $outPath2
|
|
|
|
|
|
|
|
# Verify that signatures got copied.
|
|
|
|
info=$(nix path-info --store file://$cacheDir --json $outPath2)
|
|
|
|
(! [[ $info =~ '"ultimate":true' ]])
|
|
|
|
[[ $info =~ 'cache1.example.org' ]]
|
|
|
|
(! [[ $info =~ 'cache2.example.org' ]])
|
2017-11-14 17:44:05 +00:00
|
|
|
|
|
|
|
# Verify that adding a signature to a path in a binary cache works.
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store sign-paths --store file://$cacheDir --key-file $TEST_ROOT/sk2 $outPath2
|
2017-11-14 17:44:05 +00:00
|
|
|
info=$(nix path-info --store file://$cacheDir --json $outPath2)
|
|
|
|
[[ $info =~ 'cache1.example.org' ]]
|
|
|
|
[[ $info =~ 'cache2.example.org' ]]
|
2017-11-20 18:02:57 +00:00
|
|
|
|
|
|
|
# Copying to a diverted store should fail due to a lack of valid signatures.
|
|
|
|
chmod -R u+w $TEST_ROOT/store0 || true
|
|
|
|
rm -rf $TEST_ROOT/store0
|
|
|
|
(! nix copy --to $TEST_ROOT/store0 $outPath)
|
|
|
|
|
|
|
|
# But succeed if we supply the public keys.
|
2017-11-20 18:11:02 +00:00
|
|
|
nix copy --to $TEST_ROOT/store0 $outPath --trusted-public-keys $pk1
|
2017-11-20 18:02:57 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
expect 2 nix store verify --store $TEST_ROOT/store0 -r $outPath
|
2017-11-20 18:02:57 +00:00
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify --store $TEST_ROOT/store0 -r $outPath --trusted-public-keys $pk1
|
|
|
|
nix store verify --store $TEST_ROOT/store0 -r $outPath --sigs-needed 2 --trusted-public-keys "$pk1 $pk2"
|
2017-11-20 18:02:57 +00:00
|
|
|
|
|
|
|
# It should also succeed if we disable signature checking.
|
|
|
|
(! nix copy --to $TEST_ROOT/store0 $outPath2)
|
|
|
|
nix copy --to $TEST_ROOT/store0?require-sigs=false $outPath2
|
|
|
|
|
|
|
|
# But signatures should still get copied.
|
2020-07-24 18:38:56 +00:00
|
|
|
nix store verify --store $TEST_ROOT/store0 -r $outPath2 --trusted-public-keys $pk1
|
2017-11-20 18:11:02 +00:00
|
|
|
|
|
|
|
# Content-addressed stuff can be copied without signatures.
|
|
|
|
nix copy --to $TEST_ROOT/store0 $outPathCA
|