Commit Graph

85 Commits

Author SHA1 Message Date
Joseph Birr-Pixton 363910b701 Extract all straight lookups of suites and kx groups 2024-02-20 10:35:13 +00:00
Joseph Birr-Pixton f6cd567fc2 Improve linking to per-process default provider docs 2024-02-19 11:05:47 +00:00
Eloi DEMOLIS 2f02ddc21b Create type OutboundChunks for OutboundMessage
The ConnectionCommon<T>::write_vectored was implemented by processing
each chunk, fragmenting them and wrapping each fragment in a
OutboundMessage before encrypting and sending it as separate TLS frames.
For very fragmented payloads this generates a lot of very small payloads
with most of the data being TLS headers.

OutboundChunks can contain an arbitrary amount of fragmented chunks.
This allows write_vectored to process all its chunks at once,
fragmenting it in place if needed and wrapping it in a OutboundMessage.
All the chunks are merged in a contiguous vector (taking atvantage of an
already existent copy) before being encrypted and sent as a single TLS
frame.

Signed-off-by: Eloi DEMOLIS <eloi.demolis@clever-cloud.com>
Co-Authored-By: Emmanuel Bosquet <bjokac@gmail.com>
2024-02-16 09:10:13 +00:00
Joseph Birr-Pixton e7a1b41852 Introduce concept of "process default" provider
One can be installed with `CryptoProvider::install_default`.
First call wins.

The current value can be retrieved with `CryptoProvider::get_default()`.

This can be set from the crate features, if and only if they are unambigious,
by installing the result of `CryptoProvider::from_crate_features()`.

Use this for `ClientConfig::builder` and `ServerConfig::builder` et al.
Naturally, `ClientConfig::builder_with_provider` and co. continue to exist.
2024-02-07 16:02:26 +00:00
Joseph Birr-Pixton 5cc71572e4 Default to `require_ems` in FIPS mode
Change default for `require_ems` based on `fips` crate feature,
generalising the existing tests for `require_ems` to verify this too.

Include `require_ems` in `fips()` determination.
2024-02-05 16:37:30 +00:00
Sean McGrail 6bd851e72e Add 'fips' Cargo feature
Add `rustls::crypto::default_fips_provider()` behind this
feature.
2024-02-02 16:57:39 +00:00
Joseph Birr-Pixton c83b4243b6 Expose FIPS "service indicator"
This means a `ClientConfig` and `ServerConfig` can be asked whether it
is in fips mode, and it answers by asking the same of all its
constituent cryptography.

Take new rustls-webpki and pki-types to ask the same of
`SignatureVerificationAlgorithm`.
2024-02-02 16:57:39 +00:00
YX Cao f965b9cd59 Add config field to require `extended_master_secret`
extension support from peer in TLS 1.2

* Add server config for requiring
`extended_master_secret` extension from peer.

* Add client config for requiring
`extended_master_secret` extension from peer.

* Add tests cases for server and client when requiring
`extended_master_secret` extension from peer.
2024-01-23 10:05:46 +00:00
Daniel McCarney 962814eadb client: reorder ClientConfig fields by visibility
`pub` fields should appear first, then `pub(super)` ones.
2024-01-09 14:41:03 +00:00
Daniel McCarney be5a62294c client: order ClientConfig impls
The inherit `ClientConfig` impl should appear first, and then the
`Clone` impl.
2024-01-09 14:41:03 +00:00
Daniel McCarney 8285bf1b28 client: move TLs12Resumption enum down
The `ClientConfig` parts should appear before the types it references.
The `Tls12Resumption` enum should appear after the `Resumption` type
that uses it.
2024-01-09 14:41:03 +00:00
Christian Poveda f544352a2c move sendable_plaintext from CommonState to ConnectionCommon 2023-12-20 16:15:25 +00:00
Jorge Aparicio 07297f7f4f early data support 2023-12-19 09:30:04 +00:00
Jorge Aparicio 57c963951f add UnbufferedClientConnection API + example 2023-12-19 09:30:04 +00:00
Jacob Hoffman-Andrews 6845c013cb doc: remove `crate::` prefix for links
Instead, use `#[cfg(doc)]` to conditionally import names that we want to
use in the docs. This provides a user-friendlier link name.
2023-12-04 17:58:51 +00:00
Daniel McCarney a7191785f6 remove unwrap for protocol versions w/ default provider
When building a client config or a server config using the default
provider we know that the ciphersuites will be compatible with any
choice of protocol version. By having the default `builder` method
configure itself with safe default versions, and offering
a `builder_with_protocol_versions` for customization we can transition
directly to `WantsVerifier` for these default provider builders,
removing a `Result` that will never be an error and making the API more
ergonomic in the common case.
2023-11-30 15:53:39 +00:00
Daniel McCarney b92fd839e3 crypto: rework CryptoProvider as struct
This commit replaces the existing `CryptoProvider` trait with
a `CryptoProvider` struct. This has several advantages:

