Commit Graph

2833 Commits

Author SHA1 Message Date
Jacob Hoffman-Andrews 303b3ff97d doc: add detail on UnexpectedEof
Add documentation at the top level, and link to that documentation in
the error message.
2023-11-30 18:20:36 +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 90b20a2567 docs: update README project membership
* Leadership -> membership.
* Clarify roles per member.
* List full-time members and funding source.
* Add Josh Aas, project management.
* Link to GitHub profiles.
2023-11-30 17:10:43 +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
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
Daniel McCarney d963be3c45 webpki: remove 'default' WebPkiServerVerifier helpers
These helpers assumed the *ring* crypto provider. Consumers can now use
the exported `verify_tls12_signature` and `verify_tls13_signature`
helpers with the crypto provider of their choice to implement these fns.
Similarly since `WebPkiSupportedAlgorithms` now exposes the
`supported_schemes` fn there's no need for the
`default_supported_verify_schemes` helper.
2023-11-30 15:12:14 +00:00
Daniel McCarney 44298191d7 lib: export webpki tls12/tls13 sig verify helpers under crypto
The `verify_tls12_signature` and `verify_tls13_signature` helpers from
the `webpki::verify` module can be useful when implementing a custom
client/server certificate verifier. This commit exports them under the
`crypto` mod alongside the `WebPkiSupportedAlgorithms` type they rely
on.
2023-11-30 15:12:14 +00:00
Daniel McCarney c5dfd62375 webpki: export WebPkiSupportedAlgorithms::supported_schemes
This small helper is useful in downstream code. The
`WebPkiSupportedAlgorithms` type is already public, and so are the
`SignatureScheme`s returned. Making this available saves downstream
code from having to re-implement this same iterate -> map -> collect.
2023-11-30 15:12:14 +00:00
Daniel McCarney c57a7342ec lib: consolidate crate::webpki re-exports in server 2023-11-30 15:12:14 +00:00
Daniel McCarney b0bcc9e06f webpki: add rustdoc for verify helpers
The old `verify_tls12_signature` referred to a `convert_algs` that
doesn't exist. Let's give more context to both the tls12 and tls13
signature verification fns and link to
`WebPkiSupportedAlgorithms::mapping` for more info.
2023-11-30 15:12:14 +00:00
Daniel McCarney 1b1c9f2ac6 webpki: in-line single use verify_sig_using_any_alg
This was only used by verify_tls12_signature, let's in-line that logic
since it will make it easier to document what the function does in one
place.
2023-11-30 15:12:14 +00:00
Daniel McCarney 656ad6d5d6 webpki: rename verify_signed_struct, verify_tls13
The crate-internal `verify_signed_struct` and `verify_tls13` helpers in
`webpki::verify` are only used from the context of
`{ClientCertVerifier|ServerCertVerifier}::{verify_tls12_signature|verify_tls13_signature}`
and
`WebPkiServerVerifier::{default_verify_tls12_signature|default_verify_tls13_signature}`.

This commit renames both helpers to match the name used in the
call-sites, making usage clearer.
2023-11-30 15:12:14 +00:00
Jacob Hoffman-Andrews 4736733f22 Reverse order of main vs PR 2023-11-30 15:03:11 +00:00
Joseph Birr-Pixton 0861d5fcd1 ci-bench: ignore-list aws-lc-rs RSA key validation 2023-11-30 15:03:11 +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
Jacob Hoffman-Andrews a2e43e2626 api: move TicketSwitcher to ticketer::Ticketer
The top level of the crate is meant for "paved path" exports.

In 0.21.x, there was a top-level `struct Ticketer`.

In current `main`, that's been moved to the separate crypto providers.
Additionally, there is a new public type `TicketSwitcher`. This type
should probably not be at the top level.
2023-11-30 09:27:10 +00:00
Jacob Hoffman-Andrews 3e74257be5 RootCertStore: better Debug impl
The derive(Debug) impl was printing the subject and subjectpublickeyinfo
for every single trust anchor in the root store, which made it very
difficult to read other Debug output that happened to contain a
RootCertStore.

For instance this made the Debug output for ClientConfig extremely long,
because ClientConfig often contains a WebPkiServerVerifier, which
contains a RootCertStore.

In the custom Debug impl, abbreviate the list of roots to simply say how
many of them there are.

Users who want to specifically print the contents of the root cert store
can call `subjects()` and print the output of that.
2023-11-29 22:03:36 +00:00
Daniel McCarney 74bd185f6e Cargo: 0.22.0-alpha.5 -> 0.22.0-alpha.6 2023-11-29 21:41:52 +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 af80fa35f6 Update semver-compatible dependencies 2023-11-27 14:45:32 +00:00
Jan Rüth 0c03f660ac Issue-1632: Ensure SharedSecret::secret_bytes is publicly accessible
When implementing a `CryptoProvider` external to this crate, one needs to be able to access the underlying `secret_bytes` after a key exchange when performing the TLS 1.2 PRF.

