add EchConfigListBytes for encrypted client hello configs#46
Conversation
I tacked on a version bump. |
djc
left a comment
There was a problem hiding this comment.
Is PEM encoding of EchConfig a common/described use case somewhere, or something you're hypothesizing might be useful?
It's a real use case but there's not a consistent implementation across the ecosystem yet.
Of the set I think |
I was thinking something like this: rustls/pemfile@3d3a9ef |
I want to hold on to this a bit longer. I might want to add another type for a TLS encoded list of configs. |
yeah I think this needs some rework, the new type should be for representing the encoding of a list, specifically The encoding of a single item is equivalent to a list of size 1. The raw value read from DNS that we want to represent here is in fact a list, I've just been confused by the common case being a single item that doesn't appear to be a list due to the rules of TLS presentation syntax. |
There was another aspect to my confusion I figured out over the weekend. The Hickory DNS representation of I think this is the wrong way for Hickory to present this data to a consumer. I believe most users of the data are going to be expecting the wire format described in the In the meantime I think my conclusion is that we should not have a pki-types representation for a single |
|
The crate-internal `DerInner` type is really a `Cow`-like type for generic bytes. The nature of those bytes is indicated by the pub wrapper type holding the `DerInner`. With that in mind we can re-use it for other non-DER types (e.g. ECH configs) but first need to rename the type to `BytesInner` since it is no longer DER in all cases.
Raw ECH config lists are likely to be shared between Rustls and other crates (e.g. they may be read from `rustls-pemfile` and `.pem` inputs for server configuration, or they may be fetched from DNS using DNS-over-HTTPS using `hickory-dns` for client config). This commit introduces a `EchConfigListBytes` type, wrapping `BytesInner`, that allows representing a borrowed or owned raw TLS encoded ECH config list, corresponding to the `ECHConfigList` type specified in TLS presentation language in draft-ietf-tls-esni-18 §4[0]. This type can be used between crates to maintain typed context for the bytes throughout. [0]: https://datatracker.ietf.org/doc/html/draft-ietf-tls-esni-18#section-4
This matches our preference in the main rustls repo.
I've reworked the branch around this conclusion and updated the commit/PR description accordingly. I think this is ready for re-review & I'll have an update to the WIP Rustls ECH PR to take a git patch on this branch shortly. While I was here I also tacked on the ubuntu-20.04 -> ubuntu-latest change I'm proposing in rustls/webpki#248. Like over there this branch is now showing "Required statuses must pass before merging" and will need an admin merge so we can retroactively fix the branch protection rules. |
|
Can we derive them for BytesInner then, instead of manually implementing? |
Hmmm. I don't think so because we want |
|
Ah, yes! |
Yeah, I think so: #[test]
fn bytes_inner_equality() {
let owned = BytesInner::Owned(vec![1, 2, 3]);
let borrowed = BytesInner::Borrowed(&[1, 2, 3]);
assert_eq!(owned, borrowed);
}With the derived impl: With my manual impl: I'll add some test coverage for this while I'm here. The derived version passed without error before I added a test. |
|
Can we do |
This allows deriving `PartialEq` and `Eq` automatically for the two wrapper types, `Der` and `EchConfigListBytes`. The `BytesInner` type is crate-internal and so we don't have to be worried about users accidentally comparing `BytesInner` from a `EchConfigListBytes` with a `Der` `BytesInner` without the broader type context catching the err. Similarly by dragging the meat of the `AsRef` impls down onto `BytesInner` we can simplify the `PartialEq` impl and wrapper type `AsRef` impls.
Ah! good idea. It was a similar situation here: |
|
|
||
| #[derive(Clone)] | ||
| enum DerInner<'a> { | ||
| #[derive(Debug, Clone)] |
There was a problem hiding this comment.
note: BytesInner also gains a derived Debug in this changeset to be usable with assert_eq! in the added unit test.
|
@ctz Do you have interest in reviewing this branch? I think its in a stable state now and I don't expect to need any other ECH related changes in this repo. |
|
lib: DerInner -> BytesInner
The crate-internal
DerInnertype is really aCow-like type for generic bytes. The nature of those bytes is indicated by the pub wrapper type holding theDerInner.With that in mind we can re-use it for other non-DER types (e.g. ECH configs) but first need to rename the type to
BytesInnersince it is no longer DER in all cases.EchConfigListBytes for encrypted client hello configs
Raw ECH config lists are likely to be shared between Rustls and other crates (e.g. they may be read from
rustls-pemfileand.peminputs for server configuration, or they may be fetched from DNS using DNS-over-HTTPS usinghickory-dnsfor client config).This commit introduces a
EchConfigListBytestype, wrappingBytesInner, that allows representing a borrowed or owned raw TLS encoded ECH config list, corresponding to theECHConfigListtype specified in TLS presentation language in draft-ietf-tls-esni-18 §4. This type can be used between crates to maintain typed context for the bytes throughout.