#[non_exhaustive]pub struct ValidationPolicy {Show 17 fields
pub max_path_len: u8,
pub current_time_unix: u64,
pub enforce_key_usage: bool,
pub enforce_ca_eku: bool,
pub require_crl_sign_on_cas: bool,
pub initial_explicit_policy: bool,
pub initial_any_policy_inhibit: bool,
pub initial_policy_mapping_inhibit: bool,
pub initial_policy_set: Vec<ObjectIdentifier>,
pub max_validity_secs: Option<u64>,
pub allowed_signature_algs: Option<Vec<ObjectIdentifier>>,
pub min_rsa_key_bits: Option<u32>,
pub require_subject_alt_name: bool,
pub require_rfc822_san: bool,
pub required_leaf_eku: Option<Vec<ObjectIdentifier>>,
pub required_leaf_policy_oids: Option<Vec<ObjectIdentifier>>,
pub required_leaf_subject_dn_attrs: Option<DnAttrRule>,
}Expand description
Policy parameters controlling path validation.
§Stability
ValidationPolicy is #[non_exhaustive].
Construct via ValidationPolicy::new or Default + field assignment.
Do not use struct literal syntax.
§Performance note
Policy objects are intended to be constructed once (e.g., at server startup) and reused for the lifetime of the application. Repeated construction is unnecessary.
Policy enforcement (CertificatePolicies, PolicyMappings, PolicyConstraints,
InhibitAnyPolicy) is implemented per RFC 5280 §6.1. Use the
initial_explicit_policy, initial_any_policy_inhibit,
initial_policy_mapping_inhibit, and initial_policy_set fields to
configure the initial policy state.
§Limitations
Path-building (RFC 4158 — cross-signed certificates, multiple candidate
issuers) is out of scope for this crate. The caller must supply the
complete, ordered chain (see pkix-path-builder for path discovery).
Revocation checking (CRL / OCSP) is out of scope for pkix-path; see
pkix-revocation for that functionality.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_path_len: u8Maximum chain depth, not counting the trust anchor. Default: 10.
A chain of [leaf] is depth 0. [leaf, intermediate, root] is depth 1
(one intermediate). Validation fails if depth exceeds this value.
Self-issued certificates do not count towards the depth (RFC 5280
§4.2.1.9), but they are not unlimited either: a chain longer than
2 * max_path_len + 3 certificates (the leaf, max_path_len
intermediates, and up to one self-issued certificate per CA in the
path plus one more at the top for an included root) is rejected with
Error::PathTooLong before any other processing. This bounds the
work done on an attacker-supplied chain.
current_time_unix: u64Current time as seconds since the Unix epoch (1970-01-01T00:00:00Z).
Used to check notBefore ≤ now ≤ notAfter on every certificate.
Must be set by the caller — there is no platform clock in no_std.
Warning — the default is 0 (1970-01-01): Any certificate issued
after 1970 has notBefore > 0 and will fail the validity check with
Error::ValidityPeriod. If you see unexpected ValidityPeriod
errors, check that current_time_unix is set to the current time.
Warning: passing u64::MAX causes all notAfter checks to pass.
This effectively disables expiry checking — only use it in contexts
where you explicitly want permissive (clock-free) validation.
enforce_key_usage: boolEnforce the KeyUsage extension when present. Default: true.
When true, an intermediate certificate whose KeyUsage extension is
present but does not include keyCertSign will be rejected with
Error::KeyUsageMissing, per RFC 5280 §6.1.4(n).
Certificates with no KeyUsage extension are not affected; RFC 5280
only mandates the check when the extension is present.
enforce_ca_eku: boolWhether a CA’s ExtendedKeyUsage constrains what it may issue.
Default: true.
RFC 5280 §6.1 has no EKU step, and §4.2.1.12 says only that the
extension “will appear only in end entity certificates” “in
general”. EKU nesting is therefore not an RFC 5280 path validation
rule; it is the WebPKI profile’s, and it is what every other
verifier does — rustls-webpki enforces it, OpenSSL enforces it
under -purpose, browsers enforce it.
It is on by default because without it a CA restricted to one
purpose can issue for another, which is the cross-purpose
confusion EKU on a CA exists to prevent. The check is chain
self-consistency rather than caller policy: a leaf claiming a
purpose its own issuer forbids is contradictory whatever the
caller asked about, so it does not depend on
required_leaf_eku being set.
What it does:
- A CA with no
ExtendedKeyUsageextension constrains nothing. This is the common case and stays free. - A CA whose EKU contains
anyExtendedKeyUsageconstrains nothing. - Otherwise the permitted set narrows by intersection down the chain. Two CAs with disjoint EKUs leave nothing issuable and the path is refused.
- A leaf carrying an EKU must share at least one purpose with the
permitted set. Intersection, not containment: a leaf listing
serverAuthandclientAuthunder aserverAuth-only intermediate is accepted, because the unusable extra claim is not a reason to refuse a chain that works for what it is being used for. That pattern is common in the realWebPKI. - A leaf with no EKU is not refused by this check — it claims no
purpose to contradict.
required_leaf_ekuis what rejects such a leaf where a purpose is demanded, and it is additionally checked against the permitted set.
Turn it off for a PKI that puts EKUs on CA certificates decoratively rather than restrictively.
§Known tension: delegated OCSP responders
RFC 6960 §4.2.2.2 has a CA designate a responder by issuing it a
certificate carrying id-kp-OCSPSigning. It does not require the
CA itself to carry that purpose — so a CA restricted to
serverAuth, which is what the CA/B Forum requires of a TLS
subordinate, cannot designate a responder without failing this
check. Other implementations carve id-kp-OCSPSigning out of
nesting for exactly this reason.
No carve-out is made here, because nothing in this workspace needs
one: pkix_revocation’s OCSP code establishes a CA-designated
responder by checking the responder certificate’s own EKU and its
issuance by the subject’s CA, and never validates the responder as
a path through this function. A caller who does validate a
delegated responder certificate as a path under an EKU-restricted
CA will see Error::EkuNotPermittedByIssuer, and wants this flag
off for that call. Said here rather than carved out silently, so
the choice is visible to whoever hits it.
require_crl_sign_on_cas: boolRequire cRLSign in KeyUsage on every intermediate CA. Default: false.
When true, an intermediate certificate whose KeyUsage extension is
present but does not include cRLSign will be rejected with
Error::CrlSignMissing. Certificates with no KeyUsage extension
are not affected.
RFC 5280 §6.1 does not mandate this check — it conflates path validation
with revocation infrastructure. PKITS §4.7.4 and §4.7.5 nonetheless
expect such chains to fail because a CA cert without cRLSign cannot
revoke certs it issued. Enable this flag to restore PKITS conformance
or to enforce a stricter “every CA must be able to sign CRLs” rule.
This check is independent of enforce_key_usage:
enforce_key_usage governs the RFC-mandated keyCertSign check, while
require_crl_sign_on_cas adds a separate cRLSign requirement.
initial_explicit_policy: boolInitial explicit-policy indicator (RFC 5280 §6.1.1).
When true, path validation requires that at least one valid policy exists
from the initial policy set. When false (the default), any valid path is
accepted even if no certificate policy is asserted.
initial_any_policy_inhibit: boolInitial any-policy inhibit indicator (RFC 5280 §6.1.1).
When true, the anyPolicy OID is not considered a match for any other
policy at the start of the path. When false (the default), anyPolicy
is accepted as a wildcard unless later inhibited by a CA certificate.
initial_policy_mapping_inhibit: boolInitial policy-mapping inhibit indicator (RFC 5280 §6.1.1).
When true, policy mappings are not permitted in any certificate in the
chain. When false (the default), policy mappings are allowed.
initial_policy_set: Vec<ObjectIdentifier>Initial user-requested policy set (RFC 5280 §6.1.1).
The set of certificate policies acceptable to the relying party. An empty
vec, or any set that contains anyPolicy (2.5.29.32.0), is the RFC’s
any-policy value: all policies are acceptable and the policy graph is
not intersected (§6.1.5(g)(ii)). Otherwise the final graph keeps only
policies in this set (§6.1.5(g)(iii)).
Note: this is pub but clones the OID set, so prefer constructing once
and reusing the ValidationPolicy.
max_validity_secs: Option<u64>If Some(n), reject any certificate whose (notAfter − notBefore) exceeds
n seconds. None means unconstrained (the default).
Applied to every certificate in the chain, not just the leaf.
Violations produce Error::ValidityPeriodExceedsMax.
allowed_signature_algs: Option<Vec<ObjectIdentifier>>If Some(list), reject any certificate whose signature algorithm OID is
not in list. None means any algorithm is accepted (the default).
Applied to every certificate in the chain. The check fires before
signature verification so the error is diagnostic rather than a confusing
Error::SignatureInvalid.
Violations produce Error::AlgorithmNotAllowed.
min_rsa_key_bits: Option<u32>If Some(bits), reject any certificate carrying an RSA public key whose
modulus is fewer than bits bits. Both rsaEncryption and
id-RSASSA-PSS subject keys count as RSA; other keys are not affected.
None means unconstrained (the default).
Applied to the subject key of every certificate in the chain, leaf
included. The trust anchor’s key is not checked: it is caller
configuration, not path input, so filter weak anchors when building
the trust store.
Violations produce Error::KeyTooSmall.
require_subject_alt_name: boolIf true, the leaf certificate (chain index 0) must have a non-empty
SubjectAltName extension. false means no SAN requirement (the default).
Intermediate CA certificates are not checked by this field.
Violations produce Error::MissingSan.
require_rfc822_san: boolIf true, at least one rfc822Name entry must be present in the leaf’s
SubjectAltName extension.
Only meaningful when require_subject_alt_name
is also true. When require_subject_alt_name is false, this field has
no effect.
Default: false (backward compatible).
Violations produce Error::MissingRfc822San.
required_leaf_eku: Option<Vec<ObjectIdentifier>>If Some(oids), the leaf certificate must explicitly assert every OID in
oids via its ExtendedKeyUsage extension. None means no EKU requirement
(the default).
anyExtendedKeyUsage (2.5.29.37.0) does not satisfy a specific OID
check — each required OID must be listed in the cert’s EKU extension.
Violations produce Error::MissingEku.
required_leaf_policy_oids: Option<Vec<ObjectIdentifier>>If Some(oids), the leaf certificate must explicitly assert every OID
in oids via its CertificatePolicies extension. None means no
policy-OID assertion requirement (the default).
Distinct from initial_policy_set:
initial_policy_set is the relying party’s acceptable policy set
(RFC 5280 §6.1.1, user-initial-policy-set).
required_leaf_policy_oids requires assertion — the OID must appear
on the leaf cert’s CertificatePolicies extension, independent of the
policy tree.
anyPolicy (2.5.29.32.0) does not satisfy a specific OID check.
Violations produce Error::MissingLeafPolicyOid.
This field follows the required_leaf_eku
precedent: leaf-only, opt-in, additive. Intended for CA/B Forum
subscriber-profile tier disambiguation where a tier mandates assertion
of a specific reserved policy OID.
required_leaf_subject_dn_attrs: Option<DnAttrRule>If Some(rule), the leaf certificate’s Subject DN must satisfy
rule. None means no Subject DN requirement (the default).
Violations produce Error::SubjectDnAttrRuleUnmet. See
DnAttrRule for the expression grammar and vacuity rules.
This field follows the required_leaf_eku
precedent: leaf-only, opt-in, additive. Intended for CA/B Forum
subscriber-profile tier disambiguation (e.g., S/MIME
Organization-validated tier requires organizationName).
Implementations§
Source§impl ValidationPolicy
impl ValidationPolicy
Sourcepub fn new(now_unix: u64) -> Self
pub fn new(now_unix: u64) -> Self
Construct a policy with the given time and sensible defaults.
This is the only constructor: it forces the caller to supply a timestamp,
preventing the silent validity failures that a Default with
current_time_unix = 0 would cause.
§What now_unix selects, and what it does not
now_unix is the moment at which validity periods are
evaluated: notBefore <= now_unix <= notAfter for every
certificate in the chain, and the freshness of any CRL or OCSP
response a revocation checker consults.
It does not select which version of any rule set is in force.
The rules applied are the ones encoded in this
ValidationPolicy’s own fields at the moment you build it, which
are this workspace’s current reading of the specifications.
Passing a now_unix of 2019 does not validate the chain against
the CA/B Forum Baseline Requirements as they stood in 2019; it
validates against today’s rules, asking whether the certificates
were within their validity periods in 2019.
The distinction has a sharp edge, which is why it is spelled out
rather than left to be inferred: a chain whose certificates have
expired fails for the clock, and a chain issued under a rule this
workspace now enforces more strictly fails for the rules, and
moving now_unix changes only the first.
§A third thing, easy to confuse with the second
Some rules are themselves written to change on a date, and those
dates belong to the rule rather than to now_unix. CA/B Forum
Ballot SC-081’s validity cap steps down on fixed dates, and
pkix_profiles_cabf::sc081_validity_cap takes the certificate’s
notBefore for exactly that reason: SC-081 says the cap in
force at issuance governs a certificate for its whole life, so a
relying party’s clock is the wrong input and would reject
certificates issued legitimately under an earlier cap. That is
the current rule set being date-dependent, not an older rule set
being selected.
§Evaluating against the rules of a past date
This workspace does not offer that, deliberately: it evaluates
against the current regime only. For a version-pinned historical
judgement, use pkix-policy-zlint with a pinned lint set, which
is an out-of-process oracle and can carry a rule set this one
does not.
Trait Implementations§
Source§impl Clone for ValidationPolicy
impl Clone for ValidationPolicy
Source§impl Debug for ValidationPolicy
impl Debug for ValidationPolicy
Source§impl<'de> Deserialize<'de> for ValidationPolicy
Available on crate feature serde only.
impl<'de> Deserialize<'de> for ValidationPolicy
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ValidationPolicy
Source§impl PartialEq for ValidationPolicy
impl PartialEq for ValidationPolicy
Source§impl Serialize for ValidationPolicy
Available on crate feature serde only.
impl Serialize for ValidationPolicy
serde only.