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