Actively maintained. Last release 3 months ago, commits in 24 of the last 26 weeks. A safe choice.
pip install rfc3161-clientrfc3161-client
rfc3161-client is a Python library implementing the Time-Stamp Protocol (TSP)
described in RFC 3161.
It is composed of three subprojects:
- :crab: tsp-asn1: A Rust crate using
rust-asn1to create the types used by the Time-Stamp protocol. This crate depends onrust-asn1andcryptographyto minimize the amount of duplicated code. While it is usable as a standalone crate, this is not officially supported. Drop us a message if you are interested in using it. - :crab: rfc3161-client: Another Rust crate that
provides Python bindings to the
tsp-asn1crate using PyO3. - :snake: rfc3161-client A Python library using the crate above to provide a usable API to create Timestamp Request and read Timestamp Response.
Goals and anti-goals
- This library should be correct and provide an accurate implementation of protocol described in the RFC 3161.
- This library does not perform any network activity, it simply provides primitive to build and verify objects. Network activity must be handled separately.
Usage
There are two parts to timestamping: retrieving + verifying the timestamp.
1. Retrieving a timestamp
The below code uses requests to get the timestamp from the Identrust TSA server:
# /// script
# dependencies = [
# "requests",
# "rfc3161-client",
# ]
# ///
import requests
from rfc3161_client import (
decode_timestamp_response,
TimestampRequestBuilder,
VerifierBuilder,
VerificationError,
)
# the data to sign. Could be a hash or any message. Should be bytes
message = b"Hello, World!"
# build the timestamp request
timestamp_request = (
TimestampRequestBuilder().data(message).build()
# Note: you could also add .hash_algorithm(XXX) to specify a specific hash algorithm
)
# TSA servers must be RFC 3161 compliant (see https://github.com/trailofbits/rfc3161-client/issues/46
# for a list of working servers)
tsa_server = "http://timestamp.identrust.com"
# make the request, remember to set content-type headers appropriately
response = requests.post(
tsa_server,
data=timestamp_request.as_bytes(),
headers={"Content-Type": "application/timestamp-query"},
)
response.raise_for_status()
# if successful, should give a valid TimeStampResponse object
timestamp_response = decode_timestamp_response(response.content)