rustls/
lib.rs

1//! # Rustls - a modern TLS library
2//!
3//! Rustls is a TLS library that aims to provide a good level of cryptographic security,
4//! requires no configuration to achieve that security, and provides no unsafe features or
5//! obsolete cryptography by default.
6//!
7//! Rustls implements TLS1.2 and TLS1.3 for both clients and servers. See [the full
8//! list of protocol features](manual::_04_features).
9//!
10//! ### Platform support
11//!
12//! While Rustls itself is platform independent, it requires the use of cryptography primitives
13//! for implementing the cryptography algorithms used in TLS. In Rustls, a
14//! [`crypto::CryptoProvider`] represents a collection of crypto primitive implementations.
15//!
16//! The Rustls team recommends using the [`aws-lc-rs`] crate, which for its complete feature set
17//! and performance. See [the aws-lc-rs FAQ][aws-lc-rs-platforms-faq] for more details of the
18//! platform/architecture support constraints in aws-lc-rs.
19//!
20//! [`ring`] is also available via the `ring` crate feature: see
21//! [the supported `ring` target platforms][ring-target-platforms].
22//!
23//! By providing a custom instance of the [`crypto::CryptoProvider`] struct, you
24//! can replace all cryptography dependencies of rustls.  This is a route to being portable
25//! to a wider set of architectures and environments, or compliance requirements.  See the
26//! [`crypto::CryptoProvider`] documentation for more details.
27//!
28//! Rustls requires Rust 1.79 or later.
29//!
30//! [ring-target-platforms]: https://github.com/briansmith/ring/blob/2e8363b433fa3b3962c877d9ed2e9145612f3160/include/ring-core/target.h#L18-L64
31//! [`crypto::CryptoProvider`]: crate::crypto::CryptoProvider
32//! [`ring`]: https://crates.io/crates/ring
33//! [aws-lc-rs-platforms-faq]: https://aws.github.io/aws-lc-rs/faq.html#can-i-run-aws-lc-rs-on-x-platform-or-architecture
34//! [`aws-lc-rs`]: https://crates.io/crates/aws-lc-rs
35//!
36//! ### Cryptography providers
37//!
38//! Since Rustls 0.22 it has been possible to choose the provider of the cryptographic primitives
39//! that Rustls uses. This may be appealing if you have specific platform, compliance or feature
40//! requirements.
41//!
42//! Users that wish to customize the provider in use can do so when constructing `ClientConfig`
43//! and `ServerConfig` instances using the `with_crypto_provider` method on the respective config
44//! builder types. See the [`crypto::CryptoProvider`] documentation for more details.
45//!
46//! #### Built-in providers
47//!
48//! Rustls ships with two built-in providers controlled by associated crate features:
49//!
50//!   * [`aws-lc-rs`] - available with the `aws-lc-rs` crate feature enabled
51//!   * [`ring`] - available with the `ring` crate feature enabled
52//!
53//! See the documentation for [`crypto::CryptoProvider`] for details on how providers are
54//! selected.
55//!
56//! #### Third-party providers
57//!
58//! The community has also started developing third-party providers for Rustls:
59//!
60//!   * [`boring-rustls-provider`] - a work-in-progress provider that uses [`boringssl`] for
61//!     cryptography.
62//!   * [`rustls-graviola`] - a provider that uses [`graviola`] for cryptography.
63//!   * [`rustls-mbedtls-provider`] - a provider that uses [`mbedtls`] for cryptography.
64//!   * [`rustls-openssl`] - a provider that uses [OpenSSL] for cryptography.
65//!   * [`rustls-rustcrypto`] - an experimental provider that uses the crypto primitives
66//!     from [`RustCrypto`] for cryptography.
67//!   * [`rustls-symcrypt`] - a provider that uses Microsoft's [SymCrypt] library.
68//!   * [`rustls-wolfcrypt-provider`] - a work-in-progress provider that uses [`wolfCrypt`] for cryptography.
69//!
70//! [`rustls-graviola`]: https://crates.io/crates/rustls-graviola
71//! [`graviola`]: https://github.com/ctz/graviola
72//! [`rustls-mbedtls-provider`]: https://github.com/fortanix/rustls-mbedtls-provider
73//! [`mbedtls`]: https://github.com/Mbed-TLS/mbedtls
74//! [`rustls-openssl`]: https://github.com/tofay/rustls-openssl
75//! [OpenSSL]: https://openssl-library.org/
76//! [`rustls-symcrypt`]: https://github.com/microsoft/rustls-symcrypt
77//! [SymCrypt]: https://github.com/microsoft/SymCrypt
78//! [`boring-rustls-provider`]: https://github.com/janrueth/boring-rustls-provider
79//! [`boringssl`]: https://github.com/google/boringssl
80//! [`rustls-rustcrypto`]: https://github.com/RustCrypto/rustls-rustcrypto
81//! [`RustCrypto`]: https://github.com/RustCrypto
82//! [`rustls-wolfcrypt-provider`]: https://github.com/wolfSSL/rustls-wolfcrypt-provider
83//! [`wolfCrypt`]: https://www.wolfssl.com/products/wolfcrypt
84//!
85//! #### Custom provider
86//!
87//! We also provide a simple example of writing your own provider in the [custom provider example].
88//! This example implements a minimal provider using parts of the [`RustCrypto`] ecosystem.
89//!
90//! See the [Making a custom CryptoProvider] section of the documentation for more information
91//! on this topic.
92//!
93//! [custom provider example]: https://github.com/rustls/rustls/tree/main/provider-example/
94//! [`RustCrypto`]: https://github.com/RustCrypto
95//! [Making a custom CryptoProvider]: https://docs.rs/rustls/latest/rustls/crypto/struct.CryptoProvider.html#making-a-custom-cryptoprovider
96//!
97//! ## Design overview
98//!
99//! Rustls is a low-level library. If your goal is to make HTTPS connections you may prefer
100//! to use a library built on top of Rustls like [hyper] or [ureq].
101//!
102//! [hyper]: https://crates.io/crates/hyper
103//! [ureq]: https://crates.io/crates/ureq
104//!
105//! ### Rustls does not take care of network IO
106//! It doesn't make or accept TCP connections, or do DNS, or read or write files.
107//!
108//! Our [examples] directory contains demos that show how to handle I/O using the
109//! [`stream::Stream`] helper, as well as more complex asynchronous I/O using [`mio`].
110//! If you're already using Tokio for an async runtime you may prefer to use [`tokio-rustls`] instead
111//! of interacting with rustls directly.
112//!
113//! [examples]: https://github.com/rustls/rustls/tree/main/examples
114//! [`tokio-rustls`]: https://github.com/rustls/tokio-rustls
115//!
116//! ### Rustls provides encrypted pipes
117//! These are the [`ServerConnection`] and [`ClientConnection`] types.  You supply raw TLS traffic
118//! on the left (via the [`read_tls()`] and [`write_tls()`] methods) and then read/write the
119//! plaintext on the right:
120//!
121//! [`read_tls()`]: Connection::read_tls
122//! [`write_tls()`]: Connection::read_tls
123//!
124//! ```text
125//!          TLS                                   Plaintext
126//!          ===                                   =========
127//!     read_tls()      +-----------------------+      reader() as io::Read
128//!                     |                       |
129//!           +--------->   ClientConnection    +--------->
130//!                     |          or           |
131//!           <---------+   ServerConnection    <---------+
132//!                     |                       |
133//!     write_tls()     +-----------------------+      writer() as io::Write
134//! ```
135//!
136//! ### Rustls takes care of server certificate verification
137//! You do not need to provide anything other than a set of root certificates to trust.
138//! Certificate verification cannot be turned off or disabled in the main API.
139//!
140//! ## Getting started
141//! This is the minimum you need to do to make a TLS client connection.
142//!
143//! First we load some root certificates.  These are used to authenticate the server.
144//! The simplest way is to depend on the [`webpki_roots`] crate which contains
145//! the Mozilla set of root certificates.
146//!
147//! ```rust,no_run
148//! # #[cfg(feature = "aws-lc-rs")] {
149//! let root_store = rustls::RootCertStore::from_iter(
150//!     webpki_roots::TLS_SERVER_ROOTS
151//!         .iter()
152//!         .cloned(),
153//! );
154//! # }
155//! ```
156//!
157//! [`webpki_roots`]: https://crates.io/crates/webpki-roots
158//!
159//! Next, we make a `ClientConfig`.  You're likely to make one of these per process,
160//! and use it for all connections made by that process.
161//!
162//! ```rust,no_run
163//! # #[cfg(feature = "aws-lc-rs")] {
164//! # let root_store: rustls::RootCertStore = panic!();
165//! let config = rustls::ClientConfig::builder()
166//!     .with_root_certificates(root_store)
167//!     .with_no_client_auth()
168//!     .unwrap();
169//! # }
170//! ```
171//!
172//! Now we can make a connection.  You need to provide the server's hostname so we
173//! know what to expect to find in the server's certificate.
174//!
175//! ```rust
176//! # #[cfg(feature = "aws-lc-rs")] {
177//! # use rustls;
178//! # use webpki;
179//! # use std::sync::Arc;
180//! # rustls::crypto::aws_lc_rs::default_provider().install_default();
181//! # let root_store = rustls::RootCertStore::from_iter(
182//! #  webpki_roots::TLS_SERVER_ROOTS
183//! #      .iter()
184//! #      .cloned(),
185//! # );
186//! # let config = rustls::ClientConfig::builder()
187//! #     .with_root_certificates(root_store)
188//! #     .with_no_client_auth()
189//! #     .unwrap();
190//! let rc_config = Arc::new(config);
191//! let example_com = "example.com".try_into().unwrap();
192//! let mut client = rustls::ClientConnection::new(rc_config, example_com);
193//! # }
194//! ```
195//!
196//! Now you should do appropriate IO for the `client` object.  If `client.wants_read()` yields
197//! true, you should call `client.read_tls()` when the underlying connection has data.
198//! Likewise, if `client.wants_write()` yields true, you should call `client.write_tls()`
199//! when the underlying connection is able to send data.  You should continue doing this
200//! as long as the connection is valid.
201//!
202//! The return types of `read_tls()` and `write_tls()` only tell you if the IO worked.  No
203//! parsing or processing of the TLS messages is done.  After each `read_tls()` you should
204//! therefore call `client.process_new_packets()` which parses and processes the messages.
205//! Any error returned from `process_new_packets` is fatal to the connection, and will tell you
206//! why.  For example, if the server's certificate is expired `process_new_packets` will
207//! return `Err(InvalidCertificate(Expired))`.  From this point on,
208//! `process_new_packets` will not do any new work and will return that error continually.
209//!
210//! You can extract newly received data by calling `client.reader()` (which implements the
211//! `io::Read` trait).  You can send data to the peer by calling `client.writer()` (which
212//! implements `io::Write` trait).  Note that `client.writer().write()` buffers data you
213//! send if the TLS connection is not yet established: this is useful for writing (say) a
214//! HTTP request, but this is buffered so avoid large amounts of data.
215//!
216//! The following code uses a fictional socket IO API for illustration, and does not handle
217//! errors.
218//!
219//! ```rust,no_run
220//! # #[cfg(feature = "aws-lc-rs")] {
221//! # let mut client = rustls::ClientConnection::new(panic!(), panic!()).unwrap();
222//! # struct Socket { }
223//! # impl Socket {
224//! #   fn ready_for_write(&self) -> bool { false }
225//! #   fn ready_for_read(&self) -> bool { false }
226//! #   fn wait_for_something_to_happen(&self) { }
227//! # }
228//! #
229//! # use std::io::{Read, Write, Result};
230//! # impl Read for Socket {
231//! #   fn read(&mut self, buf: &mut [u8]) -> Result<usize> { panic!() }
232//! # }
233//! # impl Write for Socket {
234//! #   fn write(&mut self, buf: &[u8]) -> Result<usize> { panic!() }
235//! #   fn flush(&mut self) -> Result<()> { panic!() }
236//! # }
237//! #
238//! # fn connect(_address: &str, _port: u16) -> Socket {
239//! #   panic!();
240//! # }
241//! use std::io;
242//! use rustls::Connection;
243//!
244//! client.writer().write(b"GET / HTTP/1.0\r\n\r\n").unwrap();
245//! let mut socket = connect("example.com", 443);
246//! loop {
247//!   if client.wants_read() && socket.ready_for_read() {
248//!     client.read_tls(&mut socket).unwrap();
249//!     client.process_new_packets().unwrap();
250//!
251//!     let mut plaintext = Vec::new();
252//!     client.reader().read_to_end(&mut plaintext).unwrap();
253//!     io::stdout().write(&plaintext).unwrap();
254//!   }
255//!
256//!   if client.wants_write() && socket.ready_for_write() {
257//!     client.write_tls(&mut socket).unwrap();
258//!   }
259//!
260//!   socket.wait_for_something_to_happen();
261//! }
262//! # }
263//! ```
264//!
265//! # Examples
266//!
267//! You can find several client and server examples of varying complexity in the [examples]
268//! directory, including [`tlsserver-mio`](https://github.com/rustls/rustls/blob/main/examples/src/bin/tlsserver-mio.rs)
269//! and [`tlsclient-mio`](https://github.com/rustls/rustls/blob/main/examples/src/bin/tlsclient-mio.rs)
270//! \- full worked examples using [`mio`].
271//!
272//! [`mio`]: https://docs.rs/mio/latest/mio/
273//!
274//! # Manual
275//!
276//! The [rustls manual](crate::manual) explains design decisions and includes how-to guidance.
277//!
278//! # Crate features
279//! Here's a list of what features are exposed by the rustls crate and what
280//! they mean.
281//!
282//! - `std` (enabled by default): enable the high-level (buffered) Connection API and other functionality
283//!   which relies on the `std` library.
284//!
285//! - `aws-lc-rs`: makes the rustls crate depend on the [`aws-lc-rs`] crate.
286//!   Use `rustls::crypto::aws_lc_rs::default_provider().install_default()` to
287//!   use it as the default `CryptoProvider`, or provide it explicitly
288//!   when making a `ClientConfig` or `ServerConfig`.
289//!
290//!   Note that aws-lc-rs has additional build-time dependencies like cmake.
291//!   See [the documentation](https://aws.github.io/aws-lc-rs/requirements/index.html) for details.
292//!
293//! - `ring`: makes the rustls crate depend on the *ring* crate for cryptography.
294//!   Use `rustls::crypto::ring::default_provider().install_default()` to
295//!   use it as the default `CryptoProvider`, or provide it explicitly
296//!   when making a `ClientConfig` or `ServerConfig`.
297//!
298//! - `fips`: enable support for FIPS140-3-approved cryptography, via the [`aws-lc-rs`] crate.
299//!   This feature enables the `aws-lc-rs` crate feature, which makes the rustls crate depend
300//!   on [aws-lc-rs](https://github.com/aws/aws-lc-rs).  It also changes the default
301//!   for [`ServerConfig::require_ems`] and [`ClientConfig::require_ems`].
302//!
303//!   See [manual::_06_fips] for more details.
304//!
305//! - `custom-provider`: disables implicit use of built-in providers (`aws-lc-rs` or `ring`). This forces
306//!   applications to manually install one, for instance, when using a custom `CryptoProvider`.
307//!
308//! - `log` (enabled by default): make the rustls crate depend on the `log` crate.
309//!   rustls outputs interesting protocol-level messages at `trace!` and `debug!` level,
310//!   and protocol-level errors at `warn!` and `error!` level.  The log messages do not
311//!   contain secret key data, and so are safe to archive without affecting session security.
312//!
313//! - `brotli`: uses the `brotli` crate for RFC8879 certificate compression support.
314//!
315//! - `zlib`: uses the `zlib-rs` crate for RFC8879 certificate compression support.
316//!
317//! [x25519mlkem768-manual]: manual::_05_defaults#about-the-post-quantum-secure-key-exchange-x25519mlkem768
318
319// Require docs for public APIs, deny unsafe code, etc.
320#![forbid(unsafe_code, unused_must_use)]
321#![cfg_attr(not(any(bench, coverage_nightly)), forbid(unstable_features))]
322#![warn(
323    clippy::alloc_instead_of_core,
324    clippy::exhaustive_enums,
325    clippy::exhaustive_structs,
326    clippy::manual_let_else,
327    clippy::std_instead_of_core,
328    clippy::use_self,
329    clippy::upper_case_acronyms,
330    elided_lifetimes_in_paths,
331    missing_docs,
332    trivial_casts,
333    trivial_numeric_casts,
334    unreachable_pub,
335    unused_import_braces,
336    unused_extern_crates,
337    unused_qualifications
338)]
339// Relax these clippy lints:
340// - ptr_arg: this triggers on references to type aliases that are Vec
341//   underneath.
342// - too_many_arguments: some things just need a lot of state, wrapping it
343//   doesn't necessarily make it easier to follow what's going on
344// - new_ret_no_self: we sometimes return `Arc<Self>`, which seems fine
345// - single_component_path_imports: our top-level `use log` import causes
346//   a false positive, https://github.com/rust-lang/rust-clippy/issues/5210
347// - new_without_default: for internal constructors, the indirection is not
348//   helpful
349#![allow(
350    clippy::too_many_arguments,
351    clippy::new_ret_no_self,
352    clippy::ptr_arg,
353    clippy::single_component_path_imports,
354    clippy::new_without_default
355)]
356// Enable documentation for all features on docs.rs
357#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
358// Enable coverage() attr for nightly coverage builds, see
359// <https://github.com/rust-lang/rust/issues/84605>
360// (`coverage_nightly` is a cfg set by `cargo-llvm-cov`)
361#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
362#![cfg_attr(bench, feature(test))]
363#![no_std]
364
365extern crate alloc;
366// This `extern crate` plus the `#![no_std]` attribute changes the default prelude from
367// `std::prelude` to `core::prelude`. That forces one to _explicitly_ import (`use`) everything that
368// is in `std::prelude` but not in `core::prelude`. This helps maintain no-std support as even
369// developers that are not interested in, or aware of, no-std support and / or that never run
370// `cargo build --no-default-features` locally will get errors when they rely on `std::prelude` API.
371#[cfg(any(feature = "std", test))]
372extern crate std;
373
374#[cfg(doc)]
375use crate::crypto::CryptoProvider;
376
377// Import `test` sysroot crate for `Bencher` definitions.
378#[cfg(bench)]
379#[allow(unused_extern_crates)]
380extern crate test;
381
382// log for logging (optional).
383#[cfg(feature = "log")]
384use log;
385
386#[cfg(not(feature = "log"))]
387mod log {
388    macro_rules! trace    ( ($($tt:tt)*) => {{}} );
389    macro_rules! debug    ( ($($tt:tt)*) => {{}} );
390    macro_rules! error    ( ($($tt:tt)*) => {{}} );
391    macro_rules! _warn    ( ($($tt:tt)*) => {{}} );
392    pub(crate) use {_warn as warn, debug, error, trace};
393}
394
395#[cfg(test)]
396#[macro_use]
397mod test_macros;
398
399/// This internal `sync` module aliases the `Arc` implementation to allow downstream forks
400/// of rustls targeting architectures without atomic pointers to replace the implementation
401/// with another implementation such as `portable_atomic_util::Arc` in one central location.
402mod sync {
403    #[allow(clippy::disallowed_types)]
404    pub(crate) type Arc<T> = alloc::sync::Arc<T>;
405    #[allow(clippy::disallowed_types)]
406    pub(crate) type Weak<T> = alloc::sync::Weak<T>;
407}
408
409#[macro_use]
410mod msgs;
411mod common_state;
412pub mod compress;
413mod conn;
414/// Crypto provider interface.
415pub mod crypto;
416mod error;
417mod hash_hs;
418#[cfg(any(feature = "std", feature = "hashbrown"))]
419mod limited_cache;
420mod rand;
421mod record_layer;
422#[cfg(feature = "std")]
423mod stream;
424mod tls12;
425mod tls13;
426mod vecbuf;
427mod verify;
428#[cfg(test)]
429mod verifybench;
430mod x509;
431#[macro_use]
432mod check;
433#[cfg(feature = "log")]
434mod bs_debug;
435mod builder;
436mod enums;
437mod key_log;
438#[cfg(feature = "std")]
439mod key_log_file;
440mod suites;
441mod versions;
442mod webpki;
443
444/// Internal classes that are used in integration tests.
445/// The contents of this section DO NOT form part of the stable interface.
446#[allow(missing_docs)]
447#[doc(hidden)]
448pub mod internal {
449    /// Low-level TLS message parsing and encoding functions.
450    pub mod msgs {
451        pub mod base {
452            pub use crate::msgs::base::{Payload, PayloadU16};
453        }
454        pub mod codec {
455            pub use crate::msgs::codec::{Codec, Reader};
456        }
457        pub mod enums {
458            pub use crate::msgs::enums::{AlertLevel, ExtensionType};
459        }
460        pub mod fragmenter {
461            pub use crate::msgs::fragmenter::MessageFragmenter;
462        }
463        pub mod message {
464            pub use crate::msgs::message::{
465                Message, MessagePayload, OutboundOpaqueMessage, PlainMessage,
466            };
467        }
468        pub mod persist {
469            pub use crate::msgs::persist::ServerSessionValue;
470        }
471    }
472
473    pub use crate::tls13::key_schedule::{derive_traffic_iv, derive_traffic_key};
474
475    pub mod fuzzing {
476        pub use crate::msgs::deframer::fuzz_deframer;
477    }
478}
479
480/// Unbuffered connection API
481///
482/// This is an alternative to the [`crate::ConnectionCommon`] API that does not internally buffer
483/// TLS nor plaintext data. Instead those buffers are managed by the API user so they have
484/// control over when and how to allocate, resize and dispose of them.
485///
486/// This API is lower level than the `ConnectionCommon` API and is built around a state machine
487/// interface where the API user must handle each state to advance and complete the
488/// handshake process.
489///
490/// Like the `ConnectionCommon` API, no IO happens internally so all IO must be handled by the API
491/// user. Unlike the `ConnectionCommon` API, this API does not make use of the [`std::io::Read`] and
492/// [`std::io::Write`] traits so it's usable in no-std context.
493///
494/// The entry points into this API are [`crate::client::UnbufferedClientConnection::new`],
495/// [`crate::server::UnbufferedServerConnection::new`] and
496/// [`unbuffered::UnbufferedConnectionCommon::process_tls_records`]. The state machine API is
497/// documented in [`unbuffered::ConnectionState`].
498///
499/// # Examples
500///
501/// [`unbuffered-client`] and [`unbuffered-server`] are examples that fully exercise the API in
502/// std, non-async context.
503///
504/// [`unbuffered-client`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffered-client.rs
505/// [`unbuffered-server`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffered-server.rs
506pub mod unbuffered {
507    pub use crate::conn::UnbufferedConnectionCommon;
508    pub use crate::conn::unbuffered::{
509        AppDataRecord, ConnectionState, EncodeError, EncodeTlsData, EncryptError,
510        InsufficientSizeError, ReadEarlyData, ReadTraffic, TransmitTlsData, UnbufferedStatus,
511        WriteTraffic,
512    };
513}
514
515// The public interface is:
516pub use crate::builder::{ConfigBuilder, ConfigSide, WantsVerifier};
517pub use crate::common_state::{CommonState, HandshakeKind, IoState, Side};
518#[cfg(feature = "std")]
519pub use crate::conn::{Connection, Reader, Writer};
520pub use crate::conn::{ConnectionCommon, SideData, kernel};
521pub use crate::enums::{
522    AlertDescription, CertificateCompressionAlgorithm, CipherSuite, ContentType, HandshakeType,
523    ProtocolVersion, SignatureAlgorithm, SignatureScheme,
524};
525pub use crate::error::{
526    CertRevocationListError, CertificateError, EncryptedClientHelloError, Error,
527    ExtendedKeyPurpose, InconsistentKeys, InvalidMessage, OtherError, PeerIncompatible,
528    PeerMisbehaved, RejectedEch,
529};
530pub use crate::key_log::{KeyLog, NoKeyLog};
531#[cfg(feature = "std")]
532pub use crate::key_log_file::KeyLogFile;
533pub use crate::msgs::enums::NamedGroup;
534pub use crate::msgs::ffdhe_groups;
535pub use crate::msgs::handshake::DistinguishedName;
536#[cfg(feature = "std")]
537pub use crate::stream::{Stream, StreamOwned};
538pub use crate::suites::{
539    CipherSuiteCommon, ConnectionTrafficSecrets, ExtractedSecrets, SupportedCipherSuite,
540};
541#[cfg(feature = "std")]
542pub use crate::ticketer::TicketRotator;
543pub use crate::tls12::Tls12CipherSuite;
544pub use crate::tls13::Tls13CipherSuite;
545pub use crate::verify::DigitallySignedStruct;
546pub use crate::versions::{ALL_VERSIONS, DEFAULT_VERSIONS, SupportedProtocolVersion};
547pub use crate::webpki::RootCertStore;
548
549/// Items for use in a client.
550pub mod client {
551    pub(super) mod builder;
552    mod client_conn;
553    mod common;
554    mod ech;
555    pub(super) mod handy;
556    mod hs;
557    #[cfg(test)]
558    mod test;
559    mod tls12;
560    mod tls13;
561
562    pub use builder::WantsClientCert;
563    pub use client_conn::{
564        ClientConfig, ClientConnectionData, ClientSessionStore, EarlyDataError, ResolvesClientCert,
565        Resumption, Tls12Resumption, UnbufferedClientConnection,
566    };
567    #[cfg(feature = "std")]
568    pub use client_conn::{ClientConnection, WriteEarlyData};
569    pub use ech::{EchConfig, EchGreaseConfig, EchMode, EchStatus};
570    pub use handy::AlwaysResolvesClientRawPublicKeys;
571    #[cfg(any(feature = "std", feature = "hashbrown"))]
572    pub use handy::ClientSessionMemoryCache;
573
574    /// Dangerous configuration that should be audited and used with extreme care.
575    pub mod danger {
576        pub use super::builder::danger::DangerousClientConfigBuilder;
577        pub use super::client_conn::danger::DangerousClientConfig;
578        pub use crate::verify::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
579    }
580
581    pub(crate) use tls12::{TLS12_HANDLER, Tls12Handler};
582    pub(crate) use tls13::{TLS13_HANDLER, Tls13Handler};
583
584    pub use crate::msgs::persist::{Tls12ClientSessionValue, Tls13ClientSessionValue};
585    pub use crate::webpki::{
586        ServerCertVerifierBuilder, VerifierBuilderError, WebPkiServerVerifier,
587        verify_server_cert_signed_by_trust_anchor, verify_server_name,
588    };
589}
590
591pub use client::ClientConfig;
592#[cfg(feature = "std")]
593pub use client::ClientConnection;
594
595/// Items for use in a server.
596pub mod server {
597    pub(crate) mod builder;
598    mod common;
599    pub(crate) mod handy;
600    mod hs;
601    mod server_conn;
602    #[cfg(test)]
603    mod test;
604    mod tls12;
605    mod tls13;
606
607    pub use builder::WantsServerCert;
608    #[cfg(any(feature = "std", feature = "hashbrown"))]
609    pub use handy::ResolvesServerCertUsingSni;
610    #[cfg(any(feature = "std", feature = "hashbrown"))]
611    pub use handy::ServerSessionMemoryCache;
612    pub use handy::{AlwaysResolvesServerRawPublicKeys, NoServerSessionStorage};
613    pub use server_conn::{
614        Accepted, ClientHello, ProducesTickets, ResolvesServerCert, ServerConfig,
615        ServerConnectionData, StoresServerSessions, UnbufferedServerConnection,
616    };
617    #[cfg(feature = "std")]
618    pub use server_conn::{AcceptedAlert, Acceptor, ReadEarlyData, ServerConnection};
619
620    pub use crate::enums::CertificateType;
621    pub use crate::verify::NoClientAuth;
622    pub use crate::webpki::{
623        ClientCertVerifierBuilder, ParsedCertificate, VerifierBuilderError, WebPkiClientVerifier,
624    };
625
626    /// Dangerous configuration that should be audited and used with extreme care.
627    pub mod danger {
628        pub use crate::verify::{ClientCertVerified, ClientCertVerifier};
629    }
630
631    pub(crate) use tls12::{TLS12_HANDLER, Tls12Handler};
632    pub(crate) use tls13::{TLS13_HANDLER, Tls13Handler};
633}
634
635pub use server::ServerConfig;
636#[cfg(feature = "std")]
637pub use server::ServerConnection;
638
639/// All defined protocol versions appear in this module.
640///
641/// ALL_VERSIONS is a provided as an array of all of these values.
642pub mod version {
643    pub use crate::versions::{
644        TLS12, TLS12_VERSION, TLS13, TLS13_VERSION, Tls12Version, Tls13Version,
645    };
646}
647
648/// Re-exports the contents of the [rustls-pki-types](https://docs.rs/rustls-pki-types) crate for easy access
649pub mod pki_types {
650    #[doc(no_inline)]
651    pub use pki_types::*;
652}
653
654/// Message signing interfaces.
655pub mod sign {
656    pub use crate::crypto::signer::{CertifiedKey, Signer, SigningKey, SingleCertAndKey};
657}
658
659/// APIs for implementing QUIC TLS
660pub mod quic;
661
662/// APIs for implementing TLS tickets
663#[cfg(any(feature = "std", feature = "hashbrown"))] // < XXX: incorrect feature gate
664pub mod ticketer;
665
666/// This is the rustls manual.
667pub mod manual;
668
669pub mod time_provider;
670
671/// APIs abstracting over locking primitives.
672pub mod lock;
673
674/// Polyfills for features that are not yet stabilized or available with current MSRV.
675pub(crate) mod polyfill;
676
677#[cfg(any(feature = "std", feature = "hashbrown"))]
678mod hash_map {
679    #[cfg(feature = "std")]
680    pub(crate) use std::collections::HashMap;
681    #[cfg(feature = "std")]
682    pub(crate) use std::collections::hash_map::Entry;
683
684    #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
685    pub(crate) use hashbrown::HashMap;
686    #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
687    pub(crate) use hashbrown::hash_map::Entry;
688}
689
690mod sealed {
691    pub trait Sealed {}
692}