Skip to content

Commit 00c13ea

Browse files
committed
Merge #9932: Fix verify-commits on travis and always check top commit's tree
b3ec305 Fix bashisms in verify-commits and always check top commit's tree (Matt Corallo) f20e664 Check gpg version before setting --weak-digest (Matt Corallo) Tree-SHA512: f87247008ae6a265e3fd371f00aec0e84f1feb713bf5859eab139a88a4e205e1f26de7b510bcc2c3ab538d5443978a48ec920d25b52b9601e625d198fa2d725f
2 parents 19be26a + b3ec305 commit 00c13ea

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

contrib/verify-commits/gpg.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,20 @@ else
1919
# an attacker could construct a pull-req that results in a commit object that
2020
# they've created a collision for. Not the most likely attack, but preventing
2121
# it is pretty easy so we do so as a "belt-and-suspenders" measure.
22-
23-
GPG_RES="$(echo "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null)"
22+
GPG_RES=""
23+
for LINE in "$(gpg --version)"; do
24+
case "$LINE" in
25+
"gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*)
26+
echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr
27+
GPG_RES="$(echo "$INPUT" | gpg --trust-model always "$@" 2>/dev/null)"
28+
;;
29+
# We assume if you're running 2.1+, you're probably running 2.1.10+
30+
# gpg will fail otherwise
31+
# We assume if you're running 1.X, it is either 1.4.1X or 1.4.20+
32+
# gpg will fail otherwise
33+
esac
34+
done
35+
[ "$GPG_RES" = "" ] && GPG_RES="$(echo "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null)"
2436
fi
2537
for LINE in $(echo "$GPG_RES"); do
2638
case "$LINE" in
@@ -40,7 +52,7 @@ if ! $VALID; then
4052
exit 1
4153
fi
4254
if $VALID && $REVSIG; then
43-
echo "$INPUT" | gpg --trust-model always "$@" | grep "\[GNUPG:\] \(NEWSIG\|SIG_ID\|VALIDSIG\)" 2>/dev/null
55+
echo "$INPUT" | gpg --trust-model always "$@" 2>/dev/null | grep "\[GNUPG:\] \(NEWSIG\|SIG_ID\|VALIDSIG\)"
4456
echo "$GOODREVSIG"
4557
else
4658
echo "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b00ba6251f71fa1edaabdf809514e1bc3c67862e
1+
f7ec7cfd38b543ba81ac7bed5b77f9a19739460b

contrib/verify-commits/verify-commits.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ IS_SIGNED () {
4343
export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG=0
4444
fi
4545

46-
if ! git -c "gpg.program=${DIR}/gpg.sh" verify-commit $1 > /dev/null 2>&1; then
46+
if ! git -c "gpg.program=${DIR}/gpg.sh" verify-commit $1 > /dev/null; then
4747
return 1;
4848
fi
4949

50-
if [ "$VERIFY_TREE" = 1 ]; then
50+
# We set $4 to 1 on the first call, always verifying the top of the tree
51+
if [ "$VERIFY_TREE" = 1 -o "$4" = "1" ]; then
5152
IFS_CACHE="$IFS"
5253
IFS='
5354
'
@@ -63,9 +64,10 @@ IS_SIGNED () {
6364
IFS="$IFS_CACHE"
6465

6566
FILE_HASHES=""
66-
for FILE in $(git ls-tree --full-tree -r --name-only $1 | LANG=C sort); do
67+
for FILE in $(git ls-tree --full-tree -r --name-only $1 | LC_ALL=C sort); do
6768
HASH=$(git cat-file blob $1:"$FILE" | sha512sum | { read FIRST OTHER; echo $FIRST; } )
68-
[ "$FILE_HASHES" != "" ] && FILE_HASHES="$FILE_HASHES"$'\n'
69+
[ "$FILE_HASHES" != "" ] && FILE_HASHES="$FILE_HASHES"'
70+
'
6971
FILE_HASHES="$FILE_HASHES$HASH $FILE"
7072
done
7173
HASH_MATCHES=0
@@ -86,7 +88,7 @@ IS_SIGNED () {
8688
local PARENTS
8789
PARENTS=$(git show -s --format=format:%P $1)
8890
for PARENT in $PARENTS; do
89-
if IS_SIGNED $PARENT $VERIFY_TREE $NO_SHA1; then
91+
if IS_SIGNED $PARENT $VERIFY_TREE $NO_SHA1 0; then
9092
return 0;
9193
fi
9294
break
@@ -111,10 +113,9 @@ fi
111113
DO_CHECKOUT_TEST=0
112114
if [ x"$2" = "x--tree-checks" ]; then
113115
DO_CHECKOUT_TEST=1
114-
115116
fi
116117

117-
IS_SIGNED "$TEST_COMMIT" "$DO_CHECKOUT_TEST" 1
118+
IS_SIGNED "$TEST_COMMIT" "$DO_CHECKOUT_TEST" 1 1
118119
RES=$?
119120
if [ "$RES" = 1 ]; then
120121
if ! "$HAVE_FAILED"; then

0 commit comments

Comments
 (0)