2 # Copyright (c) 2014-2016 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 [ "/${DIR#/}" != "$DIR" ] && DIR
=$
(dirname "$(pwd)/$0")
9 echo "Using verify-commits data from ${DIR}"
11 VERIFIED_ROOT
=$
(cat "${DIR}/trusted-git-root")
12 VERIFIED_SHA512_ROOT
=$
(cat "${DIR}/trusted-sha512-root-commit")
13 REVSIG_ALLOWED
=$
(cat "${DIR}/allow-revsig-commits")
16 [ ! -x "$(which sha512sum)" ] && HAVE_GNU_SHA512
=0
18 if [ x
"$1" = "x" ]; then
24 if [ "${CURRENT_COMMIT#* }" != "$CURRENT_COMMIT" ]; then
25 echo "Commit must not contain spaces?" > /dev
/stderr
30 if [ x
"$2" = "x--tree-checks" ]; then
36 INITIAL_COMMIT
="${CURRENT_COMMIT}"
39 if [ "$CURRENT_COMMIT" = $VERIFIED_ROOT ]; then
40 echo "There is a valid path from \"$INITIAL_COMMIT\" to $VERIFIED_ROOT where all commits are signed!"
44 if [ "$CURRENT_COMMIT" = $VERIFIED_SHA512_ROOT ]; then
45 if [ "$VERIFY_TREE" = "1" ]; then
46 echo "All Tree-SHA512s matched up to $VERIFIED_SHA512_ROOT" > /dev
/stderr
52 if [ "$NO_SHA1" = "1" ]; then
53 export BITCOIN_VERIFY_COMMITS_ALLOW_SHA1
=0
55 export BITCOIN_VERIFY_COMMITS_ALLOW_SHA1
=1
58 if [ "${REVSIG_ALLOWED#*$CURRENT_COMMIT}" != "$REVSIG_ALLOWED" ]; then
59 export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG
=1
61 export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG
=0
64 if ! git
-c "gpg.program=${DIR}/gpg.sh" verify-commit
"$CURRENT_COMMIT" > /dev
/null
; then
65 if [ "$PREV_COMMIT" != "" ]; then
66 echo "No parent of $PREV_COMMIT was signed with a trusted key!" > /dev
/stderr
67 echo "Parents are:" > /dev
/stderr
68 PARENTS
=$
(git show
-s --format=format
:%P
$PREV_COMMIT)
69 for PARENT
in $PARENTS; do
70 git show
-s $PARENT > /dev
/stderr
73 echo "$CURRENT_COMMIT was not signed with a trusted key!" > /dev
/stderr
78 # We always verify the top of the tree
79 if [ "$VERIFY_TREE" = 1 -o "$PREV_COMMIT" = "" ]; then
83 for LINE
in $
(git ls-tree
--full-tree -r "$CURRENT_COMMIT"); do
86 echo "Repo contains symlinks" > /dev
/stderr
95 for FILE
in $
(git ls-tree
--full-tree -r --name-only "$CURRENT_COMMIT" | LC_ALL
=C
sort); do
96 if [ "$HAVE_GNU_SHA512" = 1 ]; then
97 HASH
=$
(git cat-file blob
"$CURRENT_COMMIT":"$FILE" | sha512sum |
{ read FIRST _
; echo $FIRST; } )
99 HASH
=$
(git cat-file blob
"$CURRENT_COMMIT":"$FILE" | shasum
-a 512 |
{ read FIRST _
; echo $FIRST; } )
101 [ "$FILE_HASHES" != "" ] && FILE_HASHES
="$FILE_HASHES"'
103 FILE_HASHES
="$FILE_HASHES$HASH $FILE"
106 if [ "$HAVE_GNU_SHA512" = 1 ]; then
107 TREE_HASH
="$(echo "$FILE_HASHES" | sha512sum)"
109 TREE_HASH
="$(echo "$FILE_HASHES" | shasum -a 512)"
112 MSG
="$(git show -s --format=format:%B "$CURRENT_COMMIT" | tail -n1)"
115 "Tree-SHA512: $TREE_HASH")
119 if [ "$HASH_MATCHES" = "0" ]; then
120 echo "Tree-SHA512 did not match for commit $CURRENT_COMMIT" > /dev
/stderr
125 PARENTS
=$
(git show
-s --format=format
:%P
"$CURRENT_COMMIT")
126 for PARENT
in $PARENTS; do
127 PREV_COMMIT
="$CURRENT_COMMIT"
128 CURRENT_COMMIT
="$PARENT"