Skip to content

Specify sha256 in TSA request #1373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ All versions prior to 0.9.0 are untracked.

### Fixed

* TSA: Changed the Timestamp Authority requests to explicitly use sha256 for message digests.
[#1373](https://github.com/sigstore/sigstore-python/pull/1373)

* Fixed the certificate calidity period check for Timestamp Authorities (TSA).
Certificates need not have and end date, while still requiring a start date.
[#1368](https://github.com/sigstore/sigstore-python/pull/1368)
Expand Down
7 changes: 6 additions & 1 deletion sigstore/_internal/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
TimeStampResponse,
decode_timestamp_response,
)
from rfc3161_client.base import HashAlgorithm

from sigstore._internal import USER_AGENT

Expand Down Expand Up @@ -93,7 +94,11 @@ def request_timestamp(self, signature: bytes) -> TimeStampResponse:
# Build the timestamp request
try:
timestamp_request = (
TimestampRequestBuilder().data(signature).nonce(nonce=True).build()
TimestampRequestBuilder()
.hash_algorithm(HashAlgorithm.SHA256)
.data(signature)
.nonce(nonce=True)
.build()
)
except ValueError as error:
msg = f"invalid request: {error}"
Expand Down
8 changes: 8 additions & 0 deletions test/unit/internal/test_timestamping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import requests

from sigstore._internal.timestamp import TimestampAuthorityClient, TimestampError
from sigstore._utils import sha256_digest


@pytest.mark.timestamp_authority
Expand All @@ -23,6 +24,13 @@ def test_sign_request(self, tsa_url: str):
tsa = TimestampAuthorityClient(tsa_url)
response = tsa.request_timestamp(b"hello")
assert response
assert (
response.tst_info.message_imprint.message == sha256_digest(b"hello").digest
)
assert (
response.tst_info.message_imprint.hash_algorithm.dotted_string
== "2.16.840.1.101.3.4.2.1"
) # SHA256 OID

def test_sign_request_invalid_url(self):
tsa = TimestampAuthorityClient("http://fake-url")
Expand Down