Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: Token encode refactors #2110

Merged
merged 10 commits into from
Dec 24, 2024

Conversation

gretchenfrage
Copy link
Collaborator

Please see individual commit messages.

If "Make address a field of RetryToken" is too controversial, I can split it off into a subsequent PR to help the ones before it get through.

@gretchenfrage gretchenfrage changed the title Token encode refactors proto: Token encode refactors Dec 22, 2024
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

quinn-proto/src/token.rs Outdated Show resolved Hide resolved
This will be useful for NEW_TOKEN usage, as validation tokens will only
include IP address and not port.
Prior to this commit, decoding a socket addr from a RetryToken called
get_u8 and get_u16, which would have panicked if an encrypted token were
minted that terminated after that point. This replaces them with calls
that short-circuit, for consistency with other parts of the code there.
This will be useful for NEW_TOKEN usage, as it will make there be more
than one call site for this.
@gretchenfrage gretchenfrage force-pushed the token-encode-refactors branch 2 times, most recently from ee17203 to ec65aa5 Compare December 23, 2024 22:32
Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The weird address handling was leftover from of an old design where the address was AAD rather than explicitly stored. We migrated away from that because that made it impossible to distinguish invalid tokens from valid tokens with invalid addresses. Glad to see it tidied up.

quinn-proto/src/token.rs Outdated Show resolved Hide resolved
Organizes encoding payload section versus encrypting section.
Prior to this commit, a RetryToken encodes the client's address as if it
were a field, but rather than it actually being a field, it's threaded
in to encode, and validated in-place in decode. It's unclear to me why
this is. This commit makes the remote address simply a field of the
RetryToken struct.
As of the previous commit, RetryToken::decode fails only with the
Unusable variant, and validation only occurs in
IncomingToken::from_header, which uses InvalidRetryTokenError directly.
This allows us to remove ValidationError altogether.
This probably won't affect much, but is slightly more defensive.
@gretchenfrage gretchenfrage added this pull request to the merge queue Dec 24, 2024
Merged via the queue into quinn-rs:main with commit bfbeecd Dec 24, 2024
20 checks passed
@gretchenfrage gretchenfrage deleted the token-encode-refactors branch December 24, 2024 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants