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")
18 [ ! -x "$(which sha512sum)" ] && HAVE_GNU_SHA512
=0
20 if [ x
"$1" = "x" ]; then
26 if [ "${CURRENT_COMMIT#* }" != "$CURRENT_COMMIT" ]; then
27 echo "Commit must not contain spaces?" > /dev
/stderr
32 if [ x
"$2" = "x--tree-checks" ]; then
40 if [ "$CURRENT_COMMIT" = $VERIFIED_ROOT ]; then
41 echo "There is a valid path from "$CURRENT_COMMIT" to $VERIFIED_ROOT where all commits are signed!"
45 if [ "$CURRENT_COMMIT" = $VERIFIED_SHA512_ROOT ]; then
46 if [ "$VERIFY_TREE" = "1" ]; then
47 echo "All Tree-SHA512s matched up to $VERIFIED_SHA512_ROOT" > /dev
/stderr
53 if [ "$NO_SHA1" = "1" ]; then
54 export BITCOIN_VERIFY_COMMITS_ALLOW_SHA1
=0
56 export BITCOIN_VERIFY_COMMITS_ALLOW_SHA1
=1
59 if [ "${REVSIG_ALLOWED#*$CURRENT_COMMIT}" != "$REVSIG_ALLOWED" ]; then
60 export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG
=1
62 export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG
=0
65 if ! git
-c "gpg.program=${DIR}/gpg.sh" verify-commit
"$CURRENT_COMMIT" > /dev
/null
; then
66 if [ "$PREV_COMMIT" != "" ]; then
67 echo "No parent of $PREV_COMMIT was signed with a trusted key!" > /dev
/stderr
68 echo "Parents are:" > /dev
/stderr
69 PARENTS
=$
(git show
-s --format=format
:%P
$PREV_COMMIT)
70 for PARENT
in $PARENTS; do
71 git show
-s $PARENT > /dev
/stderr
74 echo "$CURRENT_COMMIT was not signed with a trusted key!" > /dev
/stderr
79 # We always verify the top of the tree
80 if [ "$VERIFY_TREE" = 1 -o "$PREV_COMMIT" = "" ]; then
84 for LINE
in $
(git ls-tree
--full-tree -r "$CURRENT_COMMIT"); do
87 echo "Repo contains symlinks" > /dev
/stderr
96 for FILE
in $
(git ls-tree
--full-tree -r --name-only "$CURRENT_COMMIT" | LC_ALL
=C
sort); do
97 if [ "$HAVE_GNU_SHA512" = 1 ]; then
98 HASH
=$
(git cat-file blob
"$CURRENT_COMMIT":"$FILE" | sha512sum |
{ read FIRST OTHER
; echo $FIRST; } )
100 HASH
=$
(git cat-file blob
"$CURRENT_COMMIT":"$FILE" | shasum
-a 512 |
{ read FIRST OTHER
; echo $FIRST; } )
102 [ "$FILE_HASHES" != "" ] && FILE_HASHES
="$FILE_HASHES"'
104 FILE_HASHES
="$FILE_HASHES$HASH $FILE"
107 if [ "$HAVE_GNU_SHA512" = 1 ]; then
108 TREE_HASH
="$(echo "$FILE_HASHES" | sha512sum)"
110 TREE_HASH
="$(echo "$FILE_HASHES" | shasum -a 512)"
113 MSG
="$(git show -s --format=format:%B "$CURRENT_COMMIT" | tail -n1)"
116 "Tree-SHA512: $TREE_HASH")
120 if [ "$HASH_MATCHES" = "0" ]; then
121 echo "Tree-SHA512 did not match for commit $CURRENT_COMMIT" > /dev
/stderr
126 PARENTS
=$
(git show
-s --format=format
:%P
"$CURRENT_COMMIT")
127 for PARENT
in $PARENTS; do
128 PREV_COMMIT
="$CURRENT_COMMIT"
129 CURRENT_COMMIT
="$PARENT"