Skip to content

Commit 5926432

Browse files
committed
guix: Add guix-verify script
1 parent 30daf76 commit 5926432

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

contrib/guix/guix-verify

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env bash
2+
export LC_ALL=C
3+
set -e -o pipefail
4+
5+
# Source the common prelude, which:
6+
# 1. Checks if we're at the top directory of the Bitcoin Core repository
7+
# 2. Defines a few common functions and variables
8+
#
9+
# shellcheck source=libexec/prelude.bash
10+
source "$(dirname "${BASH_SOURCE[0]}")/libexec/prelude.bash"
11+
12+
13+
###################
14+
## Sanity Checks ##
15+
###################
16+
17+
################
18+
# Required non-builtin commands should be invokable
19+
################
20+
21+
check_tools cat diff gpg
22+
23+
################
24+
# Required env vars should be non-empty
25+
################
26+
27+
cmd_usage() {
28+
cat <<EOF
29+
Synopsis:
30+
31+
env GUIX_SIGS_REPO=<path/to/guix.sigs> ./contrib/guix/guix-verify
32+
33+
EOF
34+
}
35+
36+
if [ -z "$GUIX_SIGS_REPO" ]; then
37+
cmd_usage
38+
exit 1
39+
fi
40+
41+
################
42+
# GUIX_SIGS_REPO should exist as a directory
43+
################
44+
45+
if [ ! -d "$GUIX_SIGS_REPO" ]; then
46+
cat << EOF
47+
ERR: The specified GUIX_SIGS_REPO is not an existent directory:
48+
49+
'$GUIX_SIGS_REPO'
50+
51+
Hint: Please clone the guix.sigs repository and point to it with the
52+
GUIX_SIGS_REPO environment variable.
53+
54+
EOF
55+
cmd_usage
56+
exit 1
57+
fi
58+
59+
################
60+
# We should be able to find at least one output
61+
################
62+
63+
OUTSIGDIR_BASE="${GUIX_SIGS_REPO}/${VERSION}"
64+
echo "Looking for output signature directories in '${OUTSIGDIR_BASE}'"
65+
66+
shopt -s nullglob
67+
OUTSIGDIRS=( "$OUTSIGDIR_BASE"/* ) # This expands to an array of directories...
68+
shopt -u nullglob
69+
70+
if (( ${#OUTSIGDIRS[@]} )); then
71+
echo "Found output signature directories:"
72+
for outsigdir in "${OUTSIGDIRS[@]}"; do
73+
echo " '$outsigdir'"
74+
done
75+
echo
76+
else
77+
echo "ERR: Could not find any output signature directories in ${OUTSIGDIR_BASE}"
78+
exit 1
79+
fi
80+
81+
82+
##############
83+
## Verify ##
84+
##############
85+
86+
# MAIN LOGIC: Loop through each output for VERSION and check that the SHA256SUMS
87+
# and SHA256SUMS.asc file match between signers, using the first
88+
# available signer as the arbitrary comparison base.
89+
for outsigdir in "${OUTSIGDIRS[@]}"; do
90+
echo "BEGIN: Checking output signatures for $(basename "$outsigdir")"
91+
echo ""
92+
signer_dirs=( "$outsigdir"/* ) # This expands to an array of directories...
93+
compare_signer_dir="${signer_dirs[0]}" # ...we just want the first one
94+
for current_signer_dir in "${signer_dirs[@]}"; do
95+
if ! gpg --quiet --batch --verify "$current_signer_dir"/SHA256SUMS.asc "$current_signer_dir"/SHA256SUMS; then
96+
echo "ERR: Failed to verify GPG signature in '${current_signer_dir}/SHA256SUMS.asc'"
97+
echo ""
98+
echo "Hint: Either the signature is invalid or the public key is missing"
99+
echo ""
100+
elif ! diff --report-identical "$compare_signer_dir"/SHA256SUMS "$current_signer_dir"/SHA256SUMS; then
101+
echo "ERR: The SHA256SUMS attestation in these two directories differ:"
102+
echo " '${compare_signer_dir}'"
103+
echo " '${current_signer_dir}'"
104+
echo ""
105+
else
106+
echo "Verified: '${current_signer_dir}'"
107+
echo ""
108+
fi
109+
done
110+
echo "DONE: Checking output signatures for $(basename "$outsigdir")"
111+
echo ""
112+
echo ""
113+
done

0 commit comments

Comments
 (0)