Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / contrib / verify-commits / verify-commits.sh
blob532b97a438f6d39e857afe27ab034c8deaa9c826
1 #!/bin/sh
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.
6 DIR=$(dirname "$0")
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")
15 HAVE_GNU_SHA512=1
16 [ ! -x "$(which sha512sum)" ] && HAVE_GNU_SHA512=0
18 if [ x"$1" = "x" ]; then
19 CURRENT_COMMIT="HEAD"
20 else
21 CURRENT_COMMIT="$1"
24 if [ "${CURRENT_COMMIT#* }" != "$CURRENT_COMMIT" ]; then
25 echo "Commit must not contain spaces?" > /dev/stderr
26 exit 1
29 VERIFY_TREE=0
30 if [ x"$2" = "x--tree-checks" ]; then
31 VERIFY_TREE=1
34 NO_SHA1=1
35 PREV_COMMIT=""
36 INITIAL_COMMIT="${CURRENT_COMMIT}"
38 while true; do
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!"
41 exit 0
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
48 VERIFY_TREE=0
49 NO_SHA1=0
52 if [ "$NO_SHA1" = "1" ]; then
53 export BITCOIN_VERIFY_COMMITS_ALLOW_SHA1=0
54 else
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
60 else
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
71 done
72 else
73 echo "$CURRENT_COMMIT was not signed with a trusted key!" > /dev/stderr
75 exit 1
78 # We always verify the top of the tree
79 if [ "$VERIFY_TREE" = 1 -o "$PREV_COMMIT" = "" ]; then
80 IFS_CACHE="$IFS"
81 IFS='
83 for LINE in $(git ls-tree --full-tree -r "$CURRENT_COMMIT"); do
84 case "$LINE" in
85 "12"*)
86 echo "Repo contains symlinks" > /dev/stderr
87 IFS="$IFS_CACHE"
88 exit 1
90 esac
91 done
92 IFS="$IFS_CACHE"
94 FILE_HASHES=""
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; } )
98 else
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"
104 done
106 if [ "$HAVE_GNU_SHA512" = 1 ]; then
107 TREE_HASH="$(echo "$FILE_HASHES" | sha512sum)"
108 else
109 TREE_HASH="$(echo "$FILE_HASHES" | shasum -a 512)"
111 HASH_MATCHES=0
112 MSG="$(git show -s --format=format:%B "$CURRENT_COMMIT" | tail -n1)"
114 case "$MSG -" in
115 "Tree-SHA512: $TREE_HASH")
116 HASH_MATCHES=1;;
117 esac
119 if [ "$HASH_MATCHES" = "0" ]; then
120 echo "Tree-SHA512 did not match for commit $CURRENT_COMMIT" > /dev/stderr
121 exit 1
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"
129 break
130 done
131 done