{"library":"rfc3161-client","title":"RFC 3161 Client","description":"A Python client library for interacting with RFC 3161 compliant Timestamping Authorities (TSAs). It enables users to request timestamps for data and verify existing RFC 3161 timestamp responses. The library is actively maintained, with regular releases addressing bug fixes, security enhancements, and feature improvements, currently at version 1.0.6.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install rfc3161-client"],"cli":null},"imports":["from rfc3161_client import TimestampRequest","from rfc3161_client import VerifierBuilder","from rfc3161_client import HashAlgorithm","from rfc3161_client.exceptions import TimestampVerificationError","from rfc3161_client.exceptions import TSAResponseError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport hashlib\nfrom rfc3161_client import TimestampRequest, VerifierBuilder, HashAlgorithm\nfrom rfc3161_client.exceptions import TSAResponseError, TimestampVerificationError\n\n# Use a public TSA URL. For production, ensure this is a trusted service.\n# Example: http://timestamp.digicert.com or a URL from your trusted provider.\nTSA_URL = os.environ.get('RFC3161_TSA_URL', 'http://timestamp.digicert.com')\n\n# 1. Prepare data to be timestamped\nmessage = b\"This is the data to be timestamped.\"\nmessage_hash = hashlib.sha256(message).digest()\n\nprint(f\"Attempting to timestamp data using TSA: {TSA_URL}\")\n\n# 2. Request a timestamp from the TSA\ntry:\n    request = TimestampRequest(\n        tsa_url=TSA_URL,\n        hashed_message=message_hash,\n        hash_algorithm=HashAlgorithm.SHA256,\n    )\n    timestamp_response = request.get_timestamp_response()\n    print(\"Timestamp received successfully.\")\n\n    # 3. Verify the timestamp response\n    # For robust verification, provide 'trusted_root_certs' of the TSA.\n    # If not provided, the verifier attempts to build a chain from certs\n    # embedded in the response or system CAs where possible (less secure).\n    verifier = VerifierBuilder().build()\n    is_valid = verifier.verify(\n        timestamp_response=timestamp_response,\n        hashed_message=message_hash,\n        hash_algorithm=HashAlgorithm.SHA256,\n        # trusted_root_certs=[b\"-----BEGIN CERTIFICATE-----\\n...\\n-----END CERTIFICATE-----\"],\n    )\n\n    if is_valid:\n        print(\"Timestamp verification successful.\")\n    else:\n        print(\"Timestamp verification FAILED.\")\n\nexcept TSAResponseError as e:\n    print(f\"Error from TSA: {e}\")\nexcept TimestampVerificationError as e:\n    print(f\"Timestamp verification error: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to request an RFC 3161 timestamp for a message hash and then verify the received response. It highlights the basic flow: hashing data, sending a `TimestampRequest`, and using a `VerifierBuilder` to confirm the authenticity and integrity of the timestamp.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}