Skip to content

Commit 379054c

Browse files
authored
verifier: Ensure that bundle digest and real digest match (#1652)
1 parent 19da9bc commit 379054c

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ All versions prior to 0.9.0 are untracked.
88

99
## [Unreleased]
1010

11+
### Fixed
12+
13+
* verification now ensures that artifact digest documented in bundle and the real digest match
14+
(this is a bundle consistency check: bundle signature was always verified over real digest)
15+
([#1652](https://github.com/sigstore/sigstore-python/pull/1652))
16+
1117
### Removed
1218

1319
* Removed support for Python 3.9 as it is end-of-life

sigstore/verify/verifier.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,24 @@ def verify_artifact(
470470
self._verify_common_signing_cert(bundle, policy)
471471

472472
hashed_input = sha256_digest(input_)
473+
bundle_signature = bundle._inner.message_signature
474+
if bundle_signature is None:
475+
raise VerificationError("Missing bundle message signature")
476+
477+
# signature is verified over input digest, but if the bundle documents the digest we still
478+
# want to ensure it matches the input digest:
479+
if (
480+
bundle_signature.message_digest is not None
481+
and hashed_input.digest != bundle_signature.message_digest.digest
482+
):
483+
raise VerificationError("Bundle message digest mismatch")
473484

474485
# (7): verify that the signature was signed by the public key in the signing certificate.
475486
try:
476487
signing_key = bundle.signing_certificate.public_key()
477488
signing_key = cast(ec.EllipticCurvePublicKey, signing_key)
478489
signing_key.verify(
479-
bundle._inner.message_signature.signature, # type: ignore[union-attr]
490+
bundle_signature.signature,
480491
hashed_input.digest,
481492
ec.ECDSA(hashed_input._as_prehashed()),
482493
)

test/unit/verify/test_verifier.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ def test_verifier_inconsistent_log_entry(signing_bundle, null_policy):
6464
verifier.verify_artifact(file.read_bytes(), bundle, null_policy)
6565

6666

67+
@pytest.mark.staging
68+
def test_verifier_digest_mismatch(signing_bundle, null_policy):
69+
"""The signature is over correct content, but digest documented in bundle is wrong"""
70+
(file, bundle) = signing_bundle("bundle.txt")
71+
bundle._inner.message_signature.message_digest.digest = b""
72+
73+
verifier = Verifier.staging()
74+
with pytest.raises(
75+
VerificationError,
76+
match="digest mismatch",
77+
):
78+
verifier.verify_artifact(file.read_bytes(), bundle, null_policy)
79+
80+
6781
@pytest.mark.staging
6882
def test_verifier_multiple_verifications(signing_materials, null_policy):
6983
verifier = Verifier.staging()

0 commit comments

Comments
 (0)