Struct PinnedServerCertVerifier

Source
pub struct PinnedServerCertVerifier<T>
where T: AsRef<[Certificate]> + Send + Sync,
{ /* private fields */ }
Expand description

A struct for TLS clients to verify the server’s certificate. Implements certificate pinning. It accepts the server’s certificate if it is identical to any of the certificates in the struct.

The rustls library has an open issue to add something like this: “Implement support for certificate pinning” https://github.com/ctz/rustls/issues/227

§Example

use std::net::TcpStream;
use std::sync::Arc;
use rustls_pin::{
    arbitrary_dns_name,
    PinnedServerCertVerifier
};
let mut tcp_stream =
    TcpStream::connect(addr).unwrap();
let mut config = rustls::ClientConfig::new();
config.dangerous().set_certificate_verifier(
    Arc::new(
        PinnedServerCertVerifier::new(vec![
            server_cert1,
            server_cert2
        ]),
    )
);
let mut session = rustls::ClientSession::new(
    &Arc::new(config),
    arbitrary_dns_name().as_ref()
);
let mut stream = rustls::Stream::new(
    &mut session, &mut tcp_stream);

Implementations§

Source§

impl<T> PinnedServerCertVerifier<T>
where T: AsRef<[Certificate]> + Send + Sync,

Source

pub fn new(certs: T) -> Self

Trait Implementations§

Source§

impl<T> ServerCertVerifier for PinnedServerCertVerifier<T>
where T: AsRef<[Certificate]> + Send + Sync,

Source§

fn verify_server_cert( &self, _roots: &RootCertStore, presented_certs: &[Certificate], _dns_name: DNSNameRef<'_>, _ocsp_response: &[u8], ) -> Result<ServerCertVerified, TLSError>

Verify a the certificate chain presented_certs against the roots configured in roots. Make sure that dns_name is quoted by the top certificate in the chain.
Source§

fn verify_tls12_signature( &self, message: &[u8], cert: &Certificate, dss: &DigitallySignedStruct, ) -> Result<HandshakeSignatureValid, TLSError>

Verify a signature allegedly by the given server certificate. Read more
Source§

fn verify_tls13_signature( &self, message: &[u8], cert: &Certificate, dss: &DigitallySignedStruct, ) -> Result<HandshakeSignatureValid, TLSError>

Verify a signature allegedly by the given server certificate. Read more
Source§

fn supported_verify_schemes(&self) -> Vec<SignatureScheme>

Return the list of SignatureSchemes that this verifier will handle, in verify_tls12_signature and verify_tls13_signature calls. 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> 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, 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.