certvalidator is a Python library for validating X.509 certificates and certificate paths according to RFC 5280. It provides robust tools for checking certificate validity, revocation status (CRL and OCSP), and trust chains. The current version is 0.11.1, and it typically sees updates every few months for minor versions, with occasional major version bumps.
pip install certvalidatorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to fetch a TLS server's certificate chain using `oscrypto`, load system trust anchors with `TrustStore`, and then validate the certificate path for a specific hostname using `CertificateValidator`.
Convert `float` timestamps to `datetime.datetime` objects using `datetime.fromtimestamp(timestamp_float)`.
Instantiate `RevocationChecker` objects (e.g., `CRLChecker()`, `OCSPChecker()`) and pass them as a list to the `revocation_checkers` argument of `CertificateValidator`.
When fetching certificates from a TLS server, use mechanisms that provide the full certificate chain (e.g., `oscrypto.tls.TLSSocket`'s `peer_certificate` and `intermediate_certificates`). If loading from files, ensure all intermediate certificates are present.
If you prefer 'soft-fail' behavior where unresolvable OCSP issues do not halt validation, instantiate `OCSPChecker(soft_fail=True)` and include it in your `revocation_checkers` list.
Ensure all intermediate certificates are provided to the `CertificateValidator`, configure appropriate trust roots via `ValidationContext`, verify certificate validity dates, and confirm key usage settings. For TLS, ensure the `hostname` parameter in `validate_tls()` matches the certificate's subject alternative names.
Enable revocation checking by setting `validation_context.allow_fetching = True` and specifying a `revocation_mode` (e.g., 'hard-fail', 'require') in your `ValidationContext`. Ensure network access to CRL and OCSP URLs. If fetching externally, provide pre-fetched CRLs/OCSP responses to the `ValidationContext`.
Provide the certificate data as a DER or PEM-encoded byte string, or as an already parsed `asn1crypto.x509.Certificate` object. For example, `with open('/path/to/cert.crt', 'rb') as f: end_entity_cert = f.read()`.Install the `asn1crypto` package using pip: `pip install asn1crypto`. If already installed, check your Python environment and ensure it's active and correctly configured.