* it consolidates all of the cryptography related settings into one API
  surface, the `CryptoProvider` struct members. Previously the provider
  had methods to suggest default ciphersuites, key exchanges etc, but
  the builder API methods could override them in confusing ways.
* it allows removing the `WantsCipherSuites` and `WantsKxGroups` builder
  states - the "safe defaults" are automatically supplied by the choice
  of a crypto provider. Customization is achieved by overriding the
  provider's struct fields. Having fewer builder states makes the API
  easier to understand and document.
* it makes customization easier: the end user can rely on "struct update
  syntax"[0] to only specify fields values for the required
  customization, and defer the rest to an existing `CryptoProvider`.

Achieving this requires a couple of additional changes:

* The cipher suite and key exchange groups are now expressed as `Vec`
  elements. This avoids imposing a `&'static` lifetime that would
  preclude runtime customization (e.g. the tls*-mio examples that
  build the list of ciphersuites at runtime based on command line
  flags).
* As a result of the `Vec` members we can no longer offer the concrete
  `CryptoProvider`s as `static` members of their respective modules.
  Instead we add `pub fn default_provider() -> CryptoProvider` methods
  to the `ring` and `aws-lc-rs` module that construct the `CryptoProvider`
  with the safe defaults, ready for further customization.

[0]: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
2023-11-30 15:53:39 +00:00
Dirkjan Ochtman 26ec868b8c Migrate to pki-types ServerName 2023-11-23 21:57:10 +00:00
Dirkjan Ochtman 93086c04a1 Inline single-use helper method 2023-11-23 21:57:10 +00:00
Joseph Birr-Pixton cd81f32592 quic: give helpful error if used with unsuitable suite
Now Tls13CipherSuite can omit QUIC support, detect and error
on the case that all the configured suites are TLS1.3-capable
but QUIC-incapable.
2023-11-17 19:27:21 +00:00
Daniel McCarney 557da04188 client: derive Debug for Resumption
All of the fields of `Resumption` are now `Debug` friendly, so we can
derive `Debug` instead of implementing it by hand.
2023-11-09 18:26:12 +00:00
Daniel McCarney 4196a01099 client: derive Debug for ClientConfig
All of the fields of `ClientConfig` are now `Debug` friendly, so we can
derive `Debug` instead of implementing it by hand.
2023-11-09 18:26:12 +00:00
Daniel McCarney a7f4ff9f4e client: add Debug bound to ResolvesClientCert
This commit adds a `Debug` bound to the `ResolvesClientCert` trait,
alongside `Send` and `Sync`. The types implementing this trait are
updated to either derive `Debug`, or implement it by hand, as
appropriate.
2023-11-09 18:26:12 +00:00
Daniel McCarney cee7e700e5 conn: add Debug bound to SideData
This commit adds a `Debug` bound to the `SideData` trait. The types
implementing it are updated to derive `Debug` or implement it by hand as
appropriate.
2023-11-09 18:26:12 +00:00
Daniel McCarney 7445b53d58 client: add Debug bound to ClientSessionStore trait
This commit adds a `Debug` bound to the `ClientSessionStore` trait,
alongside `Send` and `Sync`. Types implementing the trait are updated
with derived or hand-written `Debug` impls as appropriate, taking care
to avoid leaking any sensitive information.
2023-11-09 18:26:12 +00:00
Joseph Birr-Pixton 48d78f7232 Improve docs around `{Server,Client}Config::builder` 2023-11-09 16:18:11 +00:00
Daniel McCarney 7f071c7868 clarify hinted trust anchor subjects
This commit renames the `ClientCertVerifier::client_auth_root_subjects`
fn to `root_hint_subjects` to emphasize that these subjects
may be distinct from the subjects of the verifier's trust anchors. The
`client_auth` prefix is dropped as obvious from context.

