Commit Graph

2221 Commits

Author SHA1 Message Date
Joseph Birr-Pixton 2658d88a99 Make `SignatureScheme` enum names closer to IANA
Having our naming close to the standard makes things a bit clearer.

- ECDSA_SHA1_Legacy -> ECDSA_SHA1.
- RSA_PSS_SHA* -> RSA_PSS_RSAE_*.
- add RSA_PSS_PSS_* enums (not implemented on our side, but could be).
- ECDSA_NISTP* -> ECDSA_SECP*.
- complete supported_in_tls13(), in case these are encountered via
  pluggable crypto.

This is a breaking API change.
2023-08-04 16:27:44 +01:00
Joseph Birr-Pixton 03e88637e5 Separate-out webpki callers into specific module
The goal of this is to make it clear which parts
of the crate are specific to webpki, and which are intended
to be generic.  Eventually, this gives a route to making
the `webpki` dependency optional, putting this module
(and callers of it) behind the `webpki` feature.
2023-08-04 14:48:10 +00:00
Joseph Birr-Pixton 2f724e5ed7 Reuse `verify_server_name` for checking SNI mappings 2023-08-04 14:48:10 +00:00
Joseph Birr-Pixton 764da8a0a4 Regularise CertifiedKey::end_entity_cert error
This isn't really a error "while signing", so `SignError` isn't a good match.
2023-08-04 14:48:10 +00:00
Joseph Birr-Pixton f63c53355f verify: move construct_tls13_client_verify_message et al to tls13 2023-08-04 14:48:10 +00:00
Joseph Birr-Pixton e9c15abe06 Remove default certificate verifier trait functions
This is a breaking change.

These introduced an implicit dependency on the `webpki` crate
for anyone who wanted to implement these traits.

Instead, someone who wants to benefit from the `webpki`-backed
implementations should dispatch to `WebPkiServerVerifier` themselves.

Expose these defaults explicitly, and dispatch to them in our
various bits of example and test code.
2023-08-04 14:48:10 +00:00
Joseph Birr-Pixton 77ad069312 Refactor sign::supported_sign_tls13
This returned a slice of signature schemes allowed in TLS1.3.
But all callers actually needed something that would fit in
`Iterator::filter` so had to linear scan it.

Instead, move into a function on `SignatureScheme` (it's a fact about
that standard) and make it directly usable with `Iterator::filter`.
2023-08-04 14:48:10 +00:00
Joseph Birr-Pixton d7755d54c1 examples: remove unused sct dependency 2023-08-04 14:48:10 +00:00
Daniel McCarney 460934b1b0 verify: take Arc<RootCertStore>.
As pointed out by Jsha, an implementation of the `Acceptor` API may want
to create a verifier on something approaching a per-handshake basis in
order to provide up-to-date CRLs and client trust anchors.

We can improve on the cost of this operation by allowing shared use of
a `RootCertStore` across verifiers by wrapping it in an `Arc`.

This commit updates the `WebPkiClientVerifier`, and
`ClientCertVerifierBuilder` to take a `Arc<RootCertStore>` instead of
`RootCertStore`.

One side-effect of this change is the removal of the `add_roots` fn of
the `ClientCertVerifierBuilder` - once we take an `Arc` we can't modify
the backing `RootCertStore` without introducing some form of locking.
I think the use-case for adding additional `RootCertStore`'s after
constructing the builder is weak enough that we should drop that feature
rather than introduce locking.
2023-08-03 14:19:13 +00:00
Daniel McCarney e07323541d verify: WebPkiVerifier -> WebPkiServerVerifier.
In previous commits we reworked the primary implementation of the
`ClientCertVerifier` trait to be named `WebPkiClientVerifier`.

This commit updates the corresponding `ServerCertVerifier`
implementation in `WebPkiVerifier` to be named `WebPkiServerVerifier` to
match the client naming scheme and to better emphasize its role.
2023-08-03 14:19:13 +00:00
Daniel McCarney 697846460d anchors: add_server_trust_anchors -> add_trust_anchors
The `RootCertStore` type is used for both client and server trust
anchors. This commit renames the `add_server_trust_anchors` method to be
`add_trust_anchors` to reflect its general purpose.
2023-08-03 14:19:13 +00:00
Daniel McCarney 2d6eeec40e verifier: use builder API for client verifier.
Previously users configuring a `ServerConfig` that wanted to use
a webpki backed client certificate verifier had to make a choice of
which concrete implementation to construct, and how to configure it
(e.g. with trust anchors and CRLs). This made for a somewhat cumbersome
experience.

