PKI tools for e.g. checking certificate CRL/OCSP revocation
Project description
PKI tools exposes a high level cryptography
API and wrappers for e.g.:
- Loading certificates from PEM strings/files/cryptography object into a pydantic model including all x509 v3 extensions
- Checking revocation of certificates using OCSP with CRL fallback
- Creating Certs, CSR, CRL easy with pure pydantic objects to e.g. get a PEM file
Docs
Documentation is available at: https://pki-tools.fulder.dev
Quickstart
Install
pip install pki-tools
Usage
Loading from PEM
from pki_tools import Certificate, Chain, CertificateSigningRequest
cert_pem = """
-----BEGIN CERTIFICATE-----
<CERT_PEM_BYTES>
-----END CERTIFICATE-----
"""
issuer_cert_pem = """
-----BEGIN CERTIFICATE-----
<ISSUER_CERT_PEM_BYTES>
-----END CERTIFICATE-----
"""
csr_pem= """
-----BEGIN CERTIFICATE REQUEST-----
<CSR_PEM_BYTES>
-----END CERTIFICATE REQUEST-----
"""
cert = Certificate.from_pem_string(cert_pem)
chain = Chain.from_pem_string(issuer_cert_pem)
csr = CertificateSigningRequest.from_pem_string(csr_pem)
Checking revocation using OCSP with CRL fallback
The following example uses cert
and chain
from the loading examples above
from pki_tools import is_revoked
if is_revoked(cert, chain):
print("Certificate Revoked!")
Creating
Self signed certificate
import datetime
from pki_tools import (
Certificate,
Name,
Validity,
RSAKeyPair,
SHA512,
)
name = Name(cn=["Cert CN"])
cert = Certificate(
subject=name,
issuer=name,
validity=Validity(
not_before=datetime.datetime.today(),
not_after=datetime.datetime.today() + datetime.timedelta(days=1),
),
)
cert.sign(RSAKeyPair.generate(), SHA512)
print(cert.pem_string)
Create CSR
from pki_tools import (
Name,
CertificateSigningRequest,
RSAKeyPair,
SHA512,
)
name = Name(cn=["Cert CN"])
csr = CertificateSigningRequest(subject=name)
csr.sign(RSAKeyPair.generate(), SHA512)
print(csr.pem_string)
Project details
Release history Release notifications | RSS feed
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.38.tar.gz
(26.4 kB
view hashes)
Built Distribution
pki_tools-0.0.38-py3-none-any.whl
(34.0 kB
view hashes)
Close
Hashes for pki_tools-0.0.38-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f154759d46f3dbc9b0c74dd98f8fec158176918f7a67a9e111c968549c5956f |
|
MD5 | 1fbc0179df5800d387d3ec8f21f67ff6 |
|
BLAKE2b-256 | 015a5afe5bd1035897025e3754ec356e0c077f58562c706f8f7b3524520afc99 |