The Rustdoc comment for the trait fn is expanded to give more
information about what these hint subjects are used for, and why there
are instances where the hint subject names aren't 1:1 with the
verifier's root cert store subject names.

Similarly the `ResolvesClientCert::resolve` fn's argument is renamed
from `root_hint_subjects` and the rustdoc gains additional context.
2023-10-30 15:04:46 +00:00
Jorge Aparicio 5427a4d6e9 use `core::prelude` instead of `std::prelude` 2023-10-10 15:53:23 +00:00
Daniel McCarney 21a7df5700 proj: remove secret_extraction feature
In an effort to reduce our feature list, this commit replaces the
`secret_extraction` feature flag with functions that are always present,
but named `dangerous_extract_secrets` to emphasize potential danger.

Cargo features are additive, which means transitive dependencies could
enable them for you without explicit opt-in. Using obviously named
functions will maintain the property that it's easy to grep for imports,
but avoids feature flag bloat and the additive downsides.
2023-09-27 13:21:16 +00:00
Daniel McCarney 5fd434f7bd proj: remove dangerous_configuration feature
In an effort to reduce our feature list, this commit replaces the
`dangerous_configuration` feature flag with separate `danger` modules.

Cargo features are additive, which means transitive dependencies could
enable them for you without explicit opt-in. Using obviously named
modules will maintain the property that it's easy to grep for imports,
but avoids feature flag bloat and the additive downsides.

After discussion we've chosen to not include the webpki verifier and
helper functions as part of the dangerous API surface. Functionality for
setting a custom verifier, or implementing one to make assertions about
verification status, remain marked as dangerous via their module name.
2023-09-19 17:53:52 +00:00
Joseph Birr-Pixton 048ff10740 Use dynamic dispatch for `CryptoProvider`
Instead of the type `rustls::crypto:💍:Ring`, the value
`rustls::crypto:💍:RING` implements this, and is more
entertaining to write.

`ServerConfig::builder()` references this by default, and
is equivalent to `ServerConfig::builder_with_provider(crypto:💍:RING)`.
2023-09-19 11:09:38 +00:00
Joseph Birr-Pixton 6cb43a65df Extract lookup of named SupportedKxGroup into function 2023-09-19 11:09:38 +00:00
Joseph Birr-Pixton 0e1908890d Use dynamic dispatch for key exchanges
This turns `SupportedKxGroup` into a trait, which can tell you
which `NamedGroup` it is, and `start()` an `ActiveKeyExchange`.

An `ActiveKeyExchange` represents the need for the peer's public key
which can be passed to `ActiveKeyExchange::complete`.

Unfortunately we can't be generic at compile-time over the various uses
of the resulting shared secret, so define a further type
which encapsulates the resulting shared secret.

Predefined key exchange algorithms (eg `rustls::kx_group::X25519`)
are now `&'static dyn rustls::SupportedKxGroup`.

The remainder of this commit is noise as much code ceased needing
to be generic of CryptoProvider (for its `KeyExchange` associated type).
2023-09-19 11:09:38 +00:00
Dirkjan Ochtman 09903a5c1e Clarify that building configs is not actually expensive
The actually expensive part is mostly the gathering of certificates
from the platform trust root store, and it would be better to document
that in the relevant API (that is, in rustls-native-certs). Apart
from that, I believe that the use of `Arc`-wrapped types is also an
effective signal that the wrapped types should be reused where possible.
2023-08-24 15:39:12 +00:00
Jacob Hoffman-Andrews f0e7dd2cca doc: fix max_fragment_size docs
The docs formerly said the default maximum was 2**16 (64 kB) but according to
spec (and implementation) it's actually 2**14 (16 kb).