In its place, this commit:

* Adds a `WebPkiClientVerifier` type that replace both the
  `AllowAnyAuthenticatedClient` and `AllowAnyAnonymousOrAuthenticatedClient`
  verifiers. The name emphasizes that the implementation is backed by
  `rustls/webpki` to help distinguish it from platform verifiers.

  The new type can only be constructed external to the crate using
  a `ClientCertVerifierBuilder` builder that walks the user through
  specifying roots, CRLs, and policy for anonymous clients.

* Turns the `NoClientAuth` verifier into a crate internal type that also
  only be constructed via the `ClientCertVerifierBuilder`.

* Removes the `boxed()` fn's of the above, since they won't be needed
  anymore - consumers will construct a `Arc<dyn ClientCertVerifier>`
  through the builder and don't need to have `ClientCertVerifier`
  in-scope via the dangerous config feature.

* Updates all existing usages in tests and examples to use the new
  builder API.
2023-08-03 14:19:13 +00:00
Joseph Birr-Pixton cf1f8b1422 Move to using prerelease rustls-webpki 0.102.0-alpha.0
This is intended to just maintain the status-quo, not take
advantage of the new features in this release.
2023-08-03 10:18:51 +00:00
Dirkjan Ochtman 56cbc89df0 Fix up nightly clippy issue with incorrect comment 2023-08-02 08:21:42 +00:00
Tshepang Mbambo 79de94221f
readme: add some readability pauses (#1380)
See https://github.com/rustls/rustls/pull/1380#issuecomment-1660649621
2023-08-02 09:45:37 +02:00
Daniel McCarney 1776e0ba3b msgs: make TlsListElement/ListLength pub(crate).
This commit resolves two TODO's left in `msgs/codec.rs` about using
`pub(crate)` visibility for `TlsListElement` and `ListLength` once MSRV
allows it. That time has come :)
2023-08-01 15:50:05 +00:00
Jorge Aparicio d4535756cf enable clippy lints to prevent future uses of re-exported std API 2023-07-31 17:38:19 +00:00
Jorge Aparicio 01a9c6cd7f directly use core:: & alloc:: API instead of std:: re-exports 2023-07-31 17:38:19 +00:00
Joseph Birr-Pixton 54a7771d90 Check usage/intro docs in README.md are in sync 2023-07-28 12:57:17 +00:00
Daniel McCarney 763a17ef5f ci: fix setup-go build cache warnings.
Since v4 of the `actions/setup-go` action, caching is enabled by default
and when a `go.sum` can't be found in the root of the project, a warning
is logged.

Since we don't have a `go.sum` in the project root, this warning was
being issued by both tasks that used the `setup-go` action:

* The BoGo test suite task
* The code coverage task

For the first of these, caching is disabled to avoid the warning - we
weren't benefiting from this to begin with and setting
`cache-dependency-path` to `bogo/bogo/go.sum` or `bogo/go.sum` wasn't
working.

