pub struct MtlsIdentity { /* private fields */ }Expand description
A single-sided mTLS identity: a CA that signs one leaf certificate.
Each side of the mTLS connection generates its own MtlsIdentity. Only the
CA certificate (public) is shared with the peer — private keys never leave
the process that generated them.
Host (client) Container (server)
───────────────── ─────────────────────
MtlsIdentity::generate_client() MtlsIdentity::generate_server()
├─ client CA cert ──────────────► trusted by server (verifies client)
├─ client leaf cert (in memory) ├─ server CA cert ◄── output to stdout
└─ client leaf key (in memory) ├─ server leaf cert (in memory)
└─ server leaf key (in memory)
host trusts server CA cert ◄──────── parsed from stdoutImplementations§
Source§impl MtlsIdentity
impl MtlsIdentity
Sourcepub fn generate_client() -> Result<Self>
pub fn generate_client() -> Result<Self>
Generate a client identity (CA + client leaf cert).
Sourcepub fn generate_server() -> Result<Self>
pub fn generate_server() -> Result<Self>
Generate a server identity (CA + server leaf cert with localhost SANs).
Sourcepub fn ca_cert_pem(&self) -> Result<String>
pub fn ca_cert_pem(&self) -> Result<String>
Get the CA certificate PEM (public, safe to share with the peer).
Sourcepub fn create_server_config(
&self,
trusted_client_ca_pem: &str,
) -> Result<ServerConfig>
pub fn create_server_config( &self, trusted_client_ca_pem: &str, ) -> Result<ServerConfig>
Build a rustls::ServerConfig that serves with this identity’s leaf
cert and trusts the given client CA PEM for client authentication.
Sourcepub fn create_client_config(
&self,
trusted_server_ca_pem: &str,
) -> Result<ClientConfig>
pub fn create_client_config( &self, trusted_server_ca_pem: &str, ) -> Result<ClientConfig>
Build a rustls::ClientConfig that authenticates with this identity’s
leaf cert and trusts the given server CA PEM.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MtlsIdentity
impl !RefUnwindSafe for MtlsIdentity
impl Send for MtlsIdentity
impl Sync for MtlsIdentity
impl Unpin for MtlsIdentity
impl UnsafeUnpin for MtlsIdentity
impl !UnwindSafe for MtlsIdentity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more