commit | 936b971a83e371f3a3d59124e33a1e90f653dbc2 | [log] [tgz] |
---|---|---|
author | wbond <will@wbond.net> | Fri Jul 24 08:38:55 2015 -0400 |
committer | wbond <will@wbond.net> | Fri Jul 24 08:38:55 2015 -0400 |
tree | cf8aa06d1e9d0dae59f2e1e85c81b6c002e21f35 | |
parent | 7a5c01555913be1bfdb9c312cdb7b94efce8dfd6 [diff] |
Added x509.Name.hashable and x509.RelativeDistinguishedName.hashable for use as dict keys, or presence in sets
A fast, pure Python library for parsing and serializing ASN.1 structures. 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:
Standard | Module | Source |
---|---|---|
X509 | asn1crypto.x509 | RFC5280 |
CRL | asn1crypto.crl | RFC5280 |
CSR | asn1crypto.csr | RFC2986, RFC2985 |
OCSP | asn1crypto.ocsp | RFC6960 |
PKCS#12 | asn1crypto.pkcs12 | RFC7292 |
PKCS#8 | asn1crypto.keys | RFC5208 |
PKCS#1 v2.1 (RSA keys) | asn1crypto.keys | RFC3447 |
DSA keys | asn1crypto.keys | RFC3279 |
Elliptic curve keys | asn1crypto.keys | SECG SEC1 V2 |
PKCS#5 v2.1 | asn1crypto.algos | PKCS#5 v2.1 |
CMS (and PKCS#7) | asn1crypto.cms | RFC5652, RFC2315 |
TSP | asn1crypto.tsp | RFC3161 |
PDF signatures | asn1crypto.pdf | PDF 1.7 |
asn1crypto is licensed under the terms of the MIT license. See the LICENSE file for the exact license text.
Python 2.7, 3.3, 3.4, pypy or pypy3. No third-party packages required.
0.9.0 - changelog
pip install asn1crypto
The documentation for asn1crypto is composed of tutorials on basic usage and links to the source for the various pre-defined type classes.
asn1crypto.core
asn1crypto.algos
asn1crypto.keys
asn1crypto.x509
asn1crypto.crl
asn1crypto.ocsp
asn1crypto.csr
asn1crypto.pkcs12
asn1crypto.cms
asn1crypto.tsp
asn1crypto.pdf
The following commands will run the test suite, linter and test coverage:
python run.py tests python run.py lint python run.py coverage
To run only some tests, pass a regular expression as a parameter to tests
.
python run.py tests ocsp
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:
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:
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 of more.