For the second of these, it's not clear _why_ we were installing the Go
toolchain. The BoGo test suite is not being run by this task and so Go
is not required. Removing it fixes the warning.
2023-07-28 12:04:26 +00:00
Joseph Birr-Pixton ad62b2cf4a Update example usage in README.md
(with admin/pull-usage)
2023-07-27 08:34:49 +00:00
dependabot[bot] 29a207be86 build(deps): update webpki-roots requirement from 0.24 to 0.25
.. and then fix build for webpki-roots 0.25.x.
2023-07-27 08:34:49 +00:00
Joseph Birr-Pixton cc19eabc25 client: detect HRR with incorrect session_id
See comment for justification from RFC.
2023-07-26 15:32:14 +00:00
Joseph Birr-Pixton b2ba1a2a71 Require new webpki and use its new APIs 2023-07-26 15:32:14 +00:00
Joseph Birr-Pixton 41769b4801 Regression test for echoing session id in HRR 2023-07-26 15:32:14 +00:00
Joseph Birr-Pixton aa30870f15 server: echo client's session_id in HRR 2023-07-26 15:32:14 +00:00
Dirkjan Ochtman 304116b476 crypto: fix typo in docstring 2023-07-24 13:15:27 +00:00
Joseph Birr-Pixton 3d121b9d62 tls13: refactor choosing of first kx group 2023-07-18 17:47:43 +00:00
Joseph Birr-Pixton 83be0aa348 Refactor crypto::KeyExchange to simplify
This replaces the one use of `start()` (in TLS1.2 server) with
`choose()`, and then calls the result `start()` which I think is
slightly clearer.
2023-07-18 17:47:43 +00:00
Joseph Birr-Pixton 3d5c93aa0b Remove ticketer from CryptoProvider
Instead, the ring-based `rustls::Ticketer` is exported directly,
as is the `TicketSwitcher` which is a useful building block for
downstream users.
2023-07-18 17:47:43 +00:00
Joseph Birr-Pixton 7d6a84ba0c Use subtle::ConstantTimeEq instead of ring::constant_time 2023-07-18 17:47:43 +00:00
Daniel McCarney 74fa57c9c8 ring: match KeyExchange impl block to trait.
The `KeyExchange` trait's methods were ordered constructors -> complex
functions -> less complex functions. The original *ring* specific
`KeyExchange` didn't match this ordering. This commit synchronizes the
two.
2023-07-18 17:47:43 +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 0e52a9b2c1 crypto: add SupportedGroup trait.
This commit adds a trait for referring to supported key exchanges over
named groups in a general fashion. The *ring* specific
`SupportedKxGroup` type is then made to implement this trait.
2023-07-18 17:47:43 +00:00
Daniel McCarney 9c945eadb9 lib: move `kx_group` module to crypto/ring. 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 2279faa124 kx: lift `KeyExchangeError` into `crypto`
The `KeyExchangeError` type is generic enough to live in the `crypto`
module. This will allow it to be shared with non-ring implementations in
the future.
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
Daniel McCarney d60df2c368 kx: rename fields for readability/convention.
Following up on the previous commit, this commit updates the
`KeyExchange` struct's private `skxg`, `pubkey` and `privkey` fields to
be named `group`, `pub_key` and `priv_key`. This better matches the Rust
naming convention for struct members and makes for easier to understand
code.
2023-07-18 17:47:43 +00:00
Daniel McCarney ec3c8b5294 kx: replace pubkey field w/ pub_key() accessor.
The only consumers of the `pub(crate)` visible `pubkey` field of the
`KeyExchange` struct were using it to get at a `&[u8]` of public key
bytes.

This commit:

1. Unexports the `pubkey` field of the `KeyExchange` struct.
2. Adds a `pub(crate)` visible `pub_key()` method to return the public
   key as a `&[u8]`.
3. Adjusts the tls12 client `emit_clientkx` function to use `&[u8]` for
   its pub key argument.
4. Adjusts all callers to use the new `pub_key` accessor in place of the
   field.

The name is changed from `pubkey` to `pub_key` to match Rust naming
conventions[0].

[0]: https://rust-lang.github.io/api-guidelines/naming.html
2023-07-18 17:47:43 +00:00
Dirkjan Ochtman fbc81b5f46 kx: let KeyExchange::choose() instantiate directly 2023-07-18 17:47:43 +00:00
Dirkjan Ochtman 6814ce32ac crypto: use crypto provider to produce ticketer 2023-07-18 17:47:43 +00:00
Dirkjan Ochtman d470cc45fa crypto: use crypto provider for random bytes 2023-07-18 17:47:43 +00:00
Dirkjan Ochtman ef573bcd18 crypto: redefine single DER constant 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
Joseph Birr-Pixton 1d07dd5dde Correct/allow unnecessarily &mut function args
allow unknown-lints on stable clippy, otherwise it warns about us
allowing lints that were introduced on nightly.
2023-07-18 16:01:32 +00:00
Daniel McCarney fd5f9df24a docs: update RELEASING w/ maintenance release steps.
This commit adds some short guidance on performing maintenance point
releases when `main` has breaking changes, preventing using the normal
release process.
2023-07-17 19:31:52 +00:00
Joseph Birr-Pixton bf09a07845 Remove MSRV variant of connect-tests
MSRV is important (an tested separately) for the core crate
(and its dependencies) but doesn't apply to test code.

Run these daily to notice any breakage earlier.
2023-07-13 14:52:39 +00:00
Joseph Birr-Pixton 9939793a7e client::builder: fix PhantomData clippy lint 2023-07-13 14:40:48 +00:00
Daniel McCarney 478a895cf0 ci: add a cargo-semver-checks action.
This commit updates the `build.yml` GitHub actions workflow to
additionally include a step that checks semver compatibility w/
cargo-semver-checks[0].

Notably this check passing is necessary but not sufficient for knowing
that we're maintaining semver: if this tool produces a finding we know
we aren't matching semver, but if it doesn't, we may still be breaking
semver in a way the tool can't detect.

[0]: https://github.com/obi1kenobi/cargo-semver-checks
2023-07-11 16:14:26 +00:00