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.83 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::cloned_instead_of_copied,
325 clippy::exhaustive_enums,
326 clippy::exhaustive_structs,
327 clippy::manual_let_else,
328 clippy::or_fun_call,
329 clippy::std_instead_of_core,
330 clippy::use_self,
331 clippy::upper_case_acronyms,
332 elided_lifetimes_in_paths,
333 missing_docs,
334 trivial_numeric_casts,
335 unnameable_types,
336 unreachable_pub,
337 unused_import_braces,
338 unused_extern_crates,
339 unused_qualifications
340)]
341// Relax these clippy lints:
342// - ptr_arg: this triggers on references to type aliases that are Vec
343// underneath.
344// - too_many_arguments: some things just need a lot of state, wrapping it
345// doesn't necessarily make it easier to follow what's going on
346// - new_ret_no_self: we sometimes return `Arc<Self>`, which seems fine
347// - single_component_path_imports: our top-level `use log` import causes
348// a false positive, https://github.com/rust-lang/rust-clippy/issues/5210
349// - new_without_default: for internal constructors, the indirection is not
350// helpful
351#![allow(
352 clippy::too_many_arguments,
353 clippy::new_ret_no_self,
354 clippy::ptr_arg,
355 clippy::single_component_path_imports,
356 clippy::new_without_default
357)]
358// Enable documentation for all features on docs.rs
359#![cfg_attr(rustls_docsrs, feature(doc_cfg))]
360// Enable coverage() attr for nightly coverage builds, see
361// <https://github.com/rust-lang/rust/issues/84605>
362// (`coverage_nightly` is a cfg set by `cargo-llvm-cov`)
363#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
364#![cfg_attr(bench, feature(test))]
365#![no_std]
366
367extern crate alloc;
368// This `extern crate` plus the `#![no_std]` attribute changes the default prelude from
369// `std::prelude` to `core::prelude`. That forces one to _explicitly_ import (`use`) everything that
370// is in `std::prelude` but not in `core::prelude`. This helps maintain no-std support as even
371// developers that are not interested in, or aware of, no-std support and / or that never run
372// `cargo build --no-default-features` locally will get errors when they rely on `std::prelude` API.
373#[cfg(any(feature = "std", test))]
374extern crate std;
375
376#[cfg(doc)]
377use crate::crypto::CryptoProvider;
378
379// Import `test` sysroot crate for `Bencher` definitions.
380#[cfg(bench)]
381#[allow(unused_extern_crates)]
382extern crate test;
383
384// log for logging (optional).
385#[cfg(feature = "log")]
386use log;
387
388#[cfg(not(feature = "log"))]
389mod log {
390 macro_rules! trace ( ($($tt:tt)*) => {{}} );
391 macro_rules! debug ( ($($tt:tt)*) => {{}} );
392 macro_rules! error ( ($($tt:tt)*) => {{}} );
393 macro_rules! _warn ( ($($tt:tt)*) => {{}} );
394 pub(crate) use {_warn as warn, debug, error, trace};
395}
396
397#[cfg(test)]
398#[macro_use]
399mod test_macros;
400
401/// This internal `sync` module aliases the `Arc` implementation to allow downstream forks
402/// of rustls targeting architectures without atomic pointers to replace the implementation
403/// with another implementation such as `portable_atomic_util::Arc` in one central location.
404mod sync {
405 #[allow(clippy::disallowed_types)]
406 pub(crate) type Arc<T> = alloc::sync::Arc<T>;
407 #[allow(clippy::disallowed_types)]
408 pub(crate) type Weak<T> = alloc::sync::Weak<T>;
409}
410
411#[allow(unnameable_types)]
412#[macro_use]
413mod msgs;
414mod common_state;
415pub mod compress;
416mod conn;
417/// Crypto provider interface.
418pub mod crypto;
419pub mod error;
420mod hash_hs;
421#[cfg(any(feature = "std", feature = "hashbrown"))]
422mod limited_cache;
423mod rand;
424mod record_layer;
425#[cfg(feature = "std")]
426mod stream;
427mod tls12;
428mod tls13;
429mod vecbuf;
430mod verify;
431#[cfg(test)]
432mod verifybench;
433mod x509;
434#[macro_use]
435mod check;
436#[cfg(feature = "log")]
437mod bs_debug;
438mod builder;
439pub mod enums;
440mod key_log;
441#[cfg(feature = "std")]
442mod key_log_file;
443mod suites;
444mod versions;
445mod webpki;
446
447/// Internal classes that are used in integration tests.
448/// The contents of this section DO NOT form part of the stable interface.
449#[allow(missing_docs, unnameable_types)]
450#[doc(hidden)]
451pub mod internal {
452 /// Low-level TLS message parsing and encoding functions.
453 pub mod msgs {
454 pub mod base {
455 pub use crate::msgs::base::{Payload, PayloadU16};
456 }
457 pub mod codec {
458 pub use crate::msgs::codec::{Codec, Reader};
459 }
460 pub mod enums {
461 pub use crate::msgs::enums::{AlertLevel, ExtensionType};
462 }
463 pub mod fragmenter {
464 pub use crate::msgs::fragmenter::MessageFragmenter;
465 }
466 pub mod message {
467 pub use crate::msgs::message::{
468 Message, MessagePayload, OutboundOpaqueMessage, PlainMessage,
469 };
470 }
471 pub mod persist {
472 pub use crate::msgs::persist::ServerSessionValue;
473 }
474 }
475
476 pub use crate::tls13::key_schedule::{derive_traffic_iv, derive_traffic_key};
477
478 pub mod fuzzing {
479 pub use crate::msgs::deframer::fuzz_deframer;
480 }
481}
482
483/// Unbuffered connection API
484///
485/// This is an alternative to the [`crate::ConnectionCommon`] API that does not internally buffer
486/// TLS nor plaintext data. Instead those buffers are managed by the API user so they have
487/// control over when and how to allocate, resize and dispose of them.
488///
489/// This API is lower level than the `ConnectionCommon` API and is built around a state machine
490/// interface where the API user must handle each state to advance and complete the
491/// handshake process.
492///
493/// Like the `ConnectionCommon` API, no IO happens internally so all IO must be handled by the API
494/// user. Unlike the `ConnectionCommon` API, this API does not make use of the [`std::io::Read`] and
495/// [`std::io::Write`] traits so it's usable in no-std context.
496///
497/// The entry points into this API are [`crate::client::UnbufferedClientConnection::new`],
498/// [`crate::server::UnbufferedServerConnection::new`] and
499/// [`unbuffered::UnbufferedConnectionCommon::process_tls_records`]. The state machine API is
500/// documented in [`unbuffered::ConnectionState`].
501///
502/// # Examples
503///
504/// [`unbuffered-client`] and [`unbuffered-server`] are examples that fully exercise the API in
505/// std, non-async context.
506///
507/// [`unbuffered-client`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffered-client.rs
508/// [`unbuffered-server`]: https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffered-server.rs
509pub mod unbuffered {
510 pub use crate::conn::UnbufferedConnectionCommon;
511 pub use crate::conn::unbuffered::{
512 AppDataRecord, ConnectionState, EncodeError, EncodeTlsData, EncryptError,
513 InsufficientSizeError, ReadEarlyData, ReadTraffic, TransmitTlsData, UnbufferedStatus,
514 WriteTraffic,
515 };
516}
517
518// The public interface is:
519pub use crate::builder::{ConfigBuilder, ConfigSide, WantsVerifier};
520pub use crate::common_state::{CommonState, HandshakeKind, IoState, Side};
521#[cfg(feature = "std")]
522pub use crate::conn::{Connection, Reader, Writer};
523pub use crate::conn::{ConnectionCommon, KeyingMaterialExporter, SideData, kernel};
524pub use crate::error::Error;
525pub use crate::key_log::{KeyLog, NoKeyLog};
526#[cfg(feature = "std")]
527pub use crate::key_log_file::KeyLogFile;
528pub use crate::msgs::enums::NamedGroup;
529pub use crate::msgs::ffdhe_groups;
530pub use crate::msgs::handshake::DistinguishedName;
531#[cfg(feature = "std")]
532pub use crate::stream::{Stream, StreamOwned};
533pub use crate::suites::{
534 CipherSuiteCommon, ConnectionTrafficSecrets, ExtractedSecrets, SupportedCipherSuite,
535};
536#[cfg(feature = "std")]
537pub use crate::ticketer::TicketRotator;
538pub use crate::tls12::Tls12CipherSuite;
539pub use crate::tls13::Tls13CipherSuite;
540pub use crate::verify::{DigitallySignedStruct, SignerPublicKey};
541pub use crate::versions::{ALL_VERSIONS, DEFAULT_VERSIONS, SupportedProtocolVersion};
542pub use crate::webpki::RootCertStore;
543
544/// Items for use in a client.
545pub mod client {
546 pub(super) mod builder;
547 mod client_conn;
548 mod common;
549 mod ech;
550 pub(super) mod handy;
551 mod hs;
552 #[cfg(test)]
553 mod test;
554 mod tls12;
555 mod tls13;
556
557 pub use builder::WantsClientCert;
558 pub use client_conn::{
559 ClientConfig, ClientConnectionData, ClientCredentialResolver, ClientSessionStore,
560 CredentialRequest, EarlyDataError, MayEncryptEarlyData, Resumption, Tls12Resumption,
561 UnbufferedClientConnection,
562 };
563 #[cfg(feature = "std")]
564 pub use client_conn::{ClientConnection, WriteEarlyData};
565 pub use ech::{EchConfig, EchGreaseConfig, EchMode, EchStatus};
566 pub use handy::AlwaysResolvesClientRawPublicKeys;
567 #[cfg(any(feature = "std", feature = "hashbrown"))]
568 pub use handy::ClientSessionMemoryCache;
569
570 /// Dangerous configuration that should be audited and used with extreme care.
571 pub mod danger {
572 pub use super::builder::danger::DangerousClientConfigBuilder;
573 pub use super::client_conn::danger::DangerousClientConfig;
574 pub use crate::verify::{
575 HandshakeSignatureValid, PeerVerified, ServerIdentity, ServerVerifier,
576 SignatureVerificationInput,
577 };
578 }
579
580 pub(crate) use hs::ClientHandler;
581 pub(crate) use tls12::TLS12_HANDLER;
582 pub(crate) use tls13::TLS13_HANDLER;
583
584 pub use crate::msgs::persist::{Tls12ClientSessionValue, Tls13ClientSessionValue};
585 pub use crate::webpki::{
586 ServerVerifierBuilder, VerifierBuilderError, WebPkiServerVerifier,
587 verify_identity_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 pub(crate) mod handy;
599 mod hs;
600 mod server_conn;
601 #[cfg(test)]
602 mod test;
603 mod tls12;
604 mod tls13;
605
606 pub use builder::WantsServerCert;
607 #[cfg(any(feature = "std", feature = "hashbrown"))]
608 pub use handy::ServerNameResolver;
609 #[cfg(any(feature = "std", feature = "hashbrown"))]
610 pub use handy::ServerSessionMemoryCache;
611 pub use handy::{NoServerSessionStorage, SingleRawPublicKeyResolver};
612 #[cfg(feature = "std")]
613 pub use server_conn::{Accepted, AcceptedAlert, Acceptor, ReadEarlyData, ServerConnection};
614 pub use server_conn::{
615 ClientHello, InvalidSniPolicy, ProducesTickets, ServerConfig, ServerConnectionData,
616 ServerCredentialResolver, StoresServerSessions, UnbufferedServerConnection,
617 };
618
619 pub use crate::verify::NoClientAuth;
620 pub use crate::webpki::{
621 ClientVerifierBuilder, ParsedCertificate, VerifierBuilderError, WebPkiClientVerifier,
622 };
623
624 /// Dangerous configuration that should be audited and used with extreme care.
625 pub mod danger {
626 pub use crate::verify::{
627 ClientIdentity, ClientVerifier, PeerVerified, SignatureVerificationInput,
628 };
629 }
630
631 pub(crate) use hs::ServerHandler;
632 pub(crate) use tls12::TLS12_HANDLER;
633 pub(crate) use tls13::TLS13_HANDLER;
634}
635
636pub use server::ServerConfig;
637#[cfg(feature = "std")]
638pub use server::ServerConnection;
639
640/// All defined protocol versions appear in this module.
641///
642/// ALL_VERSIONS is a provided as an array of all of these values.
643pub mod version {
644 pub use crate::versions::{
645 TLS12, TLS12_VERSION, TLS13, TLS13_VERSION, Tls12Version, Tls13Version,
646 };
647}
648
649/// Re-exports the contents of the [rustls-pki-types](https://docs.rs/rustls-pki-types) crate for easy access
650pub mod pki_types {
651 #[doc(no_inline)]
652 pub use pki_types::*;
653}
654
655/// APIs for implementing QUIC TLS
656pub mod quic;
657
658/// APIs for implementing TLS tickets
659#[cfg(feature = "std")]
660pub mod ticketer;
661
662/// This is the rustls manual.
663pub mod manual;
664
665pub mod time_provider;
666
667/// APIs abstracting over locking primitives.
668pub mod lock;
669
670#[cfg(any(feature = "std", feature = "hashbrown"))]
671mod hash_map {
672 #[cfg(feature = "std")]
673 pub(crate) use std::collections::HashMap;
674 #[cfg(feature = "std")]
675 pub(crate) use std::collections::hash_map::Entry;
676
677 #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
678 pub(crate) use hashbrown::HashMap;
679 #[cfg(all(not(feature = "std"), feature = "hashbrown"))]
680 pub(crate) use hashbrown::hash_map::Entry;
681}
682
683mod sealed {
684 #[allow(unnameable_types)]
685 pub trait Sealed {}
686}