Skip to content

Commit 572ccac

Browse files
Specify sha256 in TSA request (#1373)
* request timestamp with sha256 Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
1 parent ad9a001 commit 572ccac

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

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

1111
### Fixed
1212

13+
* TSA: Changed the Timestamp Authority requests to explicitly use sha256 for message digests.
14+
[#1373](https://github.com/sigstore/sigstore-python/pull/1373)
15+
1316
* Fixed the certificate calidity period check for Timestamp Authorities (TSA).
1417
Certificates need not have and end date, while still requiring a start date.
1518
[#1368](https://github.com/sigstore/sigstore-python/pull/1368)

sigstore/_internal/timestamp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
TimeStampResponse,
2727
decode_timestamp_response,
2828
)
29+
from rfc3161_client.base import HashAlgorithm
2930

3031
from sigstore._internal import USER_AGENT
3132

@@ -93,7 +94,11 @@ def request_timestamp(self, signature: bytes) -> TimeStampResponse:
9394
# Build the timestamp request
9495
try:
9596
timestamp_request = (
96-
TimestampRequestBuilder().data(signature).nonce(nonce=True).build()
97+
TimestampRequestBuilder()
98+
.hash_algorithm(HashAlgorithm.SHA256)
99+
.data(signature)
100+
.nonce(nonce=True)
101+
.build()
97102
)
98103
except ValueError as error:
99104
msg = f"invalid request: {error}"

test/unit/internal/test_timestamping.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import requests
1616

1717
from sigstore._internal.timestamp import TimestampAuthorityClient, TimestampError
18+
from sigstore._utils import sha256_digest
1819

1920

2021
@pytest.mark.timestamp_authority
@@ -23,6 +24,13 @@ def test_sign_request(self, tsa_url: str):
2324
tsa = TimestampAuthorityClient(tsa_url)
2425
response = tsa.request_timestamp(b"hello")
2526
assert response
27+
assert (
28+
response.tst_info.message_imprint.message == sha256_digest(b"hello").digest
29+
)
30+
assert (
31+
response.tst_info.message_imprint.hash_algorithm.dotted_string
32+
== "2.16.840.1.101.3.4.2.1"
33+
) # SHA256 OID
2634

2735
def test_sign_request_invalid_url(self):
2836
tsa = TimestampAuthorityClient("http://fake-url")

0 commit comments

Comments
 (0)