Skip to content

Commit 573d931

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#7713: Fixes for verify-commits script
1e9aab0 Remove sipa's old revoked key from verify-commits (Peter Todd) 966151e Add README for verify-commits (Peter Todd) 11164ec Remove keys that are no longer used for merging (Peter Todd) 22421fa Remove pointless warning (Peter Todd) 9523e8a Make verify-commits path-independent (Matt Corallo) f7d4a25 Make verify-commits POSIX-compliant (Matt Corallo)
1 parent d2c3b7e commit 573d931

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

contrib/verify-commits/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Tooling for verification of PGP signed commits
2+
----------------------------------------------
3+
4+
This is an incomplete work in progress, but currently includes a pre-push hook
5+
script (`pre-push-hook.sh`) for maintainers to ensure that their own commits
6+
are PGP signed (nearly always merge commits), as well as a script to verify
7+
commits against a trusted keys list.
8+
9+
10+
Using verify-commits.sh safely
11+
------------------------------
12+
13+
Remember that you can't use an untrusted script to verify itself. This means
14+
that checking out code, then running `verify-commits.sh` against `HEAD` is
15+
_not_ safe, because the version of `verify-commits.sh` that you just ran could
16+
be backdoored. Instead, you need to use a trusted version of verify-commits
17+
prior to checkout to make sure you're checking out only code signed by trusted
18+
keys:
19+
20+
git fetch origin && \
21+
./contrib/verify-commits/verify-commits.sh origin/master && \
22+
git checkout origin/master
23+
24+
Note that the above isn't a good UI/UX yet, and needs significant improvements
25+
to make it more convenient and reduce the chance of errors; pull-reqs
26+
improving this process would be much appreciated.
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
586a29253dabec3ca0f1ccba9091daabd16b8411
2-
eddaba7b5692288087a926da5733e86b47274e4e

contrib/verify-commits/gpg.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/sh
2-
INPUT=$(</dev/stdin)
2+
INPUT=$(cat /dev/stdin)
33
VALID=false
44
REVSIG=false
5-
IFS=$'\n'
5+
IFS='
6+
'
67
for LINE in $(echo "$INPUT" | gpg --trust-model always "$@" 2>/dev/null); do
78
case "$LINE" in
89
"[GNUPG:] VALIDSIG "*)
@@ -13,10 +14,9 @@ for LINE in $(echo "$INPUT" | gpg --trust-model always "$@" 2>/dev/null); do
1314
"[GNUPG:] REVKEYSIG "*)
1415
[ "$BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG" != 1 ] && exit 1
1516
while read KEY; do
16-
case "$LINE" in "[GNUPG:] REVKEYSIG ${KEY:24:40} "*)
17+
case "$LINE" in "[GNUPG:] REVKEYSIG ${KEY#????????????????????????} "*)
1718
REVSIG=true
18-
GOODREVSIG="[GNUPG:] GOODSIG ${KEY:24:40} "
19-
;;
19+
GOODREVSIG="[GNUPG:] GOODSIG ${KEY#????????????????????????} "
2020
esac
2121
done < ./contrib/verify-commits/trusted-keys
2222
;;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
165e323d851cc87213c7673c6f278e87a6f2e752
1+
82bcf405f6db1d55b684a1f63a4aabad376cdad7

contrib/verify-commits/trusted-keys

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
71A3B16735405025D447E8F274810B012346C9A6
2-
1F4410F6A89268CE3197A84C57896D2FF8F0B657
3-
01CDF4627A3B88AAE4A571C87588242FBE38D3A8
4-
AF8BE07C7049F3A26B239D5325B3083201782B2F
5-
81291FA67D2C379A006A053FEAB5AF94D9E9ABE7
62
3F1888C6DCA92A6499C4911FDBA1A67379A1A931
73
32EE5C4C3FA15CCADB46ABE529D4BCB6416F53EC

contrib/verify-commits/verify-commits.sh

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
#!/bin/sh
2+
# Not technically POSIX-compliant due to use of "local", but almost every
3+
# shell anyone uses today supports it, so its probably fine
24

35
DIR=$(dirname "$0")
4-
5-
echo "Please verify all commits in the following list are not evil:"
6-
git log "$DIR"
6+
[ "/${DIR#/}" != "$DIR" ] && DIR=$(dirname "$(pwd)/$0")
77

88
VERIFIED_ROOT=$(cat "${DIR}/trusted-git-root")
9-
10-
IS_REVSIG_ALLOWED () {
11-
while read LINE; do
12-
[ "$LINE" = "$1" ] && return 0
13-
done < "${DIR}/allow-revsig-commits"
14-
return 1
15-
}
9+
REVSIG_ALLOWED=$(cat "${DIR}/allow-revsig-commits")
1610

1711
HAVE_FAILED=false
1812
IS_SIGNED () {
1913
if [ $1 = $VERIFIED_ROOT ]; then
2014
return 0;
2115
fi
22-
if IS_REVSIG_ALLOWED "$1"; then
16+
if [ "${REVSIG_ALLOWED#*$1}" != "$REVSIG_ALLOWED" ]; then
2317
export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG=1
2418
else
2519
export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG=0
2620
fi
2721
if ! git -c "gpg.program=${DIR}/gpg.sh" verify-commit $1 > /dev/null 2>&1; then
2822
return 1;
2923
fi
30-
local PARENTS=$(git show -s --format=format:%P $1)
24+
local PARENTS
25+
PARENTS=$(git show -s --format=format:%P $1)
3126
for PARENT in $PARENTS; do
3227
if IS_SIGNED $PARENT > /dev/null; then
3328
return 0;

0 commit comments

Comments
 (0)