Commit Graph

85 Commits

Author SHA1 Message Date
Joseph Birr-Pixton 327444fdb8 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.
2023-12-07 13:45:27 +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
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
Joseph Birr-Pixton e3925b18e6 Use `BorrowedCursor` & `BorrowedBuf` from core::io 2023-11-10 16:11:42 +00:00
Daniel McCarney 66524008a7 server: derive Debug for ServerConfig
All of the `ServerConfig` fields are now `Debug` friendly, so we can
drop the custom impl and derive `Debug`.
2023-11-09 18:26:12 +00:00
Daniel McCarney 7f8a332a23 server: add Debug bound to StoresServerSessions
This commit adds a `Debug` bound to the `StoresServerSessions` trait in
addition to `Send` and `Sync`. 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 7a3542f9a2 server: add Debug bound to ResolvesServerCert
This commit adds a `Debug` bound to the `ResolvesServerCert` trait in
addition to `Send` and `Sync`. 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 70c93d16f0 ticketer: add Debug bound to ProducesTickets
This commit adds a `Debug` bound to the `ProducesTickets` trait in
addition to `Send` and `Sync`. 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
Joseph Birr-Pixton 48d78f7232 Improve docs around `{Server,Client}Config::builder` 2023-11-09 16:18:11 +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
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 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 e3c3ed5c8f More consistently use modules for unit tests 2023-09-14 13:22:08 +00:00
Joseph Birr-Pixton b145054882 Make *ring* an optional dependency
Using the crate without this feature means something external
needs to provide all the cryptography, and (eg) convenient integrated
key loading APIs disappear.
2023-09-13 15:32:29 +00:00
Jacob Hoffman-Andrews 3087811ec7 doc: link ResolvesServerCert to Acceptor
Previously, looking at ResolvesServerCert, it was not clear that there
was an async version available.
2023-09-07 13:17:13 +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
Daniel McCarney 8778b7a324 server: fix acceptor rustdoc typo. 2023-08-16 16:30:06 +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
Dirkjan Ochtman 56cbc89df0 Fix up nightly clippy issue with incorrect comment 2023-08-02 08:21:42 +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
Daniel McCarney 17a7e17534 crypto: separate module dir, ring sub-module.
For better code organization this commit moves the generic crypto
interface code from `src/crypto.rs` to `src/crypto/lib.rs`.

The *ring* specific code implementing the generic interfaces is moved to
`src/crypto/ring.rs` as a sub-module of `crypto. All imports are
adjusted accordingly.

This has the advantage of leaving `src/crypto/lib.rs` small, and without
any *ring* specific imports. In the future we may choose to feature-gate
the ring sub-module to allow building the crate without a dependency on
ring.
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
Jacob Hoffman-Andrews 171a3431f7 document secret_extraction feature flag 2023-03-29 09:56:43 +02:00
Dirkjan Ochtman 169f14f757 Create a newtype wrapper for ProtocolName 2023-03-24 21:30:09 +01:00
Jacob Hoffman-Andrews 2b3b797e69 Acceptor: remove deprecated methods and add docs 2023-03-23 16:03:26 -07:00
Daniel McCarney d9f38ede62 quic: add server_name to ServerConnection.
After splitting up the quic server connection types consumers lost the
ability to dig out the server name from the SNI extension the server
received. This commit adds the `server_name` function to
`quic::ServerConnection` to restore that ability.
2023-03-22 15:14:54 +01:00
Daniel McCarney 9b8fa405cd server: rename sni_hostname -> server_name.
The documentation retains mention of "server name indication" (SNI) for
folks that search the documentation with that more specific technical
term. For users not steeped in the deeper lore of TLS the new name
will be easier to find/understand.
2023-03-22 15:14:54 +01: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
Jacob Hoffman-Andrews a44d1669fd Move internal enums to public API
These enums (AlertDescription, ContentType, and HandshakeType) were
previously only available as part of the private API.  Eight months ago
we added a public reexport of their names, but did not remove the
private version to avoid semver breakage.

Now that we have a semver-incompatible version coming up we can move
these fully to the public API.
2023-03-21 19:45:18 +00:00
Joseph Birr-Pixton d780790329 Allow configuring how many TLS1.3 tickets servers send
This changes the default from 1 to 4 tickets.
2023-01-24 13:53:34 +00:00
Brian Smith 6dfa67809d Replace `doc(hidden)` with `pub(crate)` where those semantics are intended.
I think these uses of `doc(hidden)` are trying to implement `pub(crate)`
semantics. Perhaps it was done this way a long time ago when `pub(crate)`
wasn't a think.

This change causes an `unreachable_pub` warning for `PlaintextSink`, so
make that `pub(crate)` too.

Some external users might be using these even though they probably shouldn't
be, so this is technically a breaking change.
2023-01-16 10:32:14 +01:00
Jacob Rothstein b177e4cac2
move doc(cfg(feature = …)) to original definitions (#1156) 2023-01-11 16:26:46 -08:00
Brian Smith 6da1d8d711 Server: Change `Acceptor` to only allow one attempt per ClientHello.
When we encounter an error processing the client hello, don't try again.
Trying again generally won't do any good. This matches `Future::poll`
semantics (Futures shouldn't be polled after yielding `Ready`).
2022-12-22 11:49:27 +01:00
amos a981f0914e
extract_secrets feature for kTLS support (owned) (#1112) 2022-10-15 13:53:08 +02:00
Xuanwo bc85a0145a feat: impl Debug for all public structs
Signed-off-by: Xuanwo <github@xuanwo.io>
2022-10-14 15:44:09 +02:00
Josh Aas 217ef36c66
Fix code depending on updated ReadBuf API (#1098) 2022-09-02 06:40:51 +02:00