Skip to content

Commit

Permalink
Better test for the Timestamp Threshold
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis <[email protected]>
  • Loading branch information
DarkaMaul committed Nov 12, 2024
1 parent 5979cf1 commit 5f23327
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 6 additions & 4 deletions sigstore/verify/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
# From https://github.com/sigstore/sigstore-go/blob/e92142f0734064ebf6001f188b7330a1212245fe/pkg/verify/tsa.go#L29
MAX_ALLOWED_TIMESTAMP: int = 32

# When verifying a timestamp, this threshold represents the minimum number of required
# timestamps to consider a signature valid.
VERIFY_TIMESTAMP_THRESHOLD: int = 1


class Verifier:
"""
Expand All @@ -82,8 +86,6 @@ def __init__(self, *, rekor: RekorClient, trusted_root: TrustedRoot):
]
self._trusted_root = trusted_root

self.verify_timestamp_threshold: int = 1

@classmethod
def production(cls, *, offline: bool = False) -> Verifier:
"""
Expand Down Expand Up @@ -249,10 +251,10 @@ def _verify_common_signing_cert(
verified_timestamp = self._verify_timestamp_authority(bundle)
# The threshold is set to (1) by default but kept as a variable to allow
# this value to change
if verified_timestamp < self.verify_timestamp_threshold:
if verified_timestamp < VERIFY_TIMESTAMP_THRESHOLD:
msg = (
f"Not enough Timestamp validated to meet the Validation "
f"Threshold ({verified_timestamp}/{self.verify_timestamp_threshold})"
f"Threshold ({verified_timestamp}/{VERIFY_TIMESTAMP_THRESHOLD})"
)
raise VerificationError(msg)

Expand Down
3 changes: 3 additions & 0 deletions test/assets/tsa/bundle.txt.sigstore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
"rfc3161Timestamps": [
{
"signedTimestamp": "MIIEgDADAgEAMIIEdwYJKoZIhvcNAQcCoIIEaDCCBGQCAQMxDTALBglghkgBZQMEAgEwgc8GCyqGSIb3DQEJEAEEoIG/BIG8MIG5AgEBBgkrBgEEAYO/MAIwMTANBglghkgBZQMEAgEFAAQgF2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s6ju9Z+v0joTcaiD0F0R+YEh6xWB9+71jkg57qsJqCo2owaDAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFHr84ZbK4DrUPCzsEQbBjdT5OnRBMB8GA1UdIwQYMBaAFCkN6IAfJdG+HSOn1pSw9FnTuO1RMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMIMAoGCCqGSM49BAMCA0gAMEUCIAha0d6Cgx9r/S1itcwzCCLpj6Oddp7XHyQ6c9iskT4GAiEA7HrjYsLE4XjdsUA6OgsoO7h5IzkbsVEYUAnKEFchoKYxggHdMIIB2QIBATBIMDAxDjAMBgNVBAoTBWxvY2FsMR4wHAYDVQQDExVUZXN0IFRTQSBJbnRlcm1lZGlhdGUCFC5NT4yLWYjkqCPph6nZEn3ESGEtMAsGCWCGSAFlAwQCAaCCASYwGgYJKoZIhvcNAQkDMQ0GCyqGSIb3DQEJEAEEMBwGCSqGSIb3DQEJBTEPFw0yNDEwMzExMzMxNDRaMC8GCSqGSIb3DQEJBDEiBCDFl7LJGj2Ly6mrN3rzvyj+h0hRUK4/mvHEgTXCpy9K3DCBuAYLKoZIhvcNAQkQAi8xgagwgaUwgaIwgZ8wDQYJYIZIAWUDBAIDBQAEQPrmk1cW2IBeZnRAWYlt35rZRL+e43TUQ6C2cqGOEGYZGS5we3Yz46pM7dijeAZkn1JVS0rOf6W1TsFRrwdApP0wTDA0pDIwMDEOMAwGA1UEChMFbG9jYWwxHjAcBgNVBAMTFVRlc3QgVFNBIEludGVybWVkaWF0ZQIULk1PjItZiOSoI+mHqdkSfcRIYS0wCgYIKoZIzj0EAwIERzBFAiEAlNj866pok1LTFRuzxIfu+h/KJ/kHmKnUfNF4PL2cdgsCIEKRudmJVaifKu72aNwiMB+P1YicRzgl/QGQPNAYDxUe"
}
]
}
Expand Down
7 changes: 4 additions & 3 deletions test/unit/verify/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def verify_function(*args):
null_policy,
)

assert len(caplog.records) == 2
assert caplog.records[0].message == "Unable to verify Timestamp with CA."

def test_verifier_no_authorities(self, asset, null_policy):
Expand All @@ -299,8 +298,10 @@ def test_verifier_no_authorities(self, asset, null_policy):
null_policy,
)

def test_verifier_not_enough_timestamp(self, verifier, asset, null_policy):
verifier.verify_timestamp_threshold = 2
def test_verifier_not_enough_timestamp(
self, verifier, asset, null_policy, monkeypatch
):
monkeypatch.setattr("sigstore.verify.verifier.VERIFY_TIMESTAMP_THRESHOLD", 2)
with pytest.raises(VerificationError, match="Not enough Timestamp"):
verifier.verify_artifact(
asset("tsa/bundle.txt").read_bytes(),
Expand Down

0 comments on commit 5f23327

Please sign in to comment.