The docs recommended setting to TCP MSS but by my understanding there is a
little record overhead so it's better to set this to a little under the MSS.

Clarified that there is in fact a limit when the default value of None is used.

Use the slightly more precise "TLS record" instead of "TLS message".
2023-08-18 17:10:31 +00:00
Joseph Birr-Pixton 9bdb243ffa Enable feature(doc_auto_cfg)
This removes duplicated manual feature gates for documentation
and leaves it to `cargo doc` to derive the same information from
the actual feature gates.

I didn't find any gaps in the auto-generated features and what we had
before, but now things like `rustls::cipher_suite::TLS_ECDHE_*`
are correctly marked tls12-only.
2023-08-08 14:30:50 +00:00
Jorge Aparicio 01a9c6cd7f directly use core:: & alloc:: API instead of std:: re-exports 2023-07-31 17:38:19 +00:00
Daniel McCarney 76de9080da crypto: introduce key exchange traits.
This commit adds a `KeyExchange` associated type to the `CryptoProvider`
trait. The `KeyExchange` type is constrained with its own `KeyExchange`
trait that has an associated type for the `SupportedGroup`.

In the `crypto::ring` package we adapt the existing *ring* specific
`KeyExchange` and `SupportedKxGroup` types to these new traits.

Throughout the codebase we tighten generic bounds where required to
ensure we have a `CryptoProvider` bound that allows accessing the
associated `KeyExchange` and `SupportedGroup`. We also make the
`CryptoProvider` an associated type on the `Side` config.
2023-07-18 17:47:43 +00:00
Daniel McCarney 5e51282681 kx: move Ring key exchange impl. to crypto::ring.
This commit moves the existing Ring-based key exchange mechanisms from
`rustls/src/kx.rs` to `rustls/src/crypto/ring.rs` in anticipation of
adapting the codebase to a more general keyex trait that these types
will implement.

No changes are made to the implementation except to update import paths
to reference the new location.
2023-07-18 17:47:43 +00:00
Dirkjan Ochtman e1860c91a8 crypto: parametrize config types with crypto provider 2023-07-18 17:47:43 +00:00
Dirkjan Ochtman 3a2c595d5d Import DnsName types directly 2023-06-22 14:08:33 +01:00
Joseph Birr-Pixton ae4ca3290b Cease relying on webpki crate for DNS name types
This introduces similar but simplified `DnsName` and
`DnsNameRef` types.

Fuzz the `client::ServerName` type that exposes this
surface.
2023-06-22 11:57:34 +01:00
Smaug123 792045ba68 Remove calls to PhantomData::default 2023-05-12 21:21:58 +01:00
Dirkjan Ochtman 8a2a87b240 client: use type + builder pattern for resumption config API
Originally developed in #1259.

Co-authored-by: Daniel McCarney <daniel@binaryparadox.net>
Co-authored-by: Jacob Hoffman-Andrews <github@hoffman-andrews.com>
2023-03-29 18:08:27 +01:00
Dirkjan Ochtman 39402e1564 client: replace enable_tickets option with tls12_resumption 2023-03-29 18:08:27 +01:00
Jacob Hoffman-Andrews 171a3431f7 document secret_extraction feature flag 2023-03-29 09:56:43 +02:00
Dirkjan Ochtman fc4e38ea22 quic: introduce separate QUIC ClientConnection and ServerConnection types 2023-03-21 21:44:30 +01:00
Dirkjan Ochtman 50e06cb7e7 Introduce ConnectionCore type to hold core state and behavior 2023-03-21 21:44:30 +01:00
Dirkjan Ochtman 787f43d12d Extract common_state module from conn 2023-03-21 21:44:30 +01:00
Dirkjan Ochtman fc1e364a93 quic: attach write_hs() to Quic 2023-03-21 21:44:30 +01:00