Commit Graph

27 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
Daniel McCarney 495acf3444 crypto: explain TLS 1.2 version in TLS 1.3 message encrypters
Without the context of RFC 8446 in your mind the use of the
`ProtocolVersion::TLSv1_2` constant in the TLS 1.3 `MessageEncrypter`
implementations appears like an oversight or copy/paste error. This
commit adds a brief explanatory comment.
2023-12-06 18:41:59 +00:00
Joseph Birr-Pixton 644dfdc934 Split off tls13 module for aws-lc-rs 2023-11-21 09:58:03 +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
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
Christian Poveda 63ddf03a7c add `encrypted_payload_len` to `MessageEncrypter` 2023-11-16 19:15:54 +00:00
Joseph Birr-Pixton aaf21d1cdf Allow optional use of aws-lc-rs
Provide shims for limited number of places where ring 0.17 and
aws-lc-rs (ring 0.16-era) APIs have diverged.  This is a
short-term fix, as they are likely to diverge more over time.
Eventually we'll have to stop sharing the code like this.

For unit-like tests, export a `test_provider` alias that resolves
to a provider module, for use in these tests.

This resolves to:

- *ring* if cfg(feature = "ring"), else
- aws-lc-rs if cfg(feature = "aws_lc_rs"), else
- is absent
2023-11-09 16:18:11 +00:00
Joseph Birr-Pixton 7aa87e98a4 Make modules in crypto::ring reusable
They take the dependency on ring via `super::ring_like`, which
means they can be reused against a different, ring-compatible
crate.
2023-11-09 16:18:11 +00:00
Joseph Birr-Pixton 0013a087ab Return to using ring hkdf API
Now we no longer have a depedency on hmac, we can avoid that
and save some heap allocations.

This marginally improves TLS1.3 handshake performance.
2023-10-26 11:12:05 +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
Jorge Aparicio 5427a4d6e9 use `core::prelude` instead of `std::prelude` 2023-10-10 15:53:23 +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 79fd1f7639 suites: lift slice_to_array(s) helpers
The *ring* TLS 1.2 and TLS 1.3 AEAD algorithm implementations all shared
the same `slice_to_array` and `slices_to_arrays` helpers used to carve
up IV values for `extract_keys`.

This commit lifts these helpers to be associated with the
`ConnectionTrafficSecrets` type in the `suites` mod. This reduces
duplication, allowing all usages to share the same implementation.
2023-09-27 13:21:16 +00:00
Daniel McCarney fdcaed4145 cipher: impl `AsRef<[u8]>` for `Iv`
The TLS1.3 `Tls13AeadAlgorithm` trait passes an `Iv` instance to
`extract_secrets`. In order for a crate-external crypto provider to
offer an instance of this trait there needs to be a way to access the
`Iv`'s underlying `&[u8]` value. The crate-internal implementations of
`Tls13AeadAlgorithm` do this by accessing `Iv.0`, but this field is
`pub(crate)`.

This commit implements `AsRef<[u8]>` for `Iv` for this purpose, and
switches the existing `Iv.0` accesses to use it too. This allows
removing the `pub(crate)` access to the underlying array after also
exporting the cipher `NONCE_LEN` and exposing `Iv::new` for construction
from the correct size nonce array.
2023-09-27 13:21:16 +00:00
Daniel McCarney 3ab24727ac cipher: make extract_keys fallible
The `ConnectionTrafficSecrets` enum has a fixed number of variants,
describing supported AEAD algorithm secrets. Since it's now possible for
a crate-external crypto provider to supply new AEAD algorithms we need
to make the `extract_secrets` fn of the TLS 1.2 and TLS 1.3 AEAD
algorithm traits fallible so that if an algorithm is provided that
doesn't have a matching `ConnectionTrafficSecrets` variant, the
algorithm can return an `UnsupportedOperationError` when
`extract_secrets` is called.
2023-09-27 13:21:16 +00:00
Joseph Birr-Pixton f6f7df55c9 OpaqueMessage: privatize payload type
This removes a further need for `Payload` to be understood outside
this crate.  `payload()` allows immutable access as a slice,
`payload_mut()` allows mutable access to the underlying vec (such
as needed to decrypt the message without a copy).
2023-09-13 15:32:29 +00:00
Joseph Birr-Pixton 49f071b775 OpaqueMessage: allow construction without exposing `Payload` 2023-09-13 15:32:29 +00:00
Joseph Birr-Pixton 6541e9b18c tls13: use Error::EncryptError for encryption failures 2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton b421083f51 crypto::cipher: publicise traits for external use
This makes `Tls12AeadAlgorithm` and `Tls13AeadAlgorithm` public, as well as
the types that are associated with them.

Document fields that need to become public to allow `Tls12CipherSuite` and
`Tls13CipherSuite` to become public.
2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton 2b6a212b7e Move *ring*-backed quic implementations into crypto::ring 2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton 6757c25a4f Remove unused BulkAlgorithm enum 2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton 0375b01536 Insulate quic code from direct dependency on *ring*
eg, `HeaderProtectionKey` is no longer a struct, but a trait.
This is impl'd by `RingHeaderProtectionKey`.

This is a breaking change, because *ring* types no longer appear
in the public quic API.

This removes the final use of the `BulkAlgorithm` type, which is
deleted.

Reuse nonce computation in `cipher::Nonce::new`.
2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton d0db689d08 Move ring-backed ciphersuites into crypto::ring
As a result, crate::tls12::cipher becomes trivial enough to merge
into its parent.
2023-08-25 14:01:04 +00:00