Skip to main content

ClientCertificate

Struct ClientCertificate 

Source
pub struct ClientCertificate<'a> { /* private fields */ }
Available on crate feature mtls only.
Expand description

A client certificate the HOST has already verified, decomposed into the facts RFC 8705 matches on.

Read the module docs on the trust boundary before constructing one. Nothing in this type is a secret and nothing here is redacted in Debug: a certificate is a public document, and what authenticates the client is possession of the private key, which the TLS handshake proved to the HOST and which this crate never sees.

Everything borrows, so building one allocates nothing but the thumbprint’s hash, and passing it into the token endpoint costs one pointer.

Implementations§

Source§

impl<'a> ClientCertificate<'a>

Source

pub fn from_der(der: &[u8]) -> Self

From the DER encoding of the VERIFIED certificate: this crate cannot check the chain and takes the bytes as an established fact, so read this module’s trust boundary section before choosing where they come from. Bytes off an unstripped X-Client-Cert header authenticate nobody.

The thumbprint (RFC 8705 section 3.1) is computed here, once, so no caller has to decide which bytes to hash or which base64 alphabet to use.

The subject DN and the SAN entries default to absent; add whichever the deployment registers clients by. A certificate with no facts attached can still be BOUND to a token (section 3), which is why they are optional rather than required: section 4 makes certificate binding available to a client that does not authenticate with mutual TLS at all.

Source

pub fn from_thumbprint(thumbprint: CertificateThumbprint) -> Self

From a thumbprint the host computed itself, for a deployment whose TLS terminator forwards a fingerprint rather than the certificate (nginx’s $ssl_client_fingerprint, an ALB’s header). The host is then responsible for the encoding, which is why ClientCertificate::from_der is the constructor to prefer where the DER is available.

Source

pub fn with_subject_dn(self, dn: &'a str) -> Self

The subject distinguished name, in the RFC 4514 string representation.

The comparison this crate performs is EXACT STRING EQUALITY against the registered value (see ExpectedSubject::SubjectDn), so the host must produce the same spelling its registrations use. RFC 8705 section 2.1 allows a server to implement a more sophisticated DN comparison; this crate deliberately does not, because a partial DN parser that gets attribute ordering, escaping or case folding subtly wrong is a way to make two different subjects compare equal, and that is an authentication bypass rather than an inconvenience.

Source

pub fn with_san_dns(self, entries: &'a [&'a str]) -> Self

The dNSName subjectAltName entries.

Source

pub fn with_san_uri(self, entries: &'a [&'a str]) -> Self

The uniformResourceIdentifier subjectAltName entries.

Source

pub fn with_san_ip(self, entries: &'a [&'a str]) -> Self

The iPAddress subjectAltName entries, in their textual form.

Source

pub fn with_san_email(self, entries: &'a [&'a str]) -> Self

The rfc822Name subjectAltName entries.

Source

pub fn thumbprint(&self) -> &CertificateThumbprint

This certificate’s RFC 8705 section 3.1 thumbprint, which is what a token gets bound to.

Trait Implementations§

Source§

impl<'a> Clone for ClientCertificate<'a>

Source§

fn clone(&self) -> ClientCertificate<'a>

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<'a> Debug for ClientCertificate<'a>

Source§

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

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

impl<'a> Eq for ClientCertificate<'a>

Source§

impl<'a> PartialEq for ClientCertificate<'a>

Source§

fn eq(&self, other: &ClientCertificate<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for ClientCertificate<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ClientCertificate<'a>

§

impl<'a> RefUnwindSafe for ClientCertificate<'a>

§

impl<'a> Send for ClientCertificate<'a>

§

impl<'a> Sync for ClientCertificate<'a>

§

impl<'a> Unpin for ClientCertificate<'a>

§

impl<'a> UnsafeUnpin for ClientCertificate<'a>

§

impl<'a> UnwindSafe for ClientCertificate<'a>

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> 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.