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, by default it uses [`aws-lc-rs`] for implementing
13//! the cryptography in TLS. See [the aws-lc-rs FAQ][aws-lc-rs-platforms-faq] for more details of the
14//! platform/architecture support constraints in aws-lc-rs.
15//!
16//! [`ring`] is also available via the `ring` crate feature: see
17//! [the supported `ring` target platforms][ring-target-platforms].
18//!
19//! By providing a custom instance of the [`crypto::CryptoProvider`] struct, you
20//! can replace all cryptography dependencies of rustls. This is a route to being portable
21//! to a wider set of architectures and environments, or compliance requirements. See the
22//! [`crypto::CryptoProvider`] documentation for more details.
23//!
24//! Specifying `default-features = false` when depending on rustls will remove the
25//! dependency on aws-lc-rs.
26//!
27//! Rustls requires Rust 1.63 or later. It has an optional dependency on zlib-rs which requires 1.75 or later.
28//!
29//! [ring-target-platforms]: https://github.com/briansmith/ring/blob/2e8363b433fa3b3962c877d9ed2e9145612f3160/include/ring-core/target.h#L18-L64
30//! [`crypto::CryptoProvider`]: crate::crypto::CryptoProvider
31//! [`ring`]: https://crates.io/crates/ring
32//! [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
33//! [`aws-lc-rs`]: https://crates.io/crates/aws-lc-rs
34//!
35//! ### Cryptography providers
36//!
37//! Since Rustls 0.22 it has been possible to choose the provider of the cryptographic primitives
38//! that Rustls uses. This may be appealing if you have specific platform, compliance or feature
39//! requirements that aren't met by the default provider, [`aws-lc-rs`].
40//!
41//! Users that wish to customize the provider in use can do so when constructing `ClientConfig`
42//! and `ServerConfig` instances using the `with_crypto_provider` method on the respective config
43//! builder types. See the [`crypto::CryptoProvider`] documentation for more details.
44//!
45//! #### Built-in providers
46//!
47//! Rustls ships with two built-in providers controlled with associated feature flags:
48//!
49//! * [`aws-lc-rs`] - enabled by default, available with the `aws_lc_rs` feature flag enabled.
50//! * [`ring`] - available with the `ring` feature flag enabled.
51//!
52//! See the documentation for [`crypto::CryptoProvider`] for details on how providers are
53//! selected.
54//!
55//! #### Third-party providers
56//!
57//! The community has also started developing third-party providers for Rustls:
58//!
59//! * [`rustls-mbedtls-provider`] - a provider that uses [`mbedtls`] for cryptography.
60//! * [`rustls-openssl`] - a provider that uses [OpenSSL] for cryptography.
61//! * [`rustls-post-quantum`]: an experimental provider that adds support for post-quantum
62//! key exchange to the default aws-lc-rs provider.
63//! * [`boring-rustls-provider`] - a work-in-progress provider that uses [`boringssl`] for
64//! 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-mbedtls-provider`]: https://github.com/fortanix/rustls-mbedtls-provider
71//! [`mbedtls`]: https://github.com/Mbed-TLS/mbedtls
72//! [`rustls-openssl`]: https://github.com/tofay/rustls-openssl
73//! [OpenSSL]: https://openssl-library.org/
74//! [`rustls-symcrypt`]: https://github.com/microsoft/rustls-symcrypt
75//! [SymCrypt]: https://github.com/microsoft/SymCrypt
76//! [`boring-rustls-provider`]: https://github.com/janrueth/boring-rustls-provider
77//! [`boringssl`]: https://github.com/google/boringssl
78//! [`rustls-rustcrypto`]: https://github.com/RustCrypto/rustls-rustcrypto
79//! [`RustCrypto`]: https://github.com/RustCrypto
80//! [`rustls-post-quantum`]: https://crates.io/crates/rustls-post-quantum
81//! [`rustls-wolfcrypt-provider`]: https://github.com/wolfSSL/rustls-wolfcrypt-provider
82//! [`wolfCrypt`]: https://www.wolfssl.com/products/wolfcrypt
83//!
84//! #### Custom provider
85//!
86//! We also provide a simple example of writing your own provider in the [`custom-provider`]
87//! example. This example implements a minimal provider using parts of the [`RustCrypto`]
88//! ecosystem.
89//!
90//! See the [Making a custom CryptoProvider] section of the documentation for more information
91//! on this topic.
92//!
93//! [`custom-provider`]: 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//! # }
169//! ```
170//!
171//! Now we can make a connection. You need to provide the server's hostname so we
172//! know what to expect to find in the server's certificate.
173//!
174//! ```rust
175//! # #[cfg(feature = "aws_lc_rs")] {
176//! # use rustls;
177//! # use webpki;
178//! # use std::sync::Arc;
179//! # rustls::crypto::aws_lc_rs::default_provider().install_default();
180//! # let root_store = rustls::RootCertStore::from_iter(
181//! # webpki_roots::TLS_SERVER_ROOTS
182//! # .iter()
183//! # .cloned(),
184//! # );
185//! # let config = rustls::ClientConfig::builder()
186//! # .with_root_certificates(root_store)
187//! # .with_no_client_auth();
188//! let rc_config = Arc::new(config);
189//! let example_com = "example.com".try_into().unwrap();
190//! let mut client = rustls::ClientConnection::new(rc_config, example_com);
191//! # }
192//! ```
193//!
194//! Now you should do appropriate IO for the `client` object. If `client.wants_read()` yields
195//! true, you should call `client.read_tls()` when the underlying connection has data.
196//! Likewise, if `client.wants_write()` yields true, you should call `client.write_tls()`
197//! when the underlying connection is able to send data. You should continue doing this
198//! as long as the connection is valid.
199//!
200//! The return types of `read_tls()` and `write_tls()` only tell you if the IO worked. No
201//! parsing or processing of the TLS messages is done. After each `read_tls()` you should
202//! therefore call `client.process_new_packets()` which parses and processes the messages.
203//! Any error returned from `process_new_packets` is fatal to the connection, and will tell you
204//! why. For example, if the server's certificate is expired `process_new_packets` will
205//! return `Err(InvalidCertificate(Expired))`. From this point on,
206//! `process_new_packets` will not do any new work and will return that error continually.
207//!
208//! You can extract newly received data by calling `client.reader()` (which implements the
209//! `io::Read` trait). You can send data to the peer by calling `client.writer()` (which
210//! implements `io::Write` trait). Note that `client.writer().write()` buffers data you
211//! send if the TLS connection is not yet established: this is useful for writing (say) a
212//! HTTP request, but this is buffered so avoid large amounts of data.
213//!
214//! The following code uses a fictional socket IO API for illustration, and does not handle
215//! errors.
216//!
217//! ```rust,no_run
218//! # #[cfg(feature = "aws_lc_rs")] {
219//! # let mut client = rustls::ClientConnection::new(panic!(), panic!()).unwrap();
220//! # struct Socket { }
221//! # impl Socket {
222//! # fn ready_for_write(&self) -> bool { false }
223//! # fn ready_for_read(&self) -> bool { false }
224//! # fn wait_for_something_to_happen(&self) { }
225//! # }
226//! #
227//! # use std::io::{Read, Write, Result};
228//! # impl Read for Socket {
229//! # fn read(&mut self, buf: &mut [u8]) -> Result<usize> { panic!() }
230//! # }
231//! # impl Write for Socket {
232//! # fn write(&mut self, buf: &[u8]) -> Result<usize> { panic!() }
233//! # fn flush(&mut self) -> Result<()> { panic!() }
234//! # }
235//! #
236//! # fn connect(_address: &str, _port: u16) -> Socket {
237//! # panic!();
238//! # }
239//! use std::io;
240//! use rustls::Connection;
241//!
242//! client.writer().write(b"GET / HTTP/1.0\r\n\r\n").unwrap();
243//! let mut socket = connect("example.com", 443);
244//! loop {
245//! if client.wants_read() && socket.ready_for_read() {
246//! client.read_tls(&mut socket).unwrap();
247//! client.process_new_packets().unwrap();
248//!
249//! let mut plaintext = Vec::new();
250//! client.reader().read_to_end(&mut plaintext).unwrap();
251//! io::stdout().write(&plaintext).unwrap();
252//! }
253//!
254//! if client.wants_write() && socket.ready_for_write() {
255//! client.write_tls(&mut socket).unwrap();
256//! }
257//!
258//! socket.wait_for_something_to_happen();
259//! }
260//! # }
261//! ```
262//!
263//! # Examples
264//!
265//! You can find several client and server examples of varying complexity in the [examples]
266//! directory, including [`tlsserver-mio`](https://github.com/rustls/rustls/blob/main/examples/src/bin/tlsserver-mio.rs)
267//! and [`tlsclient-mio`](https://github.com/rustls/rustls/blob/main/examples/src/bin/tlsclient-mio.rs)
268//! \- full worked examples using [`mio`].
269//!
270//! [`mio`]: https://docs.rs/mio/latest/mio/
271//!
272//! # Crate features
273//! Here's a list of what features are exposed by the rustls crate and what
274//! they mean.
275//!
276//! - `aws_lc_rs` (enabled by default): makes the rustls crate depend on the [`aws-lc-rs`] crate.
277//! Use `rustls::crypto::aws_lc_rs::default_provider().install_default()` to
278//! use it as the default `CryptoProvider`, or provide it explicitly
279//! when making a `ClientConfig` or `ServerConfig`.
280//!
281//! Note that aws-lc-rs has additional build-time dependencies like cmake.
282//! See [the documentation](https://aws.github.io/aws-lc-rs/requirements/index.html) for details.
283//!
284//! - `ring`: makes the rustls crate depend on the *ring* crate for cryptography.
285//! Use `rustls::crypto::ring::default_provider().install_default()` to
286//! use it as the default `CryptoProvider`, or provide it explicitly
287//! when making a `ClientConfig` or `ServerConfig`.
288//!
289//! - `fips`: enable support for FIPS140-3-approved cryptography, via the aws-lc-rs crate.
290//! This feature enables the `aws_lc_rs` feature, which makes the rustls crate depend
291//! on [aws-lc-rs](https://github.com/aws/aws-lc-rs). It also changes the default
292//! for [`ServerConfig::require_ems`] and [`ClientConfig::require_ems`].
293//!
294//! See [manual::_06_fips] for more details.
295//!
296//! - `custom-provider`: disables implicit use of built-in providers (`aws-lc-rs` or `ring`). This forces
297//! applications to manually install one, for instance, when using a custom `CryptoProvider`.
298//!
299//! - `tls12` (enabled by default): enable support for TLS version 1.2. Note that, due to the
300//! additive nature of Cargo features and because it is enabled by default, other crates
301//! in your dependency graph could re-enable it for your application. If you want to disable
302//! TLS 1.2 for security reasons, consider explicitly enabling TLS 1.3 only in the config
303//! builder API.
304//!
305//! - `logging` (enabled by default): make the rustls crate depend on the `log` crate.
306//! rustls outputs interesting protocol-level messages at `trace!` and `debug!` level,
307//! and protocol-level errors at `warn!` and `error!` level. The log messages do not
308//! contain secret key data, and so are safe to archive without affecting session security.
309//!
310//! - `read_buf`: when building with Rust Nightly, adds support for the unstable
311//! `std::io::ReadBuf` and related APIs. This reduces costs from initializing
312//! buffers. Will do nothing on non-Nightly releases.
313//!
314//! - `brotli`: uses the `brotli` crate for RFC8879 certificate compression support.
315//!
316//! - `zlib`: uses the `zlib-rs` crate for RFC8879 certificate compression support.
317//!
318
319// Require docs for public APIs, deny unsafe code, etc.
320#![forbid(unsafe_code, unused_must_use)]
321#![cfg_attr(not(any(read_buf, bench)), forbid(unstable_features))]
322#![warn(
323 clippy::alloc_instead_of_core,
324 clippy::clone_on_ref_ptr,
325 clippy::manual_let_else,
326 clippy::std_instead_of_core,
327 clippy::use_self,
328 clippy::upper_case_acronyms,
329 elided_lifetimes_in_paths,
330 missing_docs,
331 trivial_casts,
332 trivial_numeric_casts,
333 unreachable_pub,
334 unused_import_braces,
335 unused_extern_crates,
336 unused_qualifications
337)]
338// Relax these clippy lints:
339// - ptr_arg: this triggers on references to type aliases that are Vec
340// underneath.
341// - too_many_arguments: some things just need a lot of state, wrapping it
342// doesn't necessarily make it easier to follow what's going on
343// - new_ret_no_self: we sometimes return `Arc<Self>`, which seems fine
344// - single_component_path_imports: our top-level `use log` import causes
345// a false positive, https://github.com/rust-lang/rust-clippy/issues/5210
346// - new_without_default: for internal constructors, the indirection is not
347// helpful
348#![allow(
349 clippy::too_many_arguments,
350 clippy::new_ret_no_self,
351 clippy::ptr_arg,
352 clippy::single_component_path_imports,
353 clippy::new_without_default
354)]
355// Enable documentation for all features on docs.rs
356#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
357// XXX: Because of https://github.com/rust-lang/rust/issues/54726, we cannot
358// write `#![rustversion::attr(nightly, feature(read_buf))]` here. Instead,
359// build.rs set `read_buf` for (only) Rust Nightly to get the same effect.
360//
361// All the other conditional logic in the crate could use
362// `#[rustversion::nightly]` instead of `#[cfg(read_buf)]`; `#[cfg(read_buf)]`
363// is used to avoid needing `rustversion` to be compiled twice during
364// cross-compiling.
365#![cfg_attr(read_buf, feature(read_buf))]
366#![cfg_attr(read_buf, feature(core_io_borrowed_buf))]
367#![cfg_attr(bench, feature(test))]
368#![no_std]
369
370extern crate alloc;
371// This `extern crate` plus the `#![no_std]` attribute changes the default prelude from
372// `std::prelude` to `core::prelude`. That forces one to _explicitly_ import (`use`) everything that
373// is in `std::prelude` but not in `core::prelude`. This helps maintain no-std support as even
374// developers that are not interested in, or aware of, no-std support and / or that never run
375// `cargo build --no-default-features` locally will get errors when they rely on `std::prelude` API.
376#[cfg(any(feature = "std", test))]
377extern crate std;
378
379#[cfg(doc)]
380use crate::crypto::CryptoProvider;
381
382// Import `test` sysroot crate for `Bencher` definitions.
383#[cfg(bench)]
384#[allow(unused_extern_crates)]
385extern crate test;
386
387// log for logging (optional).
388#[cfg(feature = "logging")]
389use log;
390
391#[cfg(not(feature = "logging"))]
392mod log {
393 macro_rules! trace ( ($($tt:tt)*) => {{}} );
394 macro_rules! debug ( ($($tt:tt)*) => {{}} );
395 macro_rules! error ( ($($tt:tt)*) => {{}} );
396 macro_rules! _warn ( ($($tt:tt)*) => {{}} );
397 pub(crate) use {_warn as warn, debug, error, trace};
398}
399
400#[cfg(test)]
401#[macro_use]
402mod test_macros;
403
404#[macro_use]
405mod msgs;
406mod common_state;
407pub mod compress;
408mod conn;
409/// Crypto provider interface.
410pub mod crypto;
411mod error;
412mod hash_hs;
413#[cfg(any(feature = "std", feature = "hashbrown"))]
414mod limited_cache;
415mod rand;
416mod record_layer;
417#[cfg(feature = "std")]
418mod stream;
419#[cfg(feature = "tls12")]
420mod tls12;
421mod tls13;
422mod vecbuf;
423mod verify;
424#[cfg(test)]
425mod verifybench;
426mod x509;
427#[macro_use]
428mod check;
429#[cfg(feature = "logging")]
430mod bs_debug;
431mod builder;
432mod enums;
433mod key_log;
434#[cfg(feature = "std")]
435mod key_log_file;
436mod suites;
437mod versions;
438mod webpki;
439
440/// Internal classes that are used in integration tests.
441/// The contents of this section DO NOT form part of the stable interface.
442#[allow(missing_docs)]
443#[doc(hidden)]
444pub mod internal {
445 /// Low-level TLS message parsing and encoding functions.
446 pub mod msgs {
447 pub mod base {
448 pub use crate::msgs::base::{Payload, PayloadU16};
449 }
450 pub mod codec {
451 pub use crate::msgs::codec::{Codec, Reader};
452 }
453 pub mod enums {
454 pub use crate::msgs::enums::{
455 AlertLevel, CertificateType, Compression, EchVersion, HpkeAead, HpkeKdf, HpkeKem,
456 NamedGroup,
457 };
458 }
459 pub mod fragmenter {
460 pub use crate::msgs::fragmenter::MessageFragmenter;
461 }
462 pub mod handshake {
463 pub use crate::msgs::handshake::{
464 CertificateChain, ClientExtension, ClientHelloPayload, DistinguishedName,
465 EchConfigContents, EchConfigPayload, HandshakeMessagePayload, HandshakePayload,
466 HpkeKeyConfig, HpkeSymmetricCipherSuite, KeyShareEntry, Random, ServerExtension,
467 ServerName, SessionId,
468 };
469 }
470 pub mod message {
471 pub use crate::msgs::message::{
472 Message, MessagePayload, OutboundOpaqueMessage, PlainMessage,
473 };
474 }
475 pub mod persist {
476 pub use crate::msgs::persist::ServerSessionValue;
477 }
478 }
479
480 pub use crate::tls13::key_schedule::{derive_traffic_iv, derive_traffic_key};
481
482 pub mod fuzzing {
483 pub use crate::msgs::deframer::fuzz_deframer;
484 }
485}
486
487/// Unbuffered connection API
488///
489/// This is an alternative to the [`crate::ConnectionCommon`] API that does not internally buffer
490/// TLS nor plaintext data. Instead those buffers are managed by the API user so they have
491/// control over when and how to allocate, resize and dispose of them.
492///
493/// This API is lower level than the `ConnectionCommon` API and is built around a state machine
494/// interface where the API user must handle each state to advance and complete the
495/// handshake process.
496///
497/// Like the `ConnectionCommon` API, no IO happens internally so all IO must be handled by the API
498/// user. Unlike the `ConnectionCommon` API, this API does not make use of the [`std::io::Read`] and
499/// [`std::io::Write`] traits so it's usable in no-std context.
500///
501/// The entry points into this API are [`crate::client::UnbufferedClientConnection::new`],
502/// [`crate::server::UnbufferedServerConnection::new`] and
503/// [`unbuffered::UnbufferedConnectionCommon::process_tls_records`]. The state machine API is
504/// documented in [`unbuffered::ConnectionState`].
505///
506/// # Examples
507///
508/// [`unbuffered-client`] and [`unbuffered-server`] are examples that fully exercise the API in
509/// std, non-async context.
510///
511/// [`unbuffered-client`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffered-client.rs
512/// [`unbuffered-server`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffered-server.rs
513pub mod unbuffered {
514 pub use crate::conn::unbuffered::{
515 AppDataRecord, ConnectionState, EncodeError, EncodeTlsData, EncryptError,
516 InsufficientSizeError, ReadEarlyData, ReadTraffic, TransmitTlsData, UnbufferedStatus,
517 WriteTraffic,
518 };
519 pub use crate::conn::UnbufferedConnectionCommon;
520}
521
522// The public interface is:
523pub use crate::builder::{ConfigBuilder, ConfigSide, WantsVerifier, WantsVersions};
524pub use crate::common_state::{CommonState, HandshakeKind, IoState, Side};
525#[cfg(feature = "std")]
526pub use crate::conn::{Connection, Reader, Writer};
527pub use crate::conn::{ConnectionCommon, SideData};
528pub use crate::enums::{
529 AlertDescription, CertificateCompressionAlgorithm, CipherSuite, ContentType, HandshakeType,
530 ProtocolVersion, SignatureAlgorithm, SignatureScheme,
531};
532pub use crate::error::{
533 CertRevocationListError, CertificateError, EncryptedClientHelloError, Error, InconsistentKeys,
534 InvalidMessage, OtherError, PeerIncompatible, PeerMisbehaved,
535};
536pub use crate::key_log::{KeyLog, NoKeyLog};
537#[cfg(feature = "std")]
538pub use crate::key_log_file::KeyLogFile;
539pub use crate::msgs::enums::NamedGroup;
540pub use crate::msgs::ffdhe_groups;
541pub use crate::msgs::handshake::DistinguishedName;
542#[cfg(feature = "std")]
543pub use crate::stream::{Stream, StreamOwned};
544pub use crate::suites::{
545 CipherSuiteCommon, ConnectionTrafficSecrets, ExtractedSecrets, SupportedCipherSuite,
546};
547#[cfg(feature = "std")]
548pub use crate::ticketer::TicketRotator;
549#[cfg(any(feature = "std", feature = "hashbrown"))] // < XXX: incorrect feature gate
550pub use crate::ticketer::TicketSwitcher;
551#[cfg(feature = "tls12")]
552pub use crate::tls12::Tls12CipherSuite;
553pub use crate::tls13::Tls13CipherSuite;
554pub use crate::verify::DigitallySignedStruct;
555pub use crate::versions::{SupportedProtocolVersion, ALL_VERSIONS, DEFAULT_VERSIONS};
556pub use crate::webpki::RootCertStore;
557
558/// Items for use in a client.
559pub mod client {
560 pub(super) mod builder;
561 mod client_conn;
562 mod common;
563 mod ech;
564 pub(super) mod handy;
565 mod hs;
566 #[cfg(feature = "tls12")]
567 mod tls12;
568 mod tls13;
569
570 pub use builder::WantsClientCert;
571 pub use client_conn::{
572 ClientConfig, ClientConnectionData, ClientSessionStore, EarlyDataError, ResolvesClientCert,
573 Resumption, Tls12Resumption, UnbufferedClientConnection,
574 };
575 #[cfg(feature = "std")]
576 pub use client_conn::{ClientConnection, WriteEarlyData};
577 pub use ech::{EchConfig, EchGreaseConfig, EchMode, EchStatus};
578 pub use handy::AlwaysResolvesClientRawPublicKeys;
579 #[cfg(any(feature = "std", feature = "hashbrown"))]
580 pub use handy::ClientSessionMemoryCache;
581
582 /// Dangerous configuration that should be audited and used with extreme care.
583 pub mod danger {
584 pub use super::builder::danger::DangerousClientConfigBuilder;
585 pub use super::client_conn::danger::DangerousClientConfig;
586 pub use crate::verify::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier};
587 }
588
589 pub use crate::msgs::persist::{Tls12ClientSessionValue, Tls13ClientSessionValue};
590 pub use crate::webpki::{
591 verify_server_cert_signed_by_trust_anchor, verify_server_name, ServerCertVerifierBuilder,
592 VerifierBuilderError, WebPkiServerVerifier,
593 };
594}
595
596pub use client::ClientConfig;
597#[cfg(feature = "std")]
598pub use client::ClientConnection;
599
600/// Items for use in a server.
601pub mod server {
602 pub(crate) mod builder;
603 mod common;
604 pub(crate) mod handy;
605 mod hs;
606 mod server_conn;
607 #[cfg(feature = "tls12")]
608 mod tls12;
609 mod tls13;
610
611 pub use builder::WantsServerCert;
612 #[cfg(any(feature = "std", feature = "hashbrown"))]
613 pub use handy::ResolvesServerCertUsingSni;
614 #[cfg(any(feature = "std", feature = "hashbrown"))]
615 pub use handy::ServerSessionMemoryCache;
616 pub use handy::{AlwaysResolvesServerRawPublicKeys, NoServerSessionStorage};
617 pub use server_conn::{
618 Accepted, ClientHello, ProducesTickets, ResolvesServerCert, ServerConfig,
619 ServerConnectionData, StoresServerSessions, UnbufferedServerConnection,
620 };
621 #[cfg(feature = "std")]
622 pub use server_conn::{AcceptedAlert, Acceptor, ReadEarlyData, ServerConnection};
623
624 pub use crate::verify::NoClientAuth;
625 pub use crate::webpki::{
626 ClientCertVerifierBuilder, ParsedCertificate, VerifierBuilderError, WebPkiClientVerifier,
627 };
628
629 /// Dangerous configuration that should be audited and used with extreme care.
630 pub mod danger {
631 pub use crate::verify::{ClientCertVerified, ClientCertVerifier};
632 }
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 #[cfg(feature = "tls12")]
644 pub use crate::versions::TLS12;
645 pub use crate::versions::TLS13;
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};
657}
658
659/// APIs for implementing QUIC TLS
660pub mod quic;
661
662#[cfg(any(feature = "std", feature = "hashbrown"))] // < XXX: incorrect feature gate
663/// APIs for implementing TLS tickets
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::hash_map::Entry;
681 #[cfg(feature = "std")]
682 pub(crate) use std::collections::HashMap;
683
684 #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
685 pub(crate) use hashbrown::hash_map::Entry;
686 #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
687 pub(crate) use hashbrown::HashMap;
688}