This change ensures that the bytes can be safely accessed.
2023-11-27 10:52:35 +00:00
Jorge Aparicio e8bd45cff9 CI: deny warnings when checking feature powerset 2023-11-24 15:14:19 +00:00
Jorge Aparicio 8188a5b291 fix warnings in -default +ring build 2023-11-24 15:14:19 +00:00
Dirkjan Ochtman a6233dcc46 Bump rustls version to alpha.5 2023-11-24 14:38:07 +00:00
Dirkjan Ochtman 72b365074f Sort dev-dependencies 2023-11-24 14:38:07 +00:00
Dirkjan Ochtman 26ec868b8c Migrate to pki-types ServerName 2023-11-23 21:57:10 +00:00
Dirkjan Ochtman ab5e2a917b Upgrade to latest rustls-pemfile 2023-11-23 21:57:10 +00:00
Dirkjan Ochtman 93086c04a1 Inline single-use helper method 2023-11-23 21:57:10 +00:00
Adolfo Ochagavía c06979e2a8 ci-bench: remove unnecessary `black_box`
The usage of black box was originally introduced to to ensure the optimizer didn't take advantage of
knowing both the client and the server side of the configuration. However, in this case, the server
and the client run in different processes, so each side of the connection has no compile-time
information about the other side.
2023-11-23 17:09:09 +00:00
Adolfo Ochagavía c514132367 ci-bench: replace magic number with constant 2023-11-23 17:09:09 +00:00
Adolfo Ochagavía 34c6e205b6 ci-bench: simplify clap command 2023-11-23 17:09:09 +00:00
Adolfo Ochagavía 06f3dcf28c ci-bench: transfer more bytes to reduce noise 2023-11-23 17:09:09 +00:00
Adolfo Ochagavía c005236270 ci-bench: add wall-time mode 2023-11-23 17:09:09 +00:00
Adolfo Ochagavía 2463f99155 ci-bench: rewrite benchmarks in async style
This is a necessary step towards sharing code between icount and
wall-time benchmarks
2023-11-23 17:09:09 +00:00
Jacob Hoffman-Andrews a72f6697e5 doc: CryptoProvider defaults can be overridden
It was surprising to me that builder_with_provider could set a
CryptoProvider, and then with_cipher_suites could choose implementations
from a different CryptoProvider. I've tried to document things to make
that a little less surprising.
2023-11-23 15:23:14 +00:00
Daniel McCarney de41c70959 CONTRIBUTING: add note about fully qualified function calls 2023-11-23 14:36:00 +00:00
Daniel McCarney e9316dfcd4 crypto: make signer mod pub(crate)
Historically the types that now live in `rustls::crypto::signer` were
present in `rustls::sign`. When the crypto provider work refactored them
into their new home, we also added a `lib.rs` re-export under
`rustls::sign`. This left two import paths for accessing the same types.

To avoid duplicated import paths without causing more downstream
churn from moving the types this commit makes the
`rustls::crypto::signer` module `pub(crate)`, leaving `rustls::sign` as
the sole way to access the contained types externally.
2023-11-23 08:28:49 +00:00
Daniel McCarney 81f828f976 client: allow providing webpki cert verifier w/o dangerous
Previously to supply a custom webpki-based server certificate verifier
when building a client configuration the caller had to invoke
`dangerous` to get access to a fn that can accept an `Arc<dyn
verify::ServerCertVerifier>`. We did this because implementing
a `ServerCertVerifier` from scratch leaves a lot of room for dangerous
errors.

However, when providing a `WebPkiServerVerifier` constructed with
`webpki::WebPkiServerVerifier::builder`, there is much less danger.
We've arranged the builder and concrete type to be safe for general
usage.

This commit changes the builder to return the concrete verifier type,
and then adds a new `with_webpki_verifier` fn to the client config
builder that accepts a `Arc<WebPkiServerVerifier` without needing to go
through `dangerous`. This will make the standard case of customizing the
built-in webpki verifier not appear dangerous, while still requiring
fully customized verifiers be provided through the dangerous API.
2023-11-22 20:01:47 +00:00
Dirkjan Ochtman e3edaef807 Rename SignError to InvalidKeyError 2023-11-22 15:22:12 +00:00
Jorge Aparicio a54c8ecbe3 CI: run clippy on the entire workspace 2023-11-22 15:06:37 +00:00
Jorge Aparicio 0c556c03ab fix clippy warnings in ci-bench 2023-11-22 15:06:37 +00:00
Jorge Aparicio 65ade3c440 turn CertificatePayload type alias into a newtype 2023-11-22 14:20:39 +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
Jacob Hoffman-Andrews 96d1691b35 doc: update docs for SigningKey
Explain why the implementors section for SigningKey is empty, where
SigningKey comes from, and what it is consumed by.

Update the functions that document encodings for loading private keys so
they are more specific and concrete.
2023-11-22 14:07:54 +00:00
Joseph Birr-Pixton 1db4506dcf Update front page docs for crypto providers 2023-11-21 19:15:40 +00:00