Skip to main content

DefaultCertificateVerifier

Struct DefaultCertificateVerifier 

Source
pub struct DefaultCertificateVerifier<C: CryptoProvider> { /* private fields */ }
Expand description

Default certificate validator that can handle both X509 chains and raw public keys.

Validates X.509 chains and raw public keys against configured trust anchors. Use with_roots to seed X.509 root CAs and with_raw_keys to pin raw public keys (RFC 7250).

Call danger_with_no_verification to skip all validation. Intended for testing only.

This is the recommended CertificateVerifier unless you are working with very tiny embedded systems that only need one or more pinned keys.

§Examples

use tls2::{CertificateVerifier, ClientConfig, DefaultCertificateVerifier, RawPublicKey, SignatureScheme};

// Full X.509 validation with system roots (requires `std` feature)
let verifier = DefaultCertificateVerifier::new(DefaultCryptoProvider).with_system_roots();

// Pin raw public keys only, reject everything else
let pinned = RawPublicKey::new(SignatureScheme::Ed25519, b"...key bytes...");
let verifier = DefaultCertificateVerifier::new().with_raw_keys([pinned]);

// Testing mode — accept anything
let verifier = DefaultCertificateVerifier::new().danger_with_no_verification();

Implementations§

Source§

impl<C: CryptoProvider> DefaultCertificateVerifier<C>

Source

pub fn new(crypto: C) -> Self

Create a new verifier with no trust anchors configured.

By default:

  • No X.509 roots are configured — X.509 chains are rejected.
  • No raw public keys are pinned — raw public keys are rejected.

Use the builder methods (with_roots, with_system_roots, with_raw_keys, danger_with_no_verification) to configure the verifier.

Source

pub fn with_system_roots(self) -> Self

Load root CAs from the operating system’s trust store.

Source

pub fn with_roots(self, custom_roots: impl IntoIterator<Item = RootCa>) -> Self

Add custom root trust anchors.

Source

pub fn with_raw_keys(self, keys: impl IntoIterator<Item = RawPublicKey>) -> Self

Pin raw public keys as trust anchors (RFC 7250).

When raw keys are configured, only received raw public keys that match one of the pinned entries are accepted. X.509 chains are not affected by this list.

Source

pub fn danger_with_no_verification(self) -> Self

Skip all certificate validation.

Every certificate — X.509 chain or raw public key — is accepted without any checks. Insecure; intended for testing only.

Source

pub fn with_clock(self, clock: Arc<dyn Clock>) -> Self

Use a custom clock for certificate validity checks.

When no clock is set, DefaultCertificateVerifier falls back to std::time::SystemTime if the std feature is enabled. Without std and without a custom clock, validation returns Error::CertificateClockMissing.

Trait Implementations§

Source§

impl<C: CryptoProvider> CertificateVerifier for DefaultCertificateVerifier<C>

Source§

fn verify_certificate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, cert: &'life1 ReceivedCertificate<'_>, server_name: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

impl<C: Clone + CryptoProvider> Clone for DefaultCertificateVerifier<C>

Source§

fn clone(&self) -> DefaultCertificateVerifier<C>

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

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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.