asn1crypto: Fast ASN.1 parser and serializer with definitions for private keys, public keys, certificates, CRL, OCSP, CMS, PKCS#3, PKCS#7, PKCS#8, PKCS#12, PKCS#5, X.509 and TSP · Pythie
Fast ASN.1 parser and serializer with definitions for private keys, public keys, certificates, CRL, OCSP, CMS, PKCS#3, PKCS#7, PKCS#8, PKCS#12, PKCS#5, X.509 and TSP
Low maintenance activity.Last release over 4 years ago, commits in 3 of the last 26 weeks. Weaker on commit activity and recent releases.
In addition to an ASN.1 BER/DER decoder and DER serializer, the project includes
a bunch of ASN.1 structures for use with various common cryptography standards:
Python has long had the pyasn1 and
pyasn1_modules available for
parsing and serializing ASN.1 structures. While the project does include a
comprehensive set of tools for parsing and serializing, the performance of the
library can be very poor, especially when dealing with bit fields and parsing
large structures such as CRLs.
After spending extensive time using pyasn1, the following issues were
identified:
Poor performance
Verbose, non-pythonic API
Out-dated and incomplete definitions in pyasn1-modules
No simple way to map data to native Python data structures
No mechanism for overridden universal ASN.1 types
The pyasn1 API is largely method driven, and uses extensive configuration
objects and lowerCamelCase names. There were no consistent options for
converting types of native Python data structures. Since the project supports
out-dated versions of Python, many newer language features are unavailable
for use.
Time was spent trying to profile issues with the performance, however the
architecture made it hard to pin down the primary source of the poor
performance. Attempts were made to improve performance by utilizing unreleased
patches and delaying parsing using the Any type. Even with such changes, the
performance was still unacceptably slow.
Finally, a number of structures in the cryptographic space use universal data
types such as BitString and OctetString, but interpret the data as other
types. For instance, signatures are really byte strings, but are encoded as
BitString. Elliptic curve keys use both BitString and OctetString to
represent integers. Parsing these structures as the base universal types and
then re-interpreting them wastes computation.
asn1crypto uses the following techniques to improve performance, especially
when extracting one or two fields from large, complex structures:
Delayed parsing of byte string values
Persistence of original ASN.1 encoded data until a value is changed
Lazy loading of child fields
Utilization of high-level Python stdlib modules
While there is no extensive performance test suite, the
CRLTests.test_parse_crl test case was used to parse a 21MB CRL file on a
late 2013 rMBP. asn1crypto parsed the certificate serial numbers in just
under 8 seconds. With pyasn1, using definitions from pyasn1-modules, the
same parsing took over 4,100 seconds.
For smaller structures the performance difference can range from a few times
faster to an order of magnitude or more.
Related Crypto Libraries
asn1crypto is part of the modularcrypto family of Python packages:
A task named deps exists to download and stage all necessary testing
dependencies. On posix platforms, curl is used for downloads and on Windows
PowerShell with Net.WebClient is used. This configuration sidesteps issues
related to getting pip to work properly and messing with site-packages for
the version of Python being used.
The ci task runs lint (if flake8 is available for the version of Python) and
coverage (or tests if coverage is not available for the version of Python).
If the current directory is a clean git working copy, the coverage data is
submitted to codecov.io.
python run.py deps
python run.py ci
Alternatives
Use instead of asn1crypto: tools that do the same job, closest first.
Use together with asn1crypto: extensions, drivers, servers and companion tools.
oscryptoPythie’s Index: 17TLS (SSL) sockets, key generation, encryption, decryption, signing, verification and KDFs using the OS crypto libraries. Does not require a compiler, and relies on the OS for patching. Works on Windows, OS X and Linux/BSD.18.5M downloads/mo
endesivePythie’s Index: 65Digital signatures for PDF, S/MIME, XML (XAdES), and CMS in Python.77.9K downloads/mo
ocspbuilderPythie’s Index: 16Creates and signs online certificate status protocol (OCSP) requests and responses for X.509 certificates1.4M downloads/mo
ocspresponderPythie’s Index: 19RFC 6960 compliant OCSP Responder framework written in Python 3.5+.1.4M downloads/mo