pub struct MutualTlsManager { /* private fields */ }Expand description
Mutual TLS manager for OAuth 2.0
Implementations§
Source§impl MutualTlsManager
impl MutualTlsManager
Sourcepub fn add_ca_certificate(&mut self, ca_cert: Vec<u8>) -> Result<()>
pub fn add_ca_certificate(&mut self, ca_cert: Vec<u8>) -> Result<()>
Add a trusted CA certificate (DER).
Trust anchors are used as given: an anchor’s own pathLen is not enforced by the
verifier, so constrain intermediates (not the anchor) with pathLen.
The certificate must parse as a single X.509 certificate and assert
basicConstraints: cA = TRUE. It becomes a trust anchor for every PKI client
that does not carry its own ca_certificates.
Sourcepub async fn register_client(&self, config: MutualTlsClientConfig) -> Result<()>
pub async fn register_client(&self, config: MutualTlsClientConfig) -> Result<()>
Register a client for Mutual TLS authentication.
A PkiMutualTls client must be bound to its certificate: set client_certificate
(exact certificate pin) or expected_subject_dn (exact subject DN), otherwise any
certificate issued by a trusted CA would authenticate as this client.
Sourcepub async fn authenticate_client(
&self,
client_id: &str,
client_certificate: &[u8],
) -> Result<MutualTlsAuthResult>
pub async fn authenticate_client( &self, client_id: &str, client_certificate: &[u8], ) -> Result<MutualTlsAuthResult>
Authenticate a client using Mutual TLS.
§Security: where the certificate bytes come from
This validates a certificate; it cannot tell whether the peer holds its private key. Pass only the certificate that your TLS acceptor verified the client’s possession of (the handshake’s peer certificate), or one forwarded by a terminating proxy that strips any client-supplied copy of the header it uses. Never pass a certificate read from a request header or body that the client controls: a public certificate is not a secret.
Equivalent to authenticate_client_with_chain
with no intermediate certificates.
Sourcepub async fn authenticate_client_with_chain(
&self,
client_id: &str,
client_certificate: &[u8],
intermediates: &[Vec<u8>],
) -> Result<MutualTlsAuthResult>
pub async fn authenticate_client_with_chain( &self, client_id: &str, client_certificate: &[u8], intermediates: &[Vec<u8>], ) -> Result<MutualTlsAuthResult>
Authenticate a client using Mutual TLS, with the intermediate certificates the client presented in the TLS handshake (DER, any order).
For PkiMutualTls the chain is built and verified by rustls-webpki (signatures,
validity of every certificate, basicConstraints and pathLen, name constraints,
clientAuth extended key usage), the trust anchors are the client’s own
ca_certificates when set and the manager’s CA store otherwise (never empty), and the
certificate must be bound to the client (see register_client).
Sourcepub fn create_certificate_confirmation(
&self,
client_certificate: &[u8],
) -> Result<CertificateConfirmation>
pub fn create_certificate_confirmation( &self, client_certificate: &[u8], ) -> Result<CertificateConfirmation>
Create certificate-bound access token confirmation
Sourcepub fn validate_certificate_bound_token(
&self,
token_confirmation: &CertificateConfirmation,
client_certificate: &[u8],
) -> Result<bool>
pub fn validate_certificate_bound_token( &self, token_confirmation: &CertificateConfirmation, client_certificate: &[u8], ) -> Result<bool>
Validate certificate-bound access token
Sourcepub async fn validate_client_certificate(
&self,
client_certificate: &[u8],
client_id: &str,
) -> Result<()>
pub async fn validate_client_certificate( &self, client_certificate: &[u8], client_id: &str, ) -> Result<()>
Validate a client certificate for mTLS authentication, returning an error unless
the certificate authenticates client_id.
The same rule applies as for authenticate_client: the
bytes must come from the TLS handshake (or a proxy that strips client-supplied copies),
never from data the client chose.
Uses the same validation as authenticate_client.
Sourcepub async fn validate_client_certificate_with_chain(
&self,
client_certificate: &[u8],
intermediates: &[Vec<u8>],
client_id: &str,
) -> Result<()>
pub async fn validate_client_certificate_with_chain( &self, client_certificate: &[u8], intermediates: &[Vec<u8>], client_id: &str, ) -> Result<()>
Like validate_client_certificate, with the
intermediate certificates presented by the client.
Trait Implementations§
Source§impl Debug for MutualTlsManager
impl Debug for MutualTlsManager
Auto Trait Implementations§
impl !Freeze for MutualTlsManager
impl !RefUnwindSafe for MutualTlsManager
impl !UnwindSafe for MutualTlsManager
impl Forget for MutualTlsManager
impl Send for MutualTlsManager
impl Sync for MutualTlsManager
impl Unpin for MutualTlsManager
impl UnsafeUnpin for MutualTlsManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more