Merge bitcoin/bitcoin#36293: contrib: exclude inactive keys from the binary quorum by default
What changed, and why it matters
This change fixes a flaw in Bitcoin Core's release-binary verification helper script. Previously, signatures made with expired or revoked developer keys were counted as valid toward the required number of 'good' signatures. That meant an attacker who had obtained old, expired, or revoked signing keys could potentially make a fake release look properly signed. The patch stops counting revoked signatures entirely and stops counting expired signatures by default, while adding a warning and an optional override for verifying older releases.
Users who verify Bitcoin Core releases with contrib/verify-binaries/verify.py should update to the patched version. They should refresh their GPG keyring before verifying releases and avoid using --allow-expired unless intentionally verifying an older release. Developers should review local keyring hygiene and keyserver privacy considerations noted in the updated README.
Security signals we found
Logic flaw in trust threshold counting
Expired/revoked signatures previously treated as good signatures
Responsible disclosure by external Red Team
Fix excludes revoked signatures unconditionally
Fix excludes expired signatures by default with opt-in override
Adds warnings and JSON reporting for expired/revoked signatures
Evidence from the diff
The patch modifies contrib/verify-binaries/verify.py so that GnuPG status lines EXPKEYSIG, REVKEYSIG, and KEYREVOKED are tracked per signature. Revoked signatures are always excluded from the min_good_sigs threshold and logged as warnings. Expired signatures are also excluded by default, but can be counted via –allow-expired or BINVERIFY_ALLOW_EXPIRED=1 for historical verification. The verify_shasums_signature return tuple gains an expired_sigs list, and JSON output includes an expired_sigs field. Tests are added to characterize the inactive-key quorum behavior.
Changed components
contrib/verify-binaries/verify.pycontrib/verify-binaries/test.pycontrib/verify-binaries/README.mdInspect captured patch +125 / −15
### contrib/verify-binaries/README.md
@@ -14,6 +14,9 @@ builder-keys](https://github.com/bitcoin-core/guix.sigs/tree/main/builder-keys)
decide which of these keys you would like to trust. For each key you want to trust, you
must obtain that key for your local GPG installation.
+A stale local GPG keyring may miss revocations.
+Keyserver updates can reveal which keys you request.
+
You can obtain these keys by
- through a browser using a key server (e.g. keyserver.ubuntu.com),
- manually using the `gpg --keyserver <url> --recv-keys <key>` command, or
@@ -27,7 +30,12 @@ signature file `SHA256SUMS.asc` from https://bitcoincore.org and https://bitcoin
It first checks if the checksum file is valid based upon a plurality of signatures, and
then downloads the release files specified in the checksum file, and checks if the
-hashes of the release files are as expected.
+hashes of the release files are as expected. Signatures from keys that GPG reports as
+expired or revoked (`EXPKEYSIG`, `REVKEYSIG`, or `KEYREVOKED`) are reported as `EXPIRED SIGNATURE` or
+`REVOKED SIGNATURE` warnings and do not count toward that plurality by default, regardless of when
+the signature was made. For older releases, `--allow-expired` or `BINVERIFY_ALLOW_EXPIRED=1`
+also counts expired signatures. Revoked ones never count. Successful JSON output lists
+expired signatures separately in `expired_sigs`.
If we encounter pubkeys in the signature file that we do not recognize, the script
can prompt the user as to whether they'd like to download the pubkeys. To enable
@@ -46,6 +54,12 @@ Validate releases with default settings:
./contrib/verify-binaries/verify.py pub 22.0-rc3
```
+Include expired keys when verifying an older release:
+
+```sh
+./contrib/verify-binaries/verify.py --allow-expired pub 22.0
+```
+
Get JSON output and don't prompt for user input (no auto key import):
```sh
### contrib/verify-binaries/test.py
@@ -1,13 +1,18 @@
#!/usr/bin/env python3
import json
+import os
import sys
import subprocess
from pathlib import Path
+from unittest import mock
+
+import verify
def main():
"""Tests ordered roughly from faster to slower."""
+ test_inactive_signature_quorum()
expect_code(run_verify("", "pub", '0.32'), 4, "Nonexistent version should fail")
expect_code(run_verify("", "pub", '0.32.awefa.12f9h'), 11, "Malformed version should fail")
expect_code(run_verify('--min-good-sigs 20', "pub", "22.0"), 9, "--min-good-sigs 20 should fail")
@@ -24,6 +29,7 @@ def main():
expect_code(_220_x86_64_linux_gnu, 0, "22.0-x86_64-linux-gnu.tar.gz should succeed")
v = result['verified_binaries']
assert result['good_trusted_sigs']
+ assert isinstance(result['expired_sigs'], list)
assert len(v) == 1
assert v['bitcoin-22.0-x86_64-linux-gnu.tar.gz'] == '59ebd25dd82a51638b7a6bb914586201e67db67b919b2a1ff08925a7936d1b16'
@@ -44,6 +50,72 @@ def main():
assert v['bitcoin-22.0-x86_64-linux-gnu.tar.gz'] == '59ebd25dd82a51638b7a6bb914586201e67db67b919b2a1ff08925a7936d1b16'
+@mock.patch.object(verify.log, 'disabled', new=True)
+def test_inactive_signature_quorum():
+ active = 'GOODSIG AAAABBBBCCCCDDDD Active Builder'
+ expired = 'EXPKEYSIG 1111222233334444 Expired Builder'
+ revoked = 'REVKEYSIG 5555666677778888 Revoked Builder'
+ revoked_expired = 'EXPKEYSIG 9999AAAABBBBCCCC Revoked Expired Builder\n[GNUPG:] KEYREVOKED'
+
+ def gpg_output(*sigs: str) -> str:
+ return '\n'.join(f'[GNUPG:] NEWSIG\n[GNUPG:] {sig}' for sig in sigs)
+
+ # Revocation takes precedence regardless of the order GnuPG reports the statuses in
+ for sig in (revoked_expired, f'KEYREVOKED\n[GNUPG:] {expired}'):
+ assert verify.parse_gpg_result(gpg_output(sig).splitlines())[0][0].status == 'revoked'
+
+ def verify_fake_gpg(parser, options: list[str], *sigs: str, min_good_sigs: int = 1):
+ # Every key is explicitly trusted, so only its inactive status can exclude it
+ args = parser.parse_args([
+ *options,
+ '--min-good-sigs', str(min_good_sigs),
+ '--trusted-keys', ','.join(sig.split()[1] for sig in (active, expired, revoked, revoked_expired)),
+ 'bin', verify.SUMS_FILENAME,
+ ])
+ with mock.patch.object(verify, 'verify_with_gpg', return_value=(0, gpg_output(*sigs))):
+ return verify.verify_shasums_signature(verify.SIGNATUREFILENAME, verify.SUMS_FILENAME, args)
+
+ for env, options, allow_expired in (
+ ({}, [], False),
+ ({}, ['--allow-expired'], True),
+ ({'BINVERIFY_ALLOW_EXPIRED': '0'}, [], False),
+ ({'BINVERIFY_ALLOW_EXPIRED': '0'}, ['--allow-expired'], True),
+ ({'BINVERIFY_ALLOW_EXPIRED': '1'}, [], True),
+ ({'BINVERIFY_ALLOW_EXPIRED': '1'}, ['--allow-expired'], True),
+ ):
+ with mock.patch.dict(os.environ, env, clear=True):
+ parser = verify.build_parser()
+
+ result, good_trusted, good_untrusted, _, _, expired_sigs = verify_fake_gpg(parser, options, expired)
+ assert result == (verify.ReturnCode.SUCCESS if allow_expired else verify.ReturnCode.NOT_ENOUGH_GOOD_SIGS)
+ assert good_trusted == []
+ assert good_untrusted == []
+ assert [sig.key for sig in expired_sigs] == ['1111222233334444']
+
+ result, *_, expired_sigs = verify_fake_gpg(parser, options, revoked)
+ assert result == verify.ReturnCode.NOT_ENOUGH_GOOD_SIGS
+ assert expired_sigs == []
+
+ result, *_, expired_sigs = verify_fake_gpg(parser, options, revoked_expired)
+ assert result == verify.ReturnCode.NOT_ENOUGH_GOOD_SIGS
+ assert expired_sigs == []
+
+ result, good_trusted, good_untrusted, _, _, expired_sigs = verify_fake_gpg(parser, options, active, expired, revoked)
+ assert result == verify.ReturnCode.SUCCESS
+ assert [sig.key for sig in good_trusted] == ['AAAABBBBCCCCDDDD']
+ assert good_untrusted == []
+ assert [str(sig) for sig in expired_sigs] == [
+ "SigData('1111222233334444', 'Expired Builder', trusted=False, status='expired')"]
+
+ result, *_ = verify_fake_gpg(parser, options, active, expired, revoked, min_good_sigs=2)
+ assert result == (verify.ReturnCode.SUCCESS if allow_expired else verify.ReturnCode.NOT_ENOUGH_GOOD_SIGS)
+
+ result, *_ = verify_fake_gpg(parser, options, active, expired, revoked, min_good_sigs=3)
+ assert result == verify.ReturnCode.NOT_ENOUGH_GOOD_SIGS
+
+ print("✓ 'Inactive signature quorum' passed")
+
+
def run_verify(global_args: str, command: str, command_args: str) -> subprocess.CompletedProcess:
maybe_here = Path.cwd() / 'verify.py'
path = maybe_here if maybe_here.exists() else Path.cwd() / 'contrib' / 'verify-binaries' / 'verify.py'
### contrib/verify-binaries/verify.py
@@ -185,13 +185,17 @@ def line_begins_with(patt: str, line: str) -> t.Optional[re.Match]:
elif line_begins_with(r"EXPKEYSIG(?:\s|$)", line):
curr_sigdata.key, curr_sigdata.name = line.split(maxsplit=3)[2:4]
curr_sigs = good_sigs
- curr_sigdata.status = "expired"
+ if curr_sigdata.status != "revoked":
+ curr_sigdata.status = "expired"
elif line_begins_with(r"REVKEYSIG(?:\s|$)", line):
curr_sigdata.key, curr_sigdata.name = line.split(maxsplit=3)[2:4]
curr_sigs = good_sigs
curr_sigdata.status = "revoked"
+ elif line_begins_with(r"KEYREVOKED(?:\s|$)", line):
+ curr_sigdata.status = "revoked"
+
elif line_begins_with(r"BADSIG(?:\s|$)", line):
curr_sigdata.key, curr_sigdata.name = line.split(maxsplit=3)[2:4]
curr_sigs = bad_sigs
@@ -341,7 +345,7 @@ def prompt_yn(prompt) -> bool:
def verify_shasums_signature(
signature_file_path: str, sums_file_path: str, args: argparse.Namespace
) -> tuple[
- ReturnCode, list[SigData], list[SigData], list[SigData], list[SigData]
+ ReturnCode, list[SigData], list[SigData], list[SigData], list[SigData], list[SigData]
]:
min_good_sigs = args.min_good_sigs
gpg_allowed_codes = [0, 2] # 2 is returned when untrusted signatures are present.
@@ -355,7 +359,7 @@ def verify_shasums_signature(
log.critical(f"unexpected GPG exit code ({gpg_retval})")
log.error(f"gpg output:\n{indent(gpg_output)}")
- return (ReturnCode.INTEGRITY_FAILURE, [], [], [], [])
+ return (ReturnCode.INTEGRITY_FAILURE, [], [], [], [], [])
# Decide which keys we trust, though not "trust" in the GPG sense, but rather
# which pubkeys convince us that this sums file is legitimate. In other words,
@@ -367,9 +371,21 @@ def verify_shasums_signature(
# Tally signatures and make sure we have enough goods to fulfill
# our threshold.
- good_trusted = [sig for sig in good if sig.trusted or sig.key in trusted_keys]
- good_untrusted = [sig for sig in good if sig not in good_trusted]
+ good_trusted: list[SigData] = []
+ good_untrusted: list[SigData] = []
+ expired: list[SigData] = []
+ for sig in good:
+ if not sig.status:
+ (good_trusted if sig.trusted or sig.key in trusted_keys else good_untrusted).append(sig)
+ elif sig.status == 'revoked':
+ log.warning(f"REVOKED SIGNATURE: {sig}")
+ else:
+ assert sig.status == 'expired', sig
+ expired.append(sig)
+ log.warning(f"EXPIRED SIGNATURE: {sig}")
num_trusted = len(good_trusted) + len(good_untrusted)
+ if args.allow_expired:
+ num_trusted += len(expired)
log.info(f"got {num_trusted} good signatures")
if num_trusted < min_good_sigs:
@@ -384,24 +400,21 @@ def verify_shasums_signature(
"not enough trusted sigs to meet threshold "
f"({num_trusted} vs. {min_good_sigs})")
- return (ReturnCode.NOT_ENOUGH_GOOD_SIGS, [], [], [], [])
+ return (ReturnCode.NOT_ENOUGH_GOOD_SIGS, [], [], [], [], expired)
for sig in good_trusted:
log.info(f"GOOD SIGNATURE: {sig}")
for sig in good_untrusted:
log.info(f"GOOD SIGNATURE (untrusted): {sig}")
- for sig in [sig for sig in good if sig.status == 'expired']:
- log.warning(f"key {sig.key} for {sig.name} is expired")
-
for sig in bad:
log.warning(f"BAD SIGNATURE: {sig}")
for sig in unknown:
log.warning(f"UNKNOWN SIGNATURE: {sig}")
- return (ReturnCode.SUCCESS, good_trusted, good_untrusted, unknown, bad)
+ return (ReturnCode.SUCCESS, good_trusted, good_untrusted, unknown, bad, expired)
def parse_sums_file(sums_file_path: str, filename_filter: list[str]) -> list[list[str]]:
@@ -480,7 +493,7 @@ def cleanup():
return got_sums_status
# Verify the signature on the SHA256SUMS file
- sigs_status, good_trusted, good_untrusted, unknown, bad = verify_shasums_signature(SIGNATUREFILENAME, SUMS_FILENAME, args)
+ sigs_status, good_trusted, good_untrusted, unknown, bad, expired = verify_shasums_signature(SIGNATUREFILENAME, SUMS_FILENAME, args)
if sigs_status != ReturnCode.SUCCESS:
if sigs_status == ReturnCode.INTEGRITY_FAILURE:
cleanup()
@@ -534,6 +547,7 @@ def cleanup():
'good_untrusted_sigs': [str(s) for s in good_untrusted],
'unknown_sigs': [str(s) for s in unknown],
'bad_sigs': [str(s) for s in bad],
+ 'expired_sigs': [str(s) for s in expired],
'verified_binaries': files_to_hashes,
}
print(json.dumps(output, indent=2))
@@ -557,7 +571,7 @@ def verify_binaries_handler(args: argparse.Namespace) -> ReturnCode:
sums_sig_path = Path(args.sums_file).with_suffix(".asc")
# Verify the signature on the SHA256SUMS file
- sigs_status, good_trusted, good_untrusted, unknown, bad = verify_shasums_signature(str(sums_sig_path), args.sums_file, args)
+ sigs_status, good_trusted, good_untrusted, unknown, bad, expired = verify_shasums_signature(str(sums_sig_path), args.sums_file, args)
if sigs_status != ReturnCode.SUCCESS:
return sigs_status
@@ -598,6 +612,7 @@ def verify_binaries_handler(args: argparse.Namespace) -> ReturnCode:
'good_untrusted_sigs': [str(s) for s in good_untrusted],
'unknown_sigs': [str(s) for s in unknown],
'bad_sigs': [str(s) for s in bad],
+ 'expired_sigs': [str(s) for s in expired],
'verified_binaries': files_to_hashes,
"missing_binaries": missing_files,
}
@@ -611,7 +626,7 @@ def verify_binaries_handler(args: argparse.Namespace) -> ReturnCode:
return ReturnCode.SUCCESS
-def main():
+def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'-v', '--verbose', action='store_true',
@@ -632,6 +647,11 @@ def main():
help=(
'The minimum number of good signatures to require successful termination.'),
)
+ parser.add_argument(
+ '--allow-expired', action='store_true',
+ default=bool_from_env('BINVERIFY_ALLOW_EXPIRED'),
+ help='Count signatures from expired keys toward the threshold when verifying older releases; revoked keys remain excluded',
+ )
parser.add_argument(
'--keyserver', action='store', nargs='?',
default=os.environ.get('BINVERIFY_KEYSERVER', 'hkps://keys.openpgp.org'),
@@ -679,7 +699,11 @@ def main():
help="Path to a binary distribution file to verify. Can be specified multiple times for multiple files to verify."
)
- args = parser.parse_args()
+ return parser
+
+
+def main():
+ args = build_parser().parse_args()
if args.quiet:
log.setLevel(logging.WARNING)
Why this scored 62/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.