Skip to main content

X509Resolver

Struct X509Resolver 

Source
pub struct X509Resolver { /* private fields */ }
Available on crate feature 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…]:

  1. The chain has at least one and at most MAX_CHAIN_LENGTH certificates.
  2. 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 x5c it defines: “The X.509 certificate signing the request MUST NOT be self-signed.”
  3. A path from the leaf to a trust anchor validates, at the validation time: each signature, each validity period, basicConstraints and 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 are rustls-webpki’s.
  4. Every CA certificate of the path that has a keyUsage extension asserts keyCertSign (RFC 5280 §6.1.4), the trust anchor included.
  5. The trust anchor the path ends at is within its own validity period.
  6. A leaf that has a keyUsage extension asserts digitalSignature or nonRepudiation (contentCommitment, which qualified seal certificates carry alone), and not keyCertSign (RFC 5280 §4.2.1.3).
  7. 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 KeyRole makes 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 X509Certificate to 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

Source

pub const MAX_CHAIN_LENGTH: usize = 10

The most certificates an x5c chain may hold.

Source

pub fn new<I, C>(anchors: I) -> Result<Self, X509Error>
where I: IntoIterator<Item = C>, C: Into<Vec<u8>>,

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.

Source

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.

Source

pub fn anchors(&self) -> impl Iterator<Item = &[u8]>

The trust anchors, DER-encoded.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for X509Resolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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,

The public key key names, usable in role. Read more
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,

The public key key names, usable in role at now, the validation time in seconds since the Unix epoch. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more