Commit Graph

37 Commits

Author SHA1 Message Date
Jacob Hoffman-Andrews 87d5259126 update examples to use pki_types re-export
We now re-export the rustls-pki-types crate. I think that means
our preferred way for crates to consume pki-types is through the
re-exports.
2023-12-08 13:54:32 +00:00
Joseph Birr-Pixton 381dcf99ee Update dependencies 2023-12-01 19:10:46 +00:00
Jacob Hoffman-Andrews 58c2d26ed0 api: move CipherSuiteCommon into crypto
The top level of the crate is meant for "paved path" exports.

In 0.21.x, this type was in `cipher_suites`, along with a few other
types that got moved to specific crypto providers. Moving this to
`crypto` instead of re-exporting under its old name in `cipher_suites`
seems acceptable, because it will mainly be used in implementing crypto
providers. Also, its internals have changed significantly so there is
already churn for this type.
2023-11-30 17:44:07 +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
Daniel McCarney b4971785fd crypto: CryptoProvider is-a KeyProvider -> has-a
In preparation for moving to a struct based model where
a `CryptoProvider` has a `&'static dyn KeyProvider` field, this commit
splits the `KeyProvider` trait from the `CryptoProvider` trait. In its
place `CryptoProvider` gets a `key_provider(&self)` fn that acts as
a stand-in for what will be a field in the struct based approach.
2023-11-30 15:53:39 +00:00
Daniel McCarney 2b791938bb crypto: split out KeyProvider trait
We're working towards making `CryptoProvider` a struct holding distinct
elements to be used for cryptography. To support this the
`load_private_key` fn needs to be lifted to a new trait, `KeyProvider`.
We can hold a `&dyn KeyProvider` in the to-be-added struct to invoke
as required for `load_private_key`.

This commit adds the new trait, includes `KeyProvider` in the existing
`CryptoProvider` trait bounds, and updates the *ring*, aws-lc-rs, and
provider example crypto providers to implement `KeyProvider`.
2023-11-30 15:53:39 +00:00
Daniel McCarney 3b5cf17ade crypto: CryptoProvider is-a SecureRandom -> has-a
In preparation for moving to a struct based model where
a `CryptoProvider` has a `&'static dyn SecureRandom` field, this commit
splits the `SecureRandom` trait from the `CryptoProvider` trait. In its
place `CryptoProvider` gets a `secure_random(&self)` fn that acts as
a stand-in for what will be a field in the struct based approach.
2023-11-30 15:53:39 +00:00
Daniel McCarney 53ed597fa1 crypto: split out SecureRandom trait
We're working towards making `CryptoProvider` a struct holding distinct
elements to be used for cryptography. To support this the `fill_random`
fn needs to be lifted to a new trait, `SecureRandom`. We can hold
a `&dyn SecureRandom` in the to-be-added struct to invoke as required
for `fill_random`. Since the trait now provides additional context, the
fn is renamed from `fill_random` to `fill`.

This commit adds the new trait, includes `SecureRandom` in the existing
`CryptoProvider` trait bounds, and updates the *ring*, aws-lc-rs, and
provider example crypto providers to implement `SecureRandom`.
2023-11-30 15:53:39 +00:00
Jacob Hoffman-Andrews d931562cf3 api: move WebPkiSupportedAlgorithms to crypto
The top level of the crate is meant for "paved path" exports.

This newly exported type is used for cryptographic provider
customization, so it properly belongs in the `crypto` module.
2023-11-30 14:29:53 +00:00
Daniel McCarney aef3381dea update rustls-webpki to alpha.8, pki-types to 2.2.3
Requires accommodating the new `Debug` bound requirement in the provider
example, and fixing some expected output in a webpki verify test.
2023-11-29 21:41:52 +00:00
Daniel McCarney 078f03334b provider-example: use Error::Other
Previously we had to use `Error::General` when translating
error instances from the hpke-rs dependencies of the provider-example
into `rustls::error::Error` instances, because one of the upstream error
types didn't implement `StdError`.

