mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 14:37:42 -03:00
verify-commits: Move trusted-keys valid sig check into verify-commits itself
Instead of having gpg.sh check against the trusted keys for a valid signature, do it inside of verify-commits itself. This also allows us to use the same trusted-keys throughout the verify-commits.py check rather than it possibly being modified during the clean merge check.
This commit is contained in:
parent
75f0e0b607
commit
53b07b2b47
2 changed files with 19 additions and 38 deletions
|
@ -5,12 +5,9 @@
|
||||||
|
|
||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
INPUT=$(cat /dev/stdin)
|
INPUT=$(cat /dev/stdin)
|
||||||
VALID=false
|
|
||||||
REVSIG=false
|
|
||||||
IFS='
|
|
||||||
'
|
|
||||||
if [ "$BITCOIN_VERIFY_COMMITS_ALLOW_SHA1" = 1 ]; then
|
if [ "$BITCOIN_VERIFY_COMMITS_ALLOW_SHA1" = 1 ]; then
|
||||||
GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null)"
|
printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
|
||||||
|
exit $?
|
||||||
else
|
else
|
||||||
# Note how we've disabled SHA1 with the --weak-digest option, disabling
|
# Note how we've disabled SHA1 with the --weak-digest option, disabling
|
||||||
# signatures - including selfsigs - that use SHA1. While you might think that
|
# signatures - including selfsigs - that use SHA1. While you might think that
|
||||||
|
@ -20,12 +17,12 @@ else
|
||||||
# an attacker could construct a pull-req that results in a commit object that
|
# an attacker could construct a pull-req that results in a commit object that
|
||||||
# they've created a collision for. Not the most likely attack, but preventing
|
# they've created a collision for. Not the most likely attack, but preventing
|
||||||
# it is pretty easy so we do so as a "belt-and-suspenders" measure.
|
# it is pretty easy so we do so as a "belt-and-suspenders" measure.
|
||||||
GPG_RES=""
|
|
||||||
for LINE in $(gpg --version); do
|
for LINE in $(gpg --version); do
|
||||||
case "$LINE" in
|
case "$LINE" in
|
||||||
"gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*)
|
"gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*)
|
||||||
echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr
|
echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr
|
||||||
GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null)"
|
printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
|
||||||
|
exit $?
|
||||||
;;
|
;;
|
||||||
# We assume if you're running 2.1+, you're probably running 2.1.10+
|
# We assume if you're running 2.1+, you're probably running 2.1.10+
|
||||||
# gpg will fail otherwise
|
# gpg will fail otherwise
|
||||||
|
@ -33,33 +30,6 @@ else
|
||||||
# gpg will fail otherwise
|
# gpg will fail otherwise
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[ "$GPG_RES" = "" ] && GPG_RES="$(printf '%s\n' "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null)"
|
printf '%s\n' "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null
|
||||||
fi
|
exit $?
|
||||||
for LINE in $GPG_RES; do
|
|
||||||
case "$LINE" in
|
|
||||||
"[GNUPG:] VALIDSIG "*)
|
|
||||||
while read KEY; do
|
|
||||||
[ "${LINE#?GNUPG:? VALIDSIG * * * * * * * * * }" = "$KEY" ] && VALID=true
|
|
||||||
done < ./contrib/verify-commits/trusted-keys
|
|
||||||
;;
|
|
||||||
"[GNUPG:] REVKEYSIG "*)
|
|
||||||
[ "$BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG" != 1 ] && exit 1
|
|
||||||
REVSIG=true
|
|
||||||
GOODREVSIG="[GNUPG:] GOODSIG ${LINE#* * *}"
|
|
||||||
;;
|
|
||||||
"[GNUPG:] EXPKEYSIG "*)
|
|
||||||
[ "$BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG" != 1 ] && exit 1
|
|
||||||
REVSIG=true
|
|
||||||
GOODREVSIG="[GNUPG:] GOODSIG ${LINE#* * *}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
if ! $VALID; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if $VALID && $REVSIG; then
|
|
||||||
printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null | grep "^\[GNUPG:\] \(NEWSIG\|SIG_ID\|VALIDSIG\)"
|
|
||||||
echo "$GOODREVSIG"
|
|
||||||
else
|
|
||||||
printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -92,6 +92,8 @@ def main():
|
||||||
unclean_merge_allowed = f.read().splitlines()
|
unclean_merge_allowed = f.read().splitlines()
|
||||||
with open(dirname + "/allow-incorrect-sha512-commits", "r", encoding="utf8") as f:
|
with open(dirname + "/allow-incorrect-sha512-commits", "r", encoding="utf8") as f:
|
||||||
incorrect_sha512_allowed = f.read().splitlines()
|
incorrect_sha512_allowed = f.read().splitlines()
|
||||||
|
with open(dirname + "/trusted-keys", "r", encoding="utf8") as f:
|
||||||
|
trusted_keys = f.read().splitlines()
|
||||||
|
|
||||||
# Set commit and branch and set variables
|
# Set commit and branch and set variables
|
||||||
current_commit = args.commit
|
current_commit = args.commit
|
||||||
|
@ -120,10 +122,19 @@ def main():
|
||||||
no_sha1 = False
|
no_sha1 = False
|
||||||
|
|
||||||
os.environ['BITCOIN_VERIFY_COMMITS_ALLOW_SHA1'] = "0" if no_sha1 else "1"
|
os.environ['BITCOIN_VERIFY_COMMITS_ALLOW_SHA1'] = "0" if no_sha1 else "1"
|
||||||
os.environ['BITCOIN_VERIFY_COMMITS_ALLOW_REVSIG'] = "1" if current_commit in revsig_allowed else "0"
|
allow_revsig = current_commit in revsig_allowed
|
||||||
|
|
||||||
# Check that the commit (and parents) was signed with a trusted key
|
# Check that the commit (and parents) was signed with a trusted key
|
||||||
if subprocess.call([GIT, '-c', 'gpg.program={}/gpg.sh'.format(dirname), 'verify-commit', current_commit], stdout=subprocess.DEVNULL):
|
valid_sig = False
|
||||||
|
verify_res = subprocess.run([GIT, '-c', 'gpg.program={}/gpg.sh'.format(dirname), 'verify-commit', "--raw", current_commit], capture_output=True)
|
||||||
|
for line in verify_res.stderr.decode().splitlines():
|
||||||
|
if line.startswith("[GNUPG:] VALIDSIG "):
|
||||||
|
key = line.split(" ")[-1]
|
||||||
|
valid_sig = key in trusted_keys
|
||||||
|
elif (line.startswith("[GNUPG:] REVKEYSIG ") or line.startswith("[GNUPG:] EXPKEYSIG ")) and not allow_revsig:
|
||||||
|
valid_sig = False
|
||||||
|
break
|
||||||
|
if not valid_sig:
|
||||||
if prev_commit != "":
|
if prev_commit != "":
|
||||||
print("No parent of {} was signed with a trusted key!".format(prev_commit), file=sys.stderr)
|
print("No parent of {} was signed with a trusted key!".format(prev_commit), file=sys.stderr)
|
||||||
print("Parents are:", file=sys.stderr)
|
print("Parents are:", file=sys.stderr)
|
||||||
|
|
Loading…
Add table
Reference in a new issue