Expand description
RFC 5280 X.509 certificate path validation — pure Rust, no_std.
Implements certificate path building and validation per RFC 5280 §6.
§Architecture
Cryptographic signature verification is pluggable via SignatureVerifier.
The default feature set wires in RustCrypto backends for RSA
(PKCS#1 v1.5 and RSASSA-PSS with SHA-256/384/512; rsa feature) and
ECDSA on P-256 (p256 feature). The optional p384, p521 and
ed25519 features add ECDSA on P-384 and P-521 and Ed25519;
rustcrypto enables all of them. DefaultVerifier dispatches over
whatever is enabled, taking the ECDSA curve from the issuer’s key.
For FIPS-validated crypto, implement SignatureVerifier against
wolfcrypt-rustcrypto and disable the rustcrypto feature.
Revocation checking is handled by pkix-revocation. This crate never
touches the network — use pkix_chain::verify_chain for the combined API.
validate_path takes anything implementing PathCertificate, which
is how it gets the bytes an issuer signed. Hand it
CertificateWithDer and the signed message is a subslice of the
certificate’s own DER; hand it a bare Certificate and the message is
rebuilt by re-encoding the parse, which is slower and correct only while
the encoder is byte-faithful for every field — an assumption that has
already failed once, for pre-2050 GeneralizedTime validity dates. Any
caller who still has the bytes should pass them; see tbs_der_slice.
§Scope: what §6.1 asks, and what it does not
§6.1 is an algorithm over the certificates in a path: it maintains a working issuer name, public key and policy state, and checks each certificate against that state. It does not ask whether any certificate conforms to §4.1 and §4.2, the sections that tell a CA how to issue one.
So a rule of the form “conforming CAs MUST …” is generally not
enforced here. A certificate missing the subjectKeyIdentifier that
§4.2.1.2 requires of every conforming CA certificate validates, as
does one whose commonName is not a character-for-character copy of a
dNSName in its subjectAltName, which CA/B Forum BR 7.1.4.3
requires. Those rules are real; they belong to pkix-lint (the RFC
5280 profile) and pkix-lint-cabf (the CA/B Forum Baseline
Requirements), which exist to check exactly this and can report every
finding on a certificate rather than stopping at the first.
Rejecting a chain because its issuer broke an issuance rule is doing lint work inside path validation, and it costs something real: the caller learns “this chain is invalid” when the truth is “this certificate is non-conforming in a way that does not affect whether the chain is valid”. Those want different responses.
§“Belongs to the lint layer” is now also where it is
Stated plainly, because the sentence above is easy to read as a
promise that something else here catches these: it does, for all
33. Each has an owning lint in pkix-lint or pkix-lint-cabf that
fires on it, out of an implemented catalogue of 27 lints.
The thirty-third was added last, and the order is worth recording.
webpki::explicit-curve is an EC key conveyed as an X9.62
SpecifiedECDomain instead of a namedCurve OID – which CA/B Forum
BR 7.1.3.1.2 forbids and RFC 5480 §2.1.1 permits, so this crate reads
it deliberately and the refusal belongs to the forum layer. For a
while nothing there implemented it: the entry was classified as the
lint layer’s while pkix-lint-cabf had no namedCurve check, making
“belongs to the lint layer” mean nothing checked it. PKIX-mxj4
wrote cabf.br.tls.spki.ec_named_curve, and Mark’s call was to write
it before the release rather than ship the gap.
The count read 32 of 32 before that entry existed at all, which looks
like a regression and is not one. The row had been a ground-truth
disagreement with no ledger entry ever since this crate gained
specifiedCurve support, because a committed baseline was not
regenerated when the behaviour changed. Classifying it moved the
denominator; writing the lint moved the numerator back.
It was 4 of 32 when the claim was first measured, under PKIX-x2gx.
27 entries named a rule no lint here implemented and 1 named a lint
that existed and missed its case; PKIX-9kag wrote the missing ones.
The gap is recorded rather than quietly closed, because the stance
above was asserted for some time before anyone checked it, and the
check is the only reason it is true.
What it still does not mean. It is not a claim about CA/B Forum conformance in general: 32 entries of one corpus is not the Baseline Requirements, and a consumer who needs that should run zlint or pkilint.
The measurement is pkix-difftest/lint-coverage.json, re-derivable
with pkix-difftest lint-limbo --features lint-oracles, and the
per-entry table is in
pkix-difftest/disagreement-classification.md. Three of the twelve
lints are not the ones PKIX-9kag planned, because the plan named
the wrong owning document or called a check unreachable that is not;
the corrections are recorded next to the entries they apply to.
This is measured, not asserted. Of the 37 chains where this crate
currently disagrees with x509-limbo’s expected result, 33 are this —
CA/B Forum BR 7.1.4.3 (9), 6.1.5 key sizes (2), RFC 5280 §4.2.1.1 and
§4.2.1.2 authorityKeyIdentifier and subjectKeyIdentifier (4),
§4.2.1.6 subjectAltName shape (2), §4.2.1.10 nameConstraints in an
end-entity certificate and degenerate encodings (4), leaf keyUsage
and basicConstraints profile rules (3), and authorityKeyIdentifier
treated as a path-building hint rather than a filter (6). Each is
classified with its rule named in
pkix-difftest/disagreement-classification.md.
§Three places the line is drawn the other way
“§6.1 does not ask for it” is a reason, not a licence, and these are the cases that show where it stops being one. Each enforces something §6.1 does not mention, and each was a real defect found by reading the corpus disagreements rather than by reasoning from the specification.
-
The trust anchor is validated. §6.1 treats the anchor as a trusted input and never examines its extensions or its validity dates. This crate checks both, reporting
AnchorDefect— because “the operator chose this anchor” is a decent argument for ignoring its contents and a poor one for ignoring its expiry, and a trust store is precisely where an expired or malformed root sits unnoticed for years. -
A CA’s
extendedKeyUsageconstrains what it may issue. §6.1 has no EKU step at all. Without this, a CA restricted toemailProtectioncould issue a TLS server certificate and the chain would validate, which is the cross-purpose confusion EKU on a CA exists to prevent. SeeValidationPolicy::enforce_ca_eku. -
A CA certificate must have a non-empty subject. This one is an issuance MUST — §4.1.2.6 — and it is enforced anyway, because it changes what §6.1 itself computes: §6.1.3(a)(4) chains a certificate to its issuer by comparing distinguished names, and an empty name compares equal to an empty name. An unnamed CA therefore issues certificates that chain to any unnamed CA, and name chaining stops distinguishing issuers.
§The test, stated so it can be applied again
Does the non-conformance change what §6.1 computes, or create a confusion §6.1’s state machine cannot see? If so it is this crate’s problem, wherever the requirement happens to be written down. If it is non-conformance with no effect on the algorithm’s output, it is the linter’s.
Stated that way because the shorter version — “path validation does not enforce issuance-profile MUSTs” — is the formulation that would have licensed all three cases above. Two of them were live defects when that stance was first proposed.
§Limitations
The following are not currently implemented:
-
UTCTimebefore 1970. The supported range is 1970-2049, where RFC 5280 §4.1.2.5.1 allows 1950-2049. A certificate whosenotBeforeornotAfterfalls in the missing twenty years is refused, and refused at the DER layer — the error reads “malformed ASN.1 DER value for UTCTime” and comes back before validation runs.This is a deliberate scope decision, not an accident. The floor is the Unix epoch because
der0.8 puts it there (“due to common operations working onUNIX_EPOCH,UtcTimes are only supported for the years 1970-2049”), and lifting it would mean forking the DER layer every consumer of this crate depends on. No conforming CA issues certificates dated before 1970, so the trade is a fork of a foundational dependency against twenty years of dates nobody uses.It is fail-closed: such a certificate is refused, never misread. OpenSSL does read them, so expect a genuine disagreement rather than a difference of strictness — NIST PKITS §4.2.3 “Valid pre2000 UTC notBefore Date Test3” is exactly this shape, and is the one PKITS vector this crate does not evaluate.
-
Legacy SHA-1 — shipped, but behind
rsa-sha1andecdsa-sha1, which are deliberately outsidedefaultand outside therustcryptoumbrella: that umbrella means “algorithms we recommend” and these are not. Verification only; nothing here signs with SHA-1. RSA moduli outside 1024–8192 bits are refused by the bundled RSA backend. -
DSA — not implemented. The recorded stance is verify-only and opt-in, following FIPS 186-5, which retains DSA “only for the purposes of verifying existing signatures”; a chain issued under DSA before it was retired either verifies or it does not, and saying which is more useful than refusing to look. When it lands it will sit outside
defaultand outsiderustcrypto, as the SHA-1 features do. Until then such a certificate is refused as an unsupported algorithm, never misread. NIST PKITS4.1.4and4.1.5are the two vectors this affects, and RFC 3279 §2.3.2 domain-parameter inheritance is the awkward half of4.1.5. -
RFC 4518 full Unicode NFKC DN normalization — ASCII case-folding plus insignificant-whitespace collapsing is applied.
BMPStringAVA values are transcoded UCS-2-BE → UTF-8 and then compared via the same ASCII-only normalization pipeline, so two AVAs that share Unicode code points but differ only in DER string-type (e.g.BMPString“Foo Co” vsUTF8String“Foo Co”) compare equal. Full RFC 4518 prep (NFKC, non-ASCII Unicode case fold, prohibit/bidi steps) is future work tracked underPKIX-l63j; until it lands, twoBMPStringvalues that contain the same Unicode code points but differ in canonical decomposition (e.g. precomposed U+00E9 ‘é’ vs decomposed U+0065 U+0301 ‘e’+ combining acute) compare unequal.UniversalStringAVA values are rejected by thedercrate at parse time (tag 0x1C is not inder::Tag, in 0.8 as in 0.7) and never reach the path validator.NumericStringAVAs go through the same ASCII pipeline: X.680 limits the type to digits and space, and LDAP’snumericStringMatch(RFC 4517 §4.2.22) prescribes the same preparation.TeletexStringAVAs go through it only when every octet lies in the ISO 646 invariant set, where T.61 and ASCII cannot disagree; outside that — a non-spacing diacritic at 0xC0–0xCF, or one of the twelve nationally-variable positions — they fall back to raw DER byte comparison, becausepkix-pathdeliberately does not transcode T.61 to Unicode. Seeteletex_is_iso646_invariantfor where the line sits and why. -
privateKeyUsagePeriod(2.5.29.16) — not processed. RFC 3280 deprecated it and RFC 5280 dropped it from the profile, so a CA asserting a key-usage window narrower than the certificate’s own validity is saying something this crate does not enforce. It is common in the wild rather than vestigial: 495 of the 609 ePassport CSCA certificates vendored underthird_party/trust-stores/carry it, as do two Russian national roots that declare an eight-year key window inside an eighteen-year certificate.It is non-critical in every one of those, which is why none is refused — a critical instance would hit the §6.1.4 rule and come back as
AnchorDefect::UnhandledCriticalExtension, correctly but to the surprise of anyone whose root suddenly stopped loading. The corpus measuring the extension’s presence is the early warning for that. A fractional-secondsGeneralizedTimeinside one is also unreachable for the same reason;tests/fractional_generalizedtime.rspins both halves. -
Path building — converting an unordered bag of certificates into a validated chain is handled by
pkix-path-builder. This crate validates a caller-ordered&[Certificate]only. -
AIA fetching — chains with missing intermediates are not reassembled from
AuthorityInfoAccessURIs here. Callers supply a complete chain, or go throughpkix-chain, which followscaIssuersURIs viapkix-aia/pkix-aia-http(PKIX-zkjb).
Modules§
- brainpool_
p224r1 bp224 - brainpoolP224r1, implemented here for want of an upstream crate.
- brainpool_
p512r1 bp512 - brainpoolP512r1, implemented here for want of an upstream crate.
- ed521
ed521 - Ed521 (EdDSA over E-521), for one ICP-Brasil certificate.
- gost_
r3410 gost - GOST R 34.10 signature verification, implemented here for want of an upstream crate.
- serde_
der serde - Helper module for format-adaptive serde serialization of DER-encodable
types. Public so downstream crates (
pkix-chain,pkix-revocation,pkix-truststore) can reuse the same wire form on their own result types without redefining the helpers. Helper functions for serde-serializing DER-encodable types in a format-adaptive wire form. - specified_
curve - Recognizing an X9.62
SpecifiedECDomainas a named curve.
Structs§
- Certificate
With Der - A certificate together with the DER it was decoded from.
- Default
Verifier ed25519orp256orp384orp521orrsa - A
SignatureVerifiercovering everyRustCryptobackend enabled at build time. - DerError
- Opaque wrapper around an underlying ASN.1 / DER error.
- Ecdsa
P256 Verifier p256 - ECDSA verifier for P-256 (
secp256r1) issuer keys. - Ecdsa
P384 Verifier p384 - ECDSA verifier for P-384 (
secp384r1) issuer keys. - Ecdsa
P521 Verifier p521 - ECDSA verifier for P-521 (
secp521r1) issuer keys. - Ecdsa
Sha1 Verifier ecdsa-sha1 - Verifies ECDSA signatures over SHA-1, on any curve this build has. Legacy interop only.
- Ed448
Verifier ed448 - Verifies Ed448 signatures (RFC 8032 EdDSA, RFC 8410 encoding).
- Ed521
Verifier ed521 - Verifies Ed521 signatures (EdDSA over E-521, per ICP-Brasil).
- Ed25519
Verifier ed25519 - Ed25519 signature verifier (RFC 8410, RFC 8032 §5.1.7).
- Gost
R3410 Verifier gost - Verifies GOST R 34.10 signatures (RFC 4491, RFC 7091).
- MlDsa87
Verifier ml-dsa - Verifies ML-DSA-87 signatures (FIPS 204).
- Name
Constraints - Re-exported for use with
TrustAnchor::name_constraints. NameConstraints extension as defined in RFC 5280 Section 4.2.1.10. - Object
Identifier - Object identifier (OID).
- Policy
Tree Node - A node of the final policy graph, exposed for post-validation qualifier
extraction on
ValidatedPath::valid_policy_tree. - RsaPkcs1v15
Ripemd160 Verifier rsa-ripemd160 - Verifies RSA PKCS#1 v1.5 signatures over RIPEMD-160. Legacy interop only.
- RsaPkcs1v15
Sha1 Verifier rsa-sha1 - Verifies RSA PKCS#1 v1.5 signatures over SHA-1. Legacy interop only.
- RsaPkcs1v15
Sha256 Verifier rsa - RSA with PKCS#1 v1.5 padding and SHA-256 signature verifier.
- RsaPkcs1v15
Sha384 Verifier rsa - RSA with PKCS#1 v1.5 padding and SHA-384 signature verifier.
- RsaPkcs1v15
Sha512 Verifier rsa - RSA with PKCS#1 v1.5 padding and SHA-512 signature verifier.
- RsaPss
Verifier rsa - RSASSA-PSS signature verifier (RFC 4055 §3.1).
- Sm2With
Sm3Verifier sm2 - Verifies SM2 signatures over SM3 (GB/T 32918).
- Trust
Anchor - A trust anchor used to terminate path validation.
- Validated
Path - The result of a successful certificate path validation.
- Validation
Policy - Policy parameters controlling path validation.
- Verification
Error - Error returned by
SignatureVerifier::verify_signature.
Enums§
- Anchor
Admission - The requirements a certificate must meet to be usable as a trust anchor, excluding the clock-dependent ones.
- Anchor
CrlSign - What RFC 5280 §6.3.3(f) can be determined about a trust anchor that also signs CRLs.
- Anchor
Defect - Why a trust anchor certificate was refused.
- DnAttr
Rule - Compositional rule for asserting required Subject DN attributes on a leaf cert.
- Error
- Errors returned by path validation.
- NoRev
Avail Prohibition - RFC 5280 §6.1.3(a)(3): reject any critical extension not in the handled set.
Which of RFC 9608 §3’s four prohibitions a
noRevAvailcertificate violates. - RsaKey
Deviation rsa - Reading an RSA public key whose DER INTEGERs are not minimal, and
saying what had to be forgiven. See
rsa_public_key_lenient. - Verification
Error Kind - Why a
SignatureVerifierdid not accept a signature.
Constants§
- MAX_
AVAS_ PER_ RDN - Maximum number of attribute-value assertions in one RDN that
names_matchwill compare.
Traits§
- Decode
- Decode trait parses a complete TLV (Tag-Length-Value) structure.
- Decode
Certificate - Builds a path element from a certificate’s DER.
- Path
Certificate - What
validate_pathaccepts as a certificate in the path. - Profile
- A PKI regime profile that bundles identity, citation, and a validation policy.
- Retained
Certificate - A path element that definitely kept the certificate’s own DER.
- Signature
Verifier - Pluggable signature verification backend.
Functions§
- anchor_
profile_ deviation - Every way
certdeviates from the CA-certificate profile, ignoring whether any of them disqualifies it as an anchor. - cert_
is_ ca - Returns
Ok(true)ifcertis a CA certificate per itsBasicConstraintsextension (RFC 5280 §4.2.1.9),Ok(false)if the extension is absent orcA = FALSE, andErr(DerError)if the extension is present but cannot be DER-decoded. - has_
no_ rev_ avail - RFC 9608 §3: a certificate carrying
noRevAvailmust not also be a CA or point at revocation information. - names_
match - Compare two distinguished names per RFC 4518 string prep rules.
- rsa_
public_ key_ lenient rsa - Reading an RSA public key whose DER INTEGERs are not minimal, and
saying what had to be forgiven. See
rsa_public_key_lenient. - tbs_
certificate_ der - Rebuilds the DER encoding of
cert’sTBSCertificate: the bytes its issuer signed. - tbs_
der_ slice - Locates the
TBSCertificateinside a certificate’s own DER and returns it as a subslice: the exact bytes the issuer signed. - validate_
path - Validate a certificate chain from subject to a trust anchor.
- validate_
path_ with_ profile - Validate a certificate chain using a
Profileto produce the policy.
Type Aliases§
- Algorithm
Identifier Ref AlgorithmIdentifierreference which hasAnyRefparameters.- Certificate
- X.509 certificates are defined in RFC 5280 Section 4.1.
- Result
- Result alias for this crate.
- Subject
Public KeyInfo Ref SubjectPublicKeyInfowithAnyRefalgorithm parameters, andBitStringRefparams.