Skip to content

Commit 2199d9b

Browse files
make TSA validity end optional (#1368)
* no trailing slash for post to /entries Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com> * end date optional Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com> * Revert "no trailing slash for post to /entries" This reverts commit 79a6d31. Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com> * lint Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com> * start is not optional Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com> * add changelog Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com> * link to PR Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com> --------- Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com> Signed-off-by: Ramon Petgrave <32398091+ramonpetgrave64@users.noreply.github.com>
1 parent 7b0100b commit 2199d9b

File tree

4 files changed

+25
-36
lines changed

4 files changed

+25
-36
lines changed

CHANGELOG.md

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

1111
### Fixed
1212

13+
* Fixed the certificate calidity period check for Timestamp Authorities (TSA).
14+
Certificates need not have and end date, while still requiring a start date.
15+
[#1368](https://github.com/sigstore/sigstore-python/pull/1368)
16+
1317
* API: Make Rekor APIs compatible with Rekor v2 by removing trailing slashes
1418
from endpoints ([#1366](https://github.com/sigstore/sigstore-python/pull/1366))
1519

sigstore/_internal/trust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _verify(self) -> None:
253253
raise Error("missing a certificate in Certificate Authority")
254254

255255
@property
256-
def validity_period_start(self) -> datetime | None:
256+
def validity_period_start(self) -> datetime:
257257
"""
258258
Validity period start.
259259
"""

sigstore/verify/verifier.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,19 @@ def _verify_signed_timestamp(
150150

151151
if (
152152
certificate_authority.validity_period_start
153-
and certificate_authority.validity_period_end
153+
<= timestamp_response.tst_info.gen_time
154+
) and (
155+
not certificate_authority.validity_period_end
156+
or timestamp_response.tst_info.gen_time
157+
< certificate_authority.validity_period_end
154158
):
155-
if (
156-
certificate_authority.validity_period_start
157-
<= timestamp_response.tst_info.gen_time
158-
< certificate_authority.validity_period_end
159-
):
160-
return TimestampVerificationResult(
161-
source=TimestampSource.TIMESTAMP_AUTHORITY,
162-
time=timestamp_response.tst_info.gen_time,
163-
)
164-
165-
_logger.debug(
166-
"Unable to verify Timestamp because not in CA time range."
167-
)
168-
else:
169-
_logger.debug(
170-
"Unable to verify Timestamp because no validity provided."
159+
return TimestampVerificationResult(
160+
source=TimestampSource.TIMESTAMP_AUTHORITY,
161+
time=timestamp_response.tst_info.gen_time,
171162
)
172163

164+
_logger.debug("Unable to verify Timestamp because not in CA time range.")
165+
173166
return None
174167

175168
def _verify_timestamp_authority(

test/unit/verify/test_verifier.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ def test_verifier_verify_timestamp(self, verifier, asset, null_policy):
212212
null_policy,
213213
)
214214

215+
def test_verifier_no_validity_end(self, verifier, asset, null_policy):
216+
verifier._trusted_root.get_timestamp_authorities()[
217+
0
218+
]._inner.valid_for.end = None
219+
verifier.verify_artifact(
220+
asset("tsa/bundle.txt").read_bytes(),
221+
Bundle.from_json(asset("tsa/bundle.txt.sigstore").read_bytes()),
222+
null_policy,
223+
)
224+
215225
def test_verifier_without_timestamp(
216226
self, verifier, asset, null_policy, monkeypatch
217227
):
@@ -241,24 +251,6 @@ def test_verifier_duplicate_timestamp(self, verifier, asset, null_policy):
241251
null_policy,
242252
)
243253

244-
def test_verifier_no_validity(self, caplog, verifier, asset, null_policy):
245-
verifier._trusted_root.get_timestamp_authorities()[
246-
0
247-
]._inner.valid_for.end = None
248-
249-
with caplog.at_level(logging.DEBUG, logger="sigstore.verify.verifier"):
250-
with pytest.raises(VerificationError, match="not enough timestamps"):
251-
verifier.verify_artifact(
252-
asset("tsa/bundle.txt").read_bytes(),
253-
Bundle.from_json(asset("tsa/bundle.txt.sigstore").read_bytes()),
254-
null_policy,
255-
)
256-
257-
assert (
258-
"Unable to verify Timestamp because no validity provided."
259-
== caplog.records[0].message
260-
)
261-
262254
def test_verifier_outside_validity_range(
263255
self, caplog, verifier, asset, null_policy
264256
):

0 commit comments

Comments
 (0)