trillium_rustls/lib.rs
1#![forbid(unsafe_code)]
2#![deny(
3 clippy::dbg_macro,
4 missing_copy_implementations,
5 rustdoc::missing_crate_level_docs,
6 missing_debug_implementations,
7 missing_docs,
8 nonstandard_style,
9 unused_qualifications
10)]
11#![cfg_attr(docsrs, feature(doc_cfg))]
12
13//! This crate provides rustls trait implementations for trillium client ([`RustlsConfig`]) and
14//! server ([`RustlsAcceptor`]).
15//!
16//! # Cargo Features
17//!
18//! This crate's default features should be appropriate for most users. To pare down on dependencies
19//! or customize trillium-rustls' usage of rustls, opt out of default features and reenable the
20//! appropriate features for your use case.
21//!
22//! ## `server` and `client` features
23//!
24//! This crate offers a `server` feature and a `client` feature. Opting out of default features
25//! allows you to avoid building any dependencies for the unused other component. By default, both
26//! `server` and `client` features are enabled.
27//!
28//! ## Cryptographic backend selection
29//!
30//! Rustls supports pluggable cryptographic backends as well as a process-default cryptographic
31//! cryptographic backend. There are two built-in feature-enabled cryptographic backends and other
32//! community provided cryptographic backends.
33//!
34//! ⚠️ There are three cryptographic backend cargo features, and they behave differently than the
35//! rustls features. Please read the following section.⚠️
36//!
37//! `trillium-rustls` tries to avoid runtime panics where possible, so compiling this crate without
38//! a valid cryptographic backend will result in a compile time error. To opt into rustls's default
39//! process-default behavior, enable `custom-crypto-provider` as described below. Enabling multiple
40//! crypto providers will select exactly one of them at compile time in the following order:
41//!
42//! ### `aws-lc-rs`
43//!
44//! This is the default cryptographic backend in concordance with rustls' default. This backend will
45//! be selected if the feature is enabled. If either of the other two cryptographic backends are
46//! selected, trillium-rustls will log an error but use `aws-lc-rs`.
47//!
48//! ### `ring`
49//!
50//! If this feature is enabled, this backend will be selected even if `custom-crypto-provider` is
51//! also enabled.
52//!
53//! ### `custom-crypto-provider`
54//!
55//! In order to use a crypto provider other than the above two options, enable the
56//! `custom-crypto-provider` feature and either configure a
57//! [`trillium_rustls::rustls::ClientConfig`][rustls::ClientConfig] or
58//! [`trillium_rustls::rustls::ServerConfig`][rustls::ServerConfig] yourself to convert the
59//! equivalent `trillium-rustls` type, or install a custom process-default crypto provider with
60//! [`trillium_rustls::rustls::crypto::CryptoProvider::install_default`][rustls::crypto::CryptoProvider::install_default]
61//! prior to executing trillium-rustls code.
62//!
63//! ## Client verifier
64//!
65//! This crate offers a `platform-verifier` feature for client usage that builds a ClientConfig with
66//! the selected cryptographic backend and uses
67//! [`rustls-platform-verifier`](https://docs.rs/rustls-platform-verifier/). This feature is enabled by
68//! default. If you disable the feature, [`webpki_roots`] will be used.
69//!
70//! To trust a specific private or self-signed certificate without dropping into raw rustls, use
71//! [`RustlsClientConfig::from_root_cert_pem`], which trusts exactly the provided roots while
72//! keeping certificate verification intact.
73//!
74//! ## `dangerous` feature
75//!
76//! ⚠️ This feature enables [`RustlsClientConfig::dangerously_accept_any_cert`], which builds a
77//! client configuration that disables server authentication entirely. It is not enabled by
78//! default and should only be used for development or explicit `--insecure`-style opt-ins. Prefer
79//! [`RustlsClientConfig::from_root_cert_pem`] whenever the certificate is known in advance.
80
81#[cfg(test)]
82#[doc = include_str!("../README.md")]
83mod readme {}
84
85#[cfg(feature = "client")]
86mod client;
87#[cfg(feature = "client")]
88pub use client::{RustlsClientConfig, RustlsClientTransport, RustlsConfig};
89
90#[cfg(feature = "server")]
91mod server;
92pub use futures_rustls::{self, rustls};
93#[cfg(feature = "server")]
94pub use server::{RustlsAcceptor, RustlsServerTransport};
95
96#[cfg(any(feature = "client", feature = "server"))]
97mod crypto_provider;
98pub(crate) use crypto_provider::crypto_provider;