pub struct X509Resolver { /* private fields */ }x509 only.Expand description
Resolves a KeyReference::X509Chain, the x5c header of a token (RFC 7515 §4.1.6), to
the public key of its first certificate once the chain validates against a trust anchor;
every other reference is Unsupported.
This is the Inline X.509 Certificates mechanism of SD-JWT VC §3.5, which the OpenID4VC High Assurance Interoperability Profile (HAIP) 1.0 mandates for SD-JWT VCs (§6.1.1), for Status List Tokens (§6.1) and for the signed requests, metadata and attestations of OID4VCI and OID4VP.
§What is checked
The application supplies the trust anchors; the crate ships none, and a certificate is
never trusted because the token carries it. For a chain [leaf, intermediate…]:
- The chain has at least one and at most
MAX_CHAIN_LENGTHcertificates. - Every certificate of the chain reads as one, and the leaf is not self-issued (its
subject is not its issuer), which HAIP requires of every
x5cit defines: “The X.509 certificate signing the request MUST NOT be self-signed.” - A path from the leaf to a trust anchor validates, at the validation time: each
signature, each validity period,
basicConstraintsand the path length, name constraints on DNS names, and no critical extension that is not understood. The certificates after the leaf are a pool to build the path from, so their order does not matter, and one that is itself a trust anchor adds nothing. Path building and these checks arerustls-webpki’s. - Every CA certificate of the path that has a
keyUsageextension assertskeyCertSign(RFC 5280 §6.1.4), the trust anchor included. - The trust anchor the path ends at is within its own validity period.
- A leaf that has a
keyUsageextension assertsdigitalSignatureornonRepudiation(contentCommitment, which qualified seal certificates carry alone), and notkeyCertSign(RFC 5280 §4.2.1.3). - The leaf’s key is one a JWS can be verified with: P-256, P-384, secp256k1 (feature
secp256k1), Ed25519 or RSA of at least 2048 bits.
Certificates are signed with ECDSA on P-256 or P-384, Ed25519, or RSA from 2048 bits, with SHA-256, SHA-384 or SHA-512. SHA-1, P-521 and Brainpool curves are refused.
§What is not checked
- Revocation. Neither CRLs nor OCSP are consulted. An application that needs it checks the chain itself, or keeps its trust anchors current.
- Extended key usage and certificate policies. SD-JWT VC and HAIP define none for
credential issuers, so any is accepted. The
KeyRolemakes no difference either: a chain is validated the same for an issuer and for a holder. - Name constraints on anything but DNS names, which is why only a DNS name binds an
iss(X509Certificate::binds). - Whether the chain leaves out the trust anchor. HAIP forbids an issuer to include it. A verifier that pins an intermediate CA cannot tell an issuer’s chain that includes it from a violation, and a copy of an anchor adds no trust, so such a chain validates.
- Who the subject is. A valid chain says the key belongs to the subject of the leaf
under one of the trust anchors, not that this subject may issue a given credential:
that is the application’s policy, with
X509Certificateto read the subject from.
§The issuer of a token
With x5c, the issuer is the subject of the leaf certificate, and an iss claim is not
authenticated by the chain (SD-JWT VC §3.5). KeyReference::binds_to therefore accepts
an iss only when the leaf binds it, as an https URL whose host is one of its DNS names
(X509Certificate::binds), and the SD-JWT VC validator accepts a credential without
iss.
Every CA under the trust anchors is trusted to certify the names it puts in a leaf, the
subject included: name constraints restrict DNS names in the Subject Alternative Name
extension, not a common name. Which mechanism verifies a token also follows from what the
token carries, a chain or a kid, whenever the application configures resolvers for both;
an application that must pin one mechanism per issuer (SD-JWT VC §3.5 asks that an
attacker cannot choose it) checks the KeyReference the validator returns, or gives each
issuer’s tokens a validator with the one resolver.
§Time
A validator passes its validation time through KeyResolver::resolve_key_at;
resolve_key validates at the current time. A resolver that
wraps this one must forward resolve_key_at, or its chains are validated at the current
time whatever the validator asks.
Implementations§
Source§impl X509Resolver
impl X509Resolver
Sourcepub const MAX_CHAIN_LENGTH: usize = 10
pub const MAX_CHAIN_LENGTH: usize = 10
The most certificates an x5c chain may hold.
Sourcepub fn new<I, C>(anchors: I) -> Result<Self, X509Error>
pub fn new<I, C>(anchors: I) -> Result<Self, X509Error>
A resolver trusting anchors, DER-encoded certificates: root CAs, or any CA
certificate the application pins.
Each anchor must be a CA certificate, one whose basicConstraints say cA and whose
keyUsage, if it has one, asserts keyCertSign: whoever holds the key of an anchor
can issue certificates this resolver accepts, so a certificate that signs credentials
is refused as an anchor. A resolver without anchors
refuses every chain.
§Errors
X509Error::InvalidCertificate when an anchor is not a certificate, and
X509Error::TrustAnchorNotCa when it is not a CA certificate.
Sourcepub fn from_pem(pem: &str) -> Result<Self, X509Error>
pub fn from_pem(pem: &str) -> Result<Self, X509Error>
A resolver trusting every certificate of pem, a concatenation of
-----BEGIN CERTIFICATE----- blocks.
§Errors
X509Error::InvalidPem when pem does not read as PEM or holds no certificate, and
X509Error::InvalidCertificate when one of them is not a certificate.
Sourcepub fn validate(&self, chain: &[Vec<u8>], now: i64) -> Result<Jwk, X509Error>
pub fn validate(&self, chain: &[Vec<u8>], now: i64) -> Result<Jwk, X509Error>
Validates chain, the certificates of an x5c header, leaf first and DER-encoded, at
now (seconds since the Unix epoch), and returns the public key of the leaf.
§Errors
An X509Error naming the first check of the type documentation that fails.
Trait Implementations§
Source§impl Clone for X509Resolver
impl Clone for X509Resolver
Source§impl Debug for X509Resolver
impl Debug for X509Resolver
Source§impl KeyResolver for X509Resolver
impl KeyResolver for X509Resolver
Source§fn resolve_key<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyReference,
role: KeyRole,
) -> Pin<Box<dyn Future<Output = Result<Jwk, KeyResolutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn resolve_key<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyReference,
role: KeyRole,
) -> Pin<Box<dyn Future<Output = Result<Jwk, KeyResolutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn resolve_key_at<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyReference,
__arg2: KeyRole,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<Jwk, KeyResolutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn resolve_key_at<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 KeyReference,
__arg2: KeyRole,
now: i64,
) -> Pin<Box<dyn Future<Output = Result<Jwk, KeyResolutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
key names, usable in role at now, the validation time in seconds
since the Unix epoch. Read more