Commit Graph

253 Commits

Author SHA1 Message Date
Sean McGrail d805e1fdfd Add 'fips' Cargo feature
Add `rustls::crypto::default_fips_provider()` behind this
feature.
2024-01-16 11:31:02 +00:00
Joseph Birr-Pixton e1149286ff 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.
2024-01-16 11:31:02 +00:00
Goncalo Gomes c296594db3 Randomize ClientHello extensions
Google Chrome project proposes Client Hello extensions should be
randomized in order to prevent fingerprinting [1]

This commit sorts all the extensions that have been sent in the same
order as before by using a seed that is saved at the start of the
connection. And keeps the PSK extension in the end.

[1] https://chromestatus.com/feature/5124606246518784

resolves #1313

Co-authored-by: Joseph Birr-Pixton <jpixton@gmail.com>
2024-01-12 16:45:17 +00:00
Daniel McCarney 2d7a39c102 msgs: HelloRetryRequest::get_requested_key_share_group -> requested_key_share_group 2024-01-05 14:21:50 +00:00
Daniel McCarney 3345415e52 msgs: ClientHelloPayload::get_keyshare_extension -> keyshare_extension 2024-01-05 14:21:50 +00:00
Daniel McCarney 349f531af3 msgs: ClientHelloPayload::get_sigalgs_extension -> sigalgs_extension 2024-01-05 14:21:50 +00:00
Joseph Birr-Pixton b1101a8737 De-duplicate knowledge of test-ca/ CA names 2024-01-04 09:21:59 +00:00
Joseph Birr-Pixton 6ede5d74f4 Avoid extraenous `.iter()` in for loops
clippy was complaining about manual `.into_iter()` calls, but actually
the manual `.iter()` calls are also not very idiomatic.
2024-01-04 09:21:59 +00:00
Joseph Birr-Pixton 271c637bd9 Split test-ca ecdsa by curve; add p521
This goes from being a single set of keys for ECDSA (with a
purposeful mix of curves) to a set of keys per curve.

That means we can avoid P521 chains in tests when it is not supported.

In those tests, reflect this as additional `KeyType` variants.
2024-01-04 09:21:59 +00:00
Joseph Birr-Pixton 1980ba6d16 aws-lc-rs: support verifying with ECDSA_P521_SHA512 2024-01-04 09:21:59 +00:00
Geoffroy Couprie 6ff948efba remove the TLS 1.2 session ticket on DecryptError
if for some reason the recorded session ticket is invalid or decoded
incorrectly by the server, we can get into a case where the resumption
handshake happens, and right after the ChangeCipherSpec message, the
server sends an encrypted handhsake message using the invalid ticket,
and the client rejects it with the BadRecordMAC alert.
Unfortunately, if the calling code retries the connection, if it will
try again with the same ticket and obtain the same result.
This commit makes sure that if we fail to decrypt the first message, we
will remove the session ticket for this server, to start from cratch on
the next connection.
2023-12-06 15:36:57 +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
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
Dirkjan Ochtman 26ec868b8c Migrate to pki-types ServerName 2023-11-23 21:57:10 +00:00
Joseph Birr-Pixton c1e34d1c81 Outlaw and test `export_keying_material` with empty output
This is not useful.
2023-11-21 09:58:03 +00:00
Dirkjan Ochtman 9169e71552 quic: remove limits from PacketKey interface
Since these are now unconditionally available on the Tls13CipherSuite,
there doesn't seem to be much point in keeping this API (which appears
be unused).
2023-11-21 08:48:18 +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
Joseph Birr-Pixton 538cb78f83 Abolish quic crate feature
This reveals that bogo_shim fails to build for `--no-default-features --features tls12`.
Feature gate the entire program on `ring | aws-lc-rs`.
2023-11-17 19:27:21 +00:00
Joseph Birr-Pixton 42cf372405 General smoke-test for `max_fragment_size`
`test_client_mtu_reduction` and `test_server_mtu_reduction` already exist
but only check client/server behaviour in (relative) isolation.

