Skip to main content

PKI tools for e.g. checking certificate CRL/OCSP revocation

Project description

Python Badge

pki-tools

PKI tools exposes a high level cryptography API for e.g.:

Installation

pip install pki-tools

Usage

CRL

Checking revocation using PEM encoded certificate

from pki_tools.crl import is_revoked, Revoked, Error

cert_pem = """
-----BEGIN CERTIFICATE-----
<CERTIFICATE_PEM_BYTES>
-----END CERTIFICATE-----
"""

try:
    is_revoked(cert_pem)
except Revoked as e:
    print(f"Certificate revoked: {e}")
except Error as e:
    print(f"Revocation check failed. Error: {e}")
    raise

Checking revocation using an already loaded cryptography x509.Certificate:

from cryptography import x509
from pki_tools.ocsp import is_revoked, Revoked, Error

cert : x509.Certificate = ...
issuer: x509.Certificate = ...

try:
    is_revoked(cert, issuer)
except Revoked as e:
    print(f"Certificate revoked: {e}")
except Error as e:
    print(f"Revocation check failed. Error: {e}")
    raise

OCSP

Checking revocation using PEM encoded certificate

from pki_tools.ocsp import is_revoked, Revoked, Error

cert_pem = """
-----BEGIN CERTIFICATE-----
<CERTIFICATE_PEM_BYTES>
-----END CERTIFICATE-----
"""

issuer_pem = """
-----BEGIN CERTIFICATE-----
<ISSUER_PEM_BYTES>
-----END CERTIFICATE-----
"""

try:
    is_revoked(cert_pem, issuer_pem)
except Revoked as e:
    print(f"Certificate revoked: {e}")
except Error as e:
    print(f"Revocation check failed. Error: {e}")
    raise

Checking revocation using an already loaded cryptography x509.Certificate:

from cryptography import x509
from pki_tools.ocsp import is_revoked, Revoked, Error

cert : x509.Certificate = ...
issuer_cert : x509.Certificate = ...

try:
    is_revoked(cert, issuer_cert)
except Revoked as e:
    print(f"Certificate revoked: {e}")
except Error as e:
    print(f"Revocation check failed. Error: {e}")
    raise

Project details


Download files

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

Source Distribution

pki_tools-0.0.3.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

pki_tools-0.0.3-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page