Skip to main content

Python implementation of the RFC3161 specification, using pyasn1

Project description Build Status Latest PyPI version Supports Wheel format

A simple client library for cryptographic timestamping service implementing the protocol from RFC3161.

This started as a fork of and has some additional patches such as Python3 support.

The latest version of this library is available from .


>>> import rfc3161ng
>>> certificate = open('data/certum_certificate.crt', 'rb').read()
>>> rt = rfc3161ng.RemoteTimestamper('', certificate=certificate)
>>> tst = rt.timestamp(data=b'John Doe')
>>> rt.check(tst, data=b'John Doe')
>>> rfc3161ng.get_timestamp(tst)
datetime.datetime(2017, 8, 31, 15, 42, 58, tzinfo=tzutc())

Example for a server that insist on SHA256:

>> import rfc3161ng >> timestamper = rfc3161ng.RemoteTimestamper(‘’,hashname=’sha256’) >> tsr = timestamper(data=b’The RedWax Project’, return_tsr=True) >> print(‘{}’.format(tsr))

Verifying timestamp using OpenSSL

One can verify the timestamp returned by the timeserver by using OpenSSL. For example with:

$ openssl ts -verify -data data_file.txt -in data_file.tsr -CAfile cacert.pem -untrusted tsa.crt

To save the tsr you can use code similar to:

>>> from pyasn1.codec.der import encoder
>>> import rfc3161ng
>>> ...
>>> timestamper = rfc3161ng.RemoteTimestamper('', certificate=certificate_data)
>>> tsr = timestamper(, return_tsr=True)
>>> with open("data_file.tsr", "wb") as f:
>>>     f.write(encoder.encode(tsr))

Alternatively you can just save the raw response.content returned from the certification server.

There is a test which also covers this in test_verify_timestamp_response_with_openssl.


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rfc3161ng, version 2.1.2
Filename, size File type Python version Upload date Hashes
Filename, size rfc3161ng-2.1.2-py2.py3-none-any.whl (9.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size rfc3161ng-2.1.2.tar.gz (21.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page