Skip to main content

Python certificate chain resolver

Licence CI Docs codecov Downloads Python) PyPI - Wheel PyPI Code style: black

Resolve and obtain the complete certificate chain from the leaf, intermediate(s) to the root of a x509 certificate using the CLI or the python API.

The library provides an easy to use API to access each property of a certificate chain and the important metadata of a certificate. The library also exposes a CLI for resolving and inspecting certificate chains from the command line.

Support

  • PKCS7, PEM and DER formats
  • LetsEncrypt certificates
  • Including the root certificate using the system CA bundle or custom bundle
  • Python2 (but not for much longer..)

Installation

Pypi package

$ pip install cert-chain-resolver

CLI Usage

For more options and examples see the read the docs or pass the --help flag.

The bundle gets written to stdout and the chain information to stderr.

from source:

$ python -m cert_chain_resolver.cli --include-root certificate.crt > bundle.crt
$ cat certificate.crt | python -m cert_chain_resolver.cli --include-root > bundle.crt

from PIP

 $ cert_chain_resolver --include-root certificate.crt > bundle.crt
 1. <Cert common_name="github.com" subject="CN=github.com,O=GitHub\, Inc.,L=San Francisco,ST=California,C=US" issuer="CN=DigiCert SHA2 High Assurance Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US">
 2. <Cert common_name="DigiCert SHA2 High Assurance Server CA" subject="CN=DigiCert SHA2 High Assurance Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US" issuer="CN=DigiCert High Assurance EV Root CA,OU=www.digicert.com,O=DigiCert Inc,C=US">
 3. <Cert common_name="DigiCert High Assurance EV Root CA" subject="CN=DigiCert High Assurance EV Root CA,OU=www.digicert.com,O=DigiCert Inc,C=US" issuer="CN=DigiCert High Assurance EV Root CA,OU=www.digicert.com,O=DigiCert Inc,C=US">

Python API

Make sure to read the documentation for more examples and options.

from cert_chain_resolver.api import resolve

with open('cert.pem', 'rb') as f:
   fb = f.read()
   chain = resolve(fb)
>>>
for cert in chain:
  print(cert)
  print(cert.export())  # Export the certificate in PEM format

<Cert common_name="cert-chain-resolver.remcokoopmans.com" subject="CN=cert-chain-resolver.remcokoopmans.com" issuer="CN=R3,O=Let's Encrypt,C=US">
"-----BEGIN CERTIFICATE-----...."
<Cert common_name="R3" subject="CN=R3,O=Let's Encrypt,C=US" issuer="CN=DST Root CA X3,O=Digital Signature Trust Co.">
"-----BEGIN CERTIFICATE-----...."
<Cert common_name="DST Root CA X3" subject="CN=DST Root CA X3,O=Digital Signature Trust Co." issuer="CN=DST Root CA X3,O=Digital Signature Trust Co.">
"-----BEGIN CERTIFICATE-----...."

Dependencies

  • cryptography

After cloning the repository

Install dependencies

$ make

Development

bootstrap

$ make

Testing

Unit testing

$ make tests

Re-run tests on file changes:

$ make tests TEST_ARGS="-- -f"

Formatting

$ make format

Download files

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

Source Distribution

cert_chain_resolver-1.4.1.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cert_chain_resolver-1.4.1-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file cert_chain_resolver-1.4.1.tar.gz.

File metadata

  • Download URL: cert_chain_resolver-1.4.1.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cert_chain_resolver-1.4.1.tar.gz
Algorithm Hash digest
SHA256 995358207109005a0a32d2f1fad59e244bdb8bb07a70b51ea6f5566b7cb2ab45
MD5 a6b53cc9d8e5415c32b963b6c3bd75f2
BLAKE2b-256 1f77a8c1feafddf0d10de5637193f9cdaf8b4ef89b064f4817357e6766ff8a09

See more details on using hashes here.

File details

Details for the file cert_chain_resolver-1.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cert_chain_resolver-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79bbfdac3a90f5eea1fc40b9b0e736ab3414f759ceafa94d6d4adb887bf055b4
MD5 d4e08858be937a758c781fac7e94b383
BLAKE2b-256 791e4ff60ca8892c510f74a2aee7e5efa2ba6c9914f743d666c8a226957c2ccf

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 files

1.4.0

2 files

1.3.0

2 files

1.2.1

2 files

1.1.1

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page