2014-10-27 08:07:25 +01:00
|
|
|
#!/bin/sh
|
2016-09-11 21:36:22 +02:00
|
|
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-10-27 08:07:25 +01:00
|
|
|
DIR=$(dirname "$0")
|
2016-05-21 10:44:29 +02:00
|
|
|
[ "/${DIR#/}" != "$DIR" ] && DIR=$(dirname "$(pwd)/$0")
|
2014-10-27 08:07:25 +01:00
|
|
|
|
2017-02-27 20:13:39 +01:00
|
|
|
echo "Using verify-commits data from ${DIR}"
|
|
|
|
|
2014-10-27 08:07:25 +01:00
|
|
|
VERIFIED_ROOT=$(cat "${DIR}/trusted-git-root")
|
2017-02-27 20:13:39 +01:00
|
|
|
VERIFIED_SHA512_ROOT=$(cat "${DIR}/trusted-sha512-root-commit")
|
2016-05-21 03:29:15 +02:00
|
|
|
REVSIG_ALLOWED=$(cat "${DIR}/allow-revsig-commits")
|
2015-10-23 11:05:42 +02:00
|
|
|
|
2014-10-27 08:07:25 +01:00
|
|
|
HAVE_FAILED=false
|
2017-03-07 17:53:27 +01:00
|
|
|
|
2017-03-07 18:04:39 +01:00
|
|
|
HAVE_GNU_SHA512=1
|
|
|
|
[ ! -x "$(which sha512sum)" ] && HAVE_GNU_SHA512=0
|
|
|
|
|
2017-03-07 17:53:27 +01:00
|
|
|
if [ x"$1" = "x" ]; then
|
|
|
|
CURRENT_COMMIT="HEAD"
|
|
|
|
else
|
|
|
|
CURRENT_COMMIT="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${CURRENT_COMMIT#* }" != "$CURRENT_COMMIT" ]; then
|
|
|
|
echo "Commit must not contain spaces?" > /dev/stderr
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
VERIFY_TREE=0
|
|
|
|
if [ x"$2" = "x--tree-checks" ]; then
|
|
|
|
VERIFY_TREE=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
NO_SHA1=1
|
|
|
|
PREV_COMMIT=""
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
if [ "$CURRENT_COMMIT" = $VERIFIED_ROOT ]; then
|
|
|
|
echo "There is a valid path from "$CURRENT_COMMIT" to $VERIFIED_ROOT where all commits are signed!"
|
2017-10-09 14:36:01 +02:00
|
|
|
exit 0
|
2014-10-27 08:07:25 +01:00
|
|
|
fi
|
2017-02-27 20:13:39 +01:00
|
|
|
|
2017-03-07 17:53:27 +01:00
|
|
|
if [ "$CURRENT_COMMIT" = $VERIFIED_SHA512_ROOT ]; then
|
2017-02-27 20:13:39 +01:00
|
|
|
if [ "$VERIFY_TREE" = "1" ]; then
|
|
|
|
echo "All Tree-SHA512s matched up to $VERIFIED_SHA512_ROOT" > /dev/stderr
|
|
|
|
fi
|
|
|
|
VERIFY_TREE=0
|
|
|
|
NO_SHA1=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$NO_SHA1" = "1" ]; then
|
|
|
|
export BITCOIN_VERIFY_COMMITS_ALLOW_SHA1=0
|
|
|
|
else
|
|
|
|
export BITCOIN_VERIFY_COMMITS_ALLOW_SHA1=1
|
|
|
|
fi
|
|
|
|
|
2017-03-07 17:53:27 +01:00
|
|
|
if [ "${REVSIG_ALLOWED#*$CURRENT_COMMIT}" != "$REVSIG_ALLOWED" ]; then
|
2015-10-23 11:05:42 +02:00
|
|
|
export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG=1
|
|
|
|
else
|
|
|
|
export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG=0
|
|
|
|
fi
|
2017-02-27 20:13:39 +01:00
|
|
|
|
2017-03-07 17:53:27 +01:00
|
|
|
if ! git -c "gpg.program=${DIR}/gpg.sh" verify-commit "$CURRENT_COMMIT" > /dev/null; then
|
|
|
|
if [ "$PREV_COMMIT" != "" ]; then
|
|
|
|
echo "No parent of $PREV_COMMIT was signed with a trusted key!" > /dev/stderr
|
|
|
|
echo "Parents are:" > /dev/stderr
|
|
|
|
PARENTS=$(git show -s --format=format:%P $PREV_COMMIT)
|
|
|
|
for PARENT in $PARENTS; do
|
|
|
|
git show -s $PARENT > /dev/stderr
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "$CURRENT_COMMIT was not signed with a trusted key!" > /dev/stderr
|
|
|
|
fi
|
|
|
|
exit 1
|
2014-10-27 08:07:25 +01:00
|
|
|
fi
|
2017-02-27 20:13:39 +01:00
|
|
|
|
2017-03-07 17:53:27 +01:00
|
|
|
# We always verify the top of the tree
|
|
|
|
if [ "$VERIFY_TREE" = 1 -o "$PREV_COMMIT" = "" ]; then
|
2017-02-27 20:13:39 +01:00
|
|
|
IFS_CACHE="$IFS"
|
|
|
|
IFS='
|
|
|
|
'
|
2017-03-07 17:53:27 +01:00
|
|
|
for LINE in $(git ls-tree --full-tree -r "$CURRENT_COMMIT"); do
|
2017-02-27 20:13:39 +01:00
|
|
|
case "$LINE" in
|
|
|
|
"12"*)
|
|
|
|
echo "Repo contains symlinks" > /dev/stderr
|
|
|
|
IFS="$IFS_CACHE"
|
2017-03-07 17:53:27 +01:00
|
|
|
exit 1
|
2017-02-27 20:13:39 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
IFS="$IFS_CACHE"
|
|
|
|
|
|
|
|
FILE_HASHES=""
|
2017-03-07 17:53:27 +01:00
|
|
|
for FILE in $(git ls-tree --full-tree -r --name-only "$CURRENT_COMMIT" | LC_ALL=C sort); do
|
2017-03-07 18:04:39 +01:00
|
|
|
if [ "$HAVE_GNU_SHA512" = 1 ]; then
|
|
|
|
HASH=$(git cat-file blob "$CURRENT_COMMIT":"$FILE" | sha512sum | { read FIRST OTHER; echo $FIRST; } )
|
|
|
|
else
|
|
|
|
HASH=$(git cat-file blob "$CURRENT_COMMIT":"$FILE" | shasum -a 512 | { read FIRST OTHER; echo $FIRST; } )
|
|
|
|
fi
|
2017-03-06 22:14:13 +01:00
|
|
|
[ "$FILE_HASHES" != "" ] && FILE_HASHES="$FILE_HASHES"'
|
|
|
|
'
|
2017-02-27 20:13:39 +01:00
|
|
|
FILE_HASHES="$FILE_HASHES$HASH $FILE"
|
|
|
|
done
|
2017-03-07 18:04:39 +01:00
|
|
|
|
|
|
|
if [ "$HAVE_GNU_SHA512" = 1 ]; then
|
|
|
|
TREE_HASH="$(echo "$FILE_HASHES" | sha512sum)"
|
|
|
|
else
|
|
|
|
TREE_HASH="$(echo "$FILE_HASHES" | shasum -a 512)"
|
|
|
|
fi
|
2017-02-27 20:13:39 +01:00
|
|
|
HASH_MATCHES=0
|
2017-03-07 17:53:27 +01:00
|
|
|
MSG="$(git show -s --format=format:%B "$CURRENT_COMMIT" | tail -n1)"
|
2017-02-27 20:13:39 +01:00
|
|
|
|
|
|
|
case "$MSG -" in
|
2017-03-07 18:04:39 +01:00
|
|
|
"Tree-SHA512: $TREE_HASH")
|
2017-02-27 20:13:39 +01:00
|
|
|
HASH_MATCHES=1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$HASH_MATCHES" = "0" ]; then
|
2017-03-07 17:53:27 +01:00
|
|
|
echo "Tree-SHA512 did not match for commit $CURRENT_COMMIT" > /dev/stderr
|
|
|
|
exit 1
|
2017-02-27 20:13:39 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-03-07 17:53:27 +01:00
|
|
|
PARENTS=$(git show -s --format=format:%P "$CURRENT_COMMIT")
|
2014-10-27 08:07:25 +01:00
|
|
|
for PARENT in $PARENTS; do
|
2017-03-07 17:53:27 +01:00
|
|
|
PREV_COMMIT="$CURRENT_COMMIT"
|
|
|
|
CURRENT_COMMIT="$PARENT"
|
2017-01-31 20:59:32 +01:00
|
|
|
break
|
2014-10-27 08:07:25 +01:00
|
|
|
done
|
2017-03-07 17:53:27 +01:00
|
|
|
done
|