You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

verify-commits.sh 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. DIR=$(dirname "$0")
  3. echo "Please verify all commits in the following list are not evil:"
  4. git log "$DIR"
  5. VERIFIED_ROOT=$(cat "${DIR}/trusted-git-root")
  6. IS_REVSIG_ALLOWED () {
  7. while read LINE; do
  8. [ "$LINE" = "$1" ] && return 0
  9. done < "${DIR}/allow-revsig-commits"
  10. return 1
  11. }
  12. HAVE_FAILED=false
  13. IS_SIGNED () {
  14. if [ $1 = $VERIFIED_ROOT ]; then
  15. return 0;
  16. fi
  17. if IS_REVSIG_ALLOWED "$1"; then
  18. export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG=1
  19. else
  20. export BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG=0
  21. fi
  22. if ! git -c "gpg.program=${DIR}/gpg.sh" verify-commit $1 > /dev/null 2>&1; then
  23. return 1;
  24. fi
  25. local PARENTS=$(git show -s --format=format:%P $1)
  26. for PARENT in $PARENTS; do
  27. if IS_SIGNED $PARENT > /dev/null; then
  28. return 0;
  29. fi
  30. done
  31. if ! "$HAVE_FAILED"; then
  32. echo "No parent of $1 was signed with a trusted key!" > /dev/stderr
  33. echo "Parents are:" > /dev/stderr
  34. for PARENT in $PARENTS; do
  35. git show -s $PARENT > /dev/stderr
  36. done
  37. HAVE_FAILED=true
  38. fi
  39. return 1;
  40. }
  41. if [ x"$1" = "x" ]; then
  42. TEST_COMMIT="HEAD"
  43. else
  44. TEST_COMMIT="$1"
  45. fi
  46. IS_SIGNED "$TEST_COMMIT"
  47. RES=$?
  48. if [ "$RES" = 1 ]; then
  49. if ! "$HAVE_FAILED"; then
  50. echo "$TEST_COMMIT was not signed with a trusted key!"
  51. fi
  52. else
  53. echo "There is a valid path from $TEST_COMMIT to $VERIFIED_ROOT where all commits are signed!"
  54. fi
  55. exit $RES