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>
impl<C: CryptoProvider> DefaultCertificateVerifier<C>
Sourcepub fn new(crypto: C) -> Self
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.
Sourcepub fn with_system_roots(self) -> Self
pub fn with_system_roots(self) -> Self
Load root CAs from the operating system’s trust store.
Sourcepub fn with_roots(self, custom_roots: impl IntoIterator<Item = RootCa>) -> Self
pub fn with_roots(self, custom_roots: impl IntoIterator<Item = RootCa>) -> Self
Add custom root trust anchors.
Sourcepub fn with_raw_keys(self, keys: impl IntoIterator<Item = RawPublicKey>) -> Self
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.
Sourcepub fn danger_with_no_verification(self) -> Self
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.
Sourcepub fn with_clock(self, clock: Arc<dyn Clock>) -> Self
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>
impl<C: CryptoProvider> CertificateVerifier for DefaultCertificateVerifier<C>
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>
impl<C: Clone + CryptoProvider> Clone for DefaultCertificateVerifier<C>
Source§fn clone(&self) -> DefaultCertificateVerifier<C>
fn clone(&self) -> DefaultCertificateVerifier<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more