Skip to main content

PeerIdentity

Trait PeerIdentity 

Source
pub trait PeerIdentity:
    Debug
    + Send
    + Sync {
    // Required method
    fn check(&self, leaf: &PeerLeaf<'_>) -> Result<(), Error>;
}
Expand description

An application’s check of the peer’s identity, run after every crate check has passed.

On the client verifier it can only refuse. On the server verifier it replaces the name check, so it is the only identity decision: its Ok admits the peer whatever server name the client connected with. Its Err is returned unchanged. A panic inside it fails the handshake.

A resumed session does not call it again: rustls reuses the earlier decision. A check whose answer can change needs a new verifier and configuration when it changes, or resumption disabled.

A check for one workload’s URI, which compares the whole identity and refuses a leaf that carries more than one:

use crypto_profile_awslc3::{Options, Profile, resolve, rustls, tls};
use std::sync::Arc;

#[derive(Debug)]
struct Workload(&'static str);

impl tls::PeerIdentity for Workload {
    fn check(&self, leaf: &tls::PeerLeaf<'_>) -> Result<(), rustls::Error> {
        match leaf.uri_names()?.as_slice() {
            [one] if *one == self.0 => Ok(()),
            _ => Err(rustls::Error::General("peer is not the expected workload".into())),
        }
    }
}

let policy = resolve(Profile::Fips1403, Options::default())?.tls;
let verifier = tls::server_cert_verifier_builder(roots(), &policy)?
    .with_peer_identity(Arc::new(Workload("spiffe://example.org/payments")))
    .build()?;

Required Methods§

Source

fn check(&self, leaf: &PeerLeaf<'_>) -> Result<(), Error>

Refuses leaf unless it carries the expected identity.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§