2025-01-29 11:20:52 +00:00
|
|
|
import pytest
|
|
|
|
from auto_archiver.modules.timestamping_enricher.timestamping_enricher import TimestampingEnricher
|
2025-02-11 18:18:19 +00:00
|
|
|
from rfc3161_client import (
|
|
|
|
TimestampRequestBuilder,
|
|
|
|
TimeStampResponse,
|
|
|
|
decode_timestamp_response,
|
|
|
|
)
|
2025-01-29 11:20:52 +00:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def digicert():
|
|
|
|
with open("tests/data/timestamp_token_digicert_com.crt", "rb") as f:
|
|
|
|
return f.read()
|
|
|
|
|
|
|
|
@pytest.mark.download
|
|
|
|
def test_sign_data(setup_module):
|
2025-02-11 18:18:19 +00:00
|
|
|
tsa_url = "http://timestamp.identrust.com"
|
2025-01-29 11:20:52 +00:00
|
|
|
tsp: TimestampingEnricher = setup_module("timestamping_enricher")
|
2025-02-25 12:08:08 +00:00
|
|
|
|
2025-01-29 11:20:52 +00:00
|
|
|
data = b"4b7b4e39f12b8c725e6e603e6d4422500316df94211070682ef10260ff5759ef"
|
2025-02-11 18:18:19 +00:00
|
|
|
result: TimeStampResponse = tsp.sign_data(tsa_url, data)
|
|
|
|
assert isinstance(result, TimeStampResponse)
|
2025-01-29 11:20:52 +00:00
|
|
|
|
2025-02-26 09:33:56 +00:00
|
|
|
cert_chain = tsp.download_certificate(result)
|
|
|
|
|
|
|
|
assert len(cert_chain) == 2
|
|
|
|
|
2025-01-29 11:20:52 +00:00
|
|
|
try:
|
2025-02-25 12:08:08 +00:00
|
|
|
valid_root = tsp.verify_signed(result, data)
|
|
|
|
assert valid_root.subject == "CN=Entrust Root Certification Authority - G2, OU=(c) 2009 Entrust, Inc. - for authorized use only, OU=See www.entrust.net/legal-terms, O=Entrust, Inc., C="
|
2025-01-29 11:20:52 +00:00
|
|
|
except Exception as e:
|
|
|
|
pytest.fail(f"Verification failed: {e}")
|
|
|
|
|
2025-02-25 12:08:08 +00:00
|
|
|
# test downloading the cert
|
|
|
|
|
2025-01-29 11:20:52 +00:00
|
|
|
def test_tsp_enricher_download_syndication(setup_module, digicert):
|
|
|
|
tsp: TimestampingEnricher = setup_module("timestamping_enricher")
|
2025-02-11 15:26:40 +00:00
|
|
|
|
|
|
|
cert_chain = tsp.download_and_verify_certificate(digicert)
|
|
|
|
assert len(cert_chain) == 3
|
|
|
|
assert cert_chain[0].filename == f"{tsp.tmp_dir}/74515005589773707779.crt"
|
|
|
|
assert cert_chain[1].filename == f"{tsp.tmp_dir}/95861100433808324400.crt"
|
|
|
|
assert cert_chain[2].filename == f"{tsp.tmp_dir}/15527051335772373346.crt"
|
2025-01-29 11:20:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_tst_cert_valid(setup_module, digicert):
|
|
|
|
tsp: TimestampingEnricher = setup_module("timestamping_enricher")
|
|
|
|
|
|
|
|
try:
|
|
|
|
tsp.verify_signed(digicert, b"4b7b4e39f12b8c725e6e603e6d4422500316df94211070682ef10260ff5759ef")
|
|
|
|
except Exception as e:
|
|
|
|
pytest.fail(f"Verification failed: {e}")
|