This commit updates the hpke-rs dependency, bringing in a fix for this
and allowing usage of the more appropriate `Error::GeneralError` error
type.
2023-11-27 16:32:07 +00:00
Dirkjan Ochtman 26ec868b8c Migrate to pki-types ServerName 2023-11-23 21:57:10 +00:00
Jacob Hoffman-Andrews db64448ddd Doc: replace "nb." with "Note:"
"nota bene" (mark well) is jargon that we don't need.
2023-11-22 14:14:37 +00:00
Joseph Birr-Pixton f0a6ec1110 Make receiver of `cipher::Message{En,De}crypter` mutable
This is necessary if implementations want to keep state between calls --
(eg, *ring*'s `aead::OpeningKey`).  The next commit takes advantage
of this.
2023-11-21 09:58:03 +00:00
Joseph Birr-Pixton fdd1f8dd4f Move key usage limits up into `CipherSuiteCommon` 2023-11-17 19:27:21 +00:00
Joseph Birr-Pixton cfec92ce70 Make Tls13CipherSuite::quic optional and public
The goal is to make it possible for provider-example to exist
without implementing (eg) QUIC header protection.

This introduces some knock-on requirements for other types/functions
to be the public, so `quic::Algorithm` can be implemented outside
the crate.
2023-11-17 19:27:21 +00:00
Steve Fan e5a4f13741 add server example for example provider 2023-11-17 17:26:43 +00:00
Joseph Birr-Pixton e3e1d8352b provider-example: normalise import order/grouping 2023-11-17 17:26:43 +00:00
Daniel McCarney b7a6091ab4 provider-example: HPKE provider w/ hpke-rs & rust-crypto
This commit implements the Rustls HPKE provider traits using hpke-rs[0]
with the rust-crypto backend.

Since HPKE is not yet used in Rustls (but will be for ECH support),
a unit test based on the RFC 9180 test vectors is added.

Likely in the future we will want to move this test somewhere outside of
the provider-example crate and use it to test a *ring* HPKE
implementation using the same test vector data.

[0]: https://github.com/franziskuskiefer/hpke-rs
2023-11-16 19:32:49 +00:00
Christian Poveda 63ddf03a7c add `encrypted_payload_len` to `MessageEncrypter` 2023-11-16 19:15:54 +00:00
Joseph Birr-Pixton c6c792b616 Delegate choosing webpki algorithms to `CryptoProvider`
This drastically simplifies `provider-example`.  But the
primary goal is ensuring a client configured `with_provider(AWS_LC_RS)`
only uses algorithms from aws-lc-rs, irrespective of crate features.
2023-11-09 16:18:11 +00:00
Joseph Birr-Pixton 3897bceeca Delegate private key loading to `CryptoProvider` 2023-11-09 16:18:11 +00:00
Joseph Birr-Pixton 0e296980fd Move `rustls::cipher_suite` members into provider module
Naming cipher suites individually seems like a "detail" feature, and
therefore having to name the provider too is not a large imposition.

Naturally this is a breaking change.
2023-11-09 16:18:11 +00:00
Yuxiang Cao 3355e06f97 refactor: more general error in SupportedKxGroup
Use `Error` instead of `GetRandomFailed` in trait `SupportedKxGroup`,
so that underlying crypto provider could throw errors other than RNG
related errors.
2023-11-07 00:53:49 +00:00
Joseph Birr-Pixton 6df2dd8f62 Bolt hmac_sign onto `Hkdf` trait
This means `Hkdf` covers the entire use of TLS1.3
for HMAC/HKDF, and that avoids having to implement
the HMAC traits just for this.
2023-10-26 11:12:05 +00:00
Joseph Birr-Pixton 636b772c39 Put HKDF use behind trait
Have an impl of this for hmac::Hmac
2023-10-26 11:12:05 +00:00
Joseph Birr-Pixton d5923030d6 Put TLS1.2 PRF implementation behind a trait
This replaces the HMAC trait in Tls12CipherSuite
(there were no other uses of HMAC).

Provide an implementation of the new PRF trait in terms of
HMAC, for convenience of providers that have a HMAC (common)
but not a separate TLS1.2 PRF (relatively uncommon).  The
*ring* and `provider-example/` providers use this.
2023-10-26 11:12:05 +00:00
Daniel McCarney 056ba78748 webpki: builder for server cert verifier, CRL support
This commit reworks the `WebPkiServerCertVerifier` type to use
a builder model similar to the `WebPkiClientCertVerifier` type. The new
`ServerCertVerifierBuilder` additionally exposes support for configuring
the depth of revocation status checking, and how to handle unknown
revocation status.
2023-10-25 14:12:46 +00:00
Dirkjan Ochtman 9f9f5f1c34 Drop rust-version metadata for internal crates 2023-10-04 14:17:18 +00:00
Daniel McCarney 55bb27953d suites: rework `ConnectionTrafficSecrets`
This commit updates `ConnectionTrafficSecrets` to hold `AeadKey` and
`Iv` instances, instead of byte arrays, removing the need for the
`slices_to_arrays` and `slice_to_array` helpers.
2023-09-28 12:57:59 +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
Daniel McCarney b1bde8c0e7 lib: remove crypto::SupportedKxGroup re-export 2023-09-19 13:39:44 +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 ee33acfcd0 Tweak formatting for provider-example Cargo manifest 2023-09-14 13:22:08 +00:00
Joseph Birr-Pixton a1950e84cf Add demonstration of custom crypto
This is an example that builds a mostly-unchanged rustls example
(simpleclient), but only using crypto from the rust-crypto project
and elsewhere.

This is intended to be minimalistic, and not a complete replacement
for *ring*.

It implements:

- TLS1.3 TLS13_CHACHA20_POLY1305_SHA256 cipher suite.
- TLS1.2 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 cipher suite.
- X25519 key exchange.
- RSA-PSS-SHA256 and RSA-PKCS1-SHA256 signature verification for
  verifying the server, integrated into the webpki crate.
- random generation using `rand_core`.

This means it can fetch www.rust-lang.org.

TLS1.2 is not strictly necessary for this server, but serves to
demonstrate that part of the API.
2023-09-13 15:32:29 +00:00