Skip to main content

TlsConfig

Struct TlsConfig 

Source
pub struct TlsConfig { /* private fields */ }
Expand description

What a store needs to speak TLS to somewhere this machine does not already trust.

Data only — no client type appears anywhere in it, which is what makes it the same three settings in all seven crates and what makes it expressible from a language that has never heard of tonic.

Empty by default, and an empty one is not “no TLS”: it is the platform’s own trust store, which is what a public certificate authority needs and what every store already did.

See the module documentation for what each store can express.

Implementations§

Source§

impl TlsConfig

Source

pub fn new() -> TlsConfig

An empty configuration: the platform’s trust store, no client certificate.

Source

pub fn with_ca_certificate_file(self, path: impl Into<PathBuf>) -> TlsConfig

Trust the certificate authority in this PEM file.

The file may hold several certificates; all of them are trusted, which is what a private CA with an intermediate needs.

The file is read when the store builds its client, not here — so a rotated CA is picked up by rebuilding the source, and a missing file is an error naming it rather than a panic in a builder chain.

Source

pub fn with_ca_certificate_pem(self, pem: impl Into<Vec<u8>>) -> TlsConfig

Trust the certificate authority in these PEM bytes.

For a program that already has the material — from a secrets manager, from its own configuration — and should not have to put it on a disk for a client to read back.

Source

pub fn with_client_certificate_files( self, certificate: impl Into<PathBuf>, key: impl Into<PathBuf>, ) -> TlsConfig

Present this client certificate and private key (mTLS).

Both are PEM files. certificate may be a chain; the leaf comes first, as every TLS stack here expects.

Source

pub fn with_client_certificate_pem( self, certificate: impl Into<Vec<u8>>, key: impl Into<Vec<u8>>, ) -> TlsConfig

Present this client certificate and private key (mTLS), from bytes.

The private key is the sharpest secret this crate handles. It is never rendered by Debug, never quoted into an error, and never written anywhere: it goes from here into the client’s own key type and stops.

Source

pub fn with_server_name(self, name: impl Into<String>) -> TlsConfig

Verify the certificate against this name rather than the address’s.

For an endpoint written as an IP — a Service’s cluster IP, a load balancer, a NodePort — against a certificate issued for a hostname. The certificate still has to chain to a trusted authority and still has to carry this name; only which name is checked moves.

Refused by the stores whose clients cannot express it; see the module documentation.

Source

pub fn with_skip_verification(self, skip: bool) -> TlsConfig

Do not authenticate the server at all.

This is not a weaker TLS; it is TLS without the part that makes it mean anything. Any party on the network path can present any certificate, read what is sent, and rewrite what comes back — and what comes back from a store is the configuration and the credentials a process is about to run on.

Try with_ca_certificate_file first. A development server with a self-signed certificate and an enterprise private CA are both one more certificate to trust, which is one line and keeps the server authenticated.

Refused by the stores whose clients cannot express it; see the module documentation.

Source

pub fn is_empty(&self) -> bool

Whether this asks for nothing at all.

A store uses it to tell “the caller wants the platform defaults” from “the caller wants something”, which is the difference between leaving its client alone and building one.

Source

pub fn ca_certificate(&self) -> Option<&Pem>

The certificate authority to trust, if one was named.

Source

pub fn client_certificate(&self) -> Option<&ClientCertificate>

The client certificate to present, if one was named.

Source

pub fn server_name(&self) -> Option<&str>

The name to verify against, if it is not the address’s.

Source

pub const fn skips_verification(&self) -> bool

Whether the server is to go unauthenticated.

Source

pub fn ca_certificate_pem( &self, described: &str, ) -> Result<Option<Vec<u8>>, Error>

The CA certificate’s PEM bytes, reading the file if that is what it is.

§Errors

If the file cannot be read; the message names the path.

Source

pub fn client_certificate_pem( &self, described: &str, ) -> Result<Option<(Vec<u8>, Vec<u8>)>, Error>

The client certificate and key as PEM bytes, reading the files if that is what they are.

§Errors

If either file cannot be read; the message names the path and never the contents.

Trait Implementations§

Source§

impl Clone for TlsConfig

Source§

fn clone(&self) -> TlsConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TlsConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for TlsConfig

Source§

fn default() -> TlsConfig

Returns the “default value” for a type. Read more
Source§

impl Eq for TlsConfig

Source§

impl PartialEq for TlsConfig

Source§

fn eq(&self, other: &TlsConfig) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TlsConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more