Struct rustls_pin::PinnedServerCertVerifier[][src]

pub struct PinnedServerCertVerifier<T> where
    T: AsRef<[Certificate]> + Send + Sync
{ /* fields omitted */ }

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

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

pub fn new(certs: T) -> Self[src]

Trait Implementations

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

Auto Trait Implementations

impl<T> RefUnwindSafe for PinnedServerCertVerifier<T> where
    T: RefUnwindSafe

impl<T> Send for PinnedServerCertVerifier<T>

impl<T> Sync for PinnedServerCertVerifier<T>

impl<T> Unpin for PinnedServerCertVerifier<T> where
    T: Unpin

impl<T> UnwindSafe for PinnedServerCertVerifier<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.