This test just checks handshaking and bidirectional data flow over
a matrix of key types, TLS versions, and max_fragment_sizes.
2023-11-10 17:44:32 +00:00
Joseph Birr-Pixton e3925b18e6 Use `BorrowedCursor` & `BorrowedBuf` from core::io 2023-11-10 16:11:42 +00:00
Joseph Birr-Pixton d3ab8f030b Opt in to feature(core_io_borrowed_buf)
This is needed for `BorrowedBuf` now, even if via the std::io reexport.
2023-11-10 16:11:42 +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 ff86ccf140 verify: add Debug bound to ClientCertVerifier
This commit adds a `Debug` bound to the `ClientCertVerifier` 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 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 653abcbf7f key_log: add Debug bound to KeyLog trait
This commit adds a `Debug` bound to the `KeyLog` trait in addition to
`Send` and `Sync`. Each implementation in the codebase is updated to
derive, or hand-implement the `Debug` trait, taking care not to include
any fields that may contain secret key information.
2023-11-09 18:26:12 +00:00
Joseph Birr-Pixton 1379f12657 Enable testing and benchmarking with aws-lc-rs 2023-11-09 16:18:11 +00:00
Joseph Birr-Pixton 8ea64754ac Remove reexport of signing impls in `rustls::sign::*`
These continue to be available in `rustls::crypto:💍:sign::*`.
2023-11-09 16:18:11 +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
Daniel McCarney c3f00c7179 tests: test server hint subject control
Adds tests for:
* Sending an empty root hint subjects list.
* Adding custom root hint subjects in addition to the defaults.
2023-10-30 15:04:46 +00:00
Daniel McCarney 3cfa71d853 tests: generalize client cert resolve test
Pull out a generic helper from the existing client cert resolver test,
rename the test that uses the helper to emphasize it's testing a default
configuration. This will make it easier to add a test for non-default
configurations.
2023-10-30 15:04:46 +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
Joseph Birr-Pixton 602929fa26 Test excess secret exporting, to address TODO 2023-10-26 11:12:05 +00:00
Daniel McCarney 60420c53aa tests: add verify_server_cert_signed_by_trust_anchor helper test 2023-10-25 14:12:46 +00:00
Daniel McCarney 587a0ec1d3 tests: coverage for server revocation depth/unknown status
This commit adds test coverage for a client connecting to a server with
a webpki server certificate verifier configured to do CRL revocation
checking.
2023-10-25 14:12:46 +00:00
Daniel McCarney 46f719a8a0 tests: coverage for client revocation depth/unknown status
This commit updates the existing client certificate revocation testing
to also exercise the two new verifier options for controlling the depth
of revocation checking, and deciding how to handle unknown revocation
status.
2023-10-25 14:12:46 +00:00
Joseph Birr-Pixton 3659b61193 KeyShareEntry: tighten up use in tests
- swap `PayloadU16` for `KeyShareEntry::new`
- swap public members for accessor fn
2023-10-19 15:07:38 +00:00
Joseph Birr-Pixton 7a3daed1d7 Reduce rustls::internal exports to exactly what is used
This causes a cascade of types in `msgs` that were pub but are
no longer reachable: most of this commit is from `cargo fix`.
2023-10-19 15:07:38 +00:00
Daniel McCarney 326008d032 tests: ServerCheckNoSNI -> ServerCheckNoSni
This commit renames the `ServerCheckNoSNI` struct to `ServerCheckNoSni`
to match Rust naming conventions.
2023-10-18 08:25:00 +00:00
Robsdedude 0bbc1cf3f8 Flush writers before potentially expecting a response 2023-10-18 07:49:43 +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 e7a15fb935 lib: remove crypto:💍:kx_group re-export 2023-09-19 13:39:44 +00:00
Daniel McCarney 46b3442d57 lib: remove crypto:💍:ALL_CIPHER_SUITES re-export 2023-09-19 13:39:44 +00:00