Introduce struct ngtcp2_stateless_reset_token#2035
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the handling of stateless reset tokens within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces the ngtcp2_stateless_reset_token struct to improve type safety and code clarity when handling stateless reset tokens, which is a significant and positive refactoring. The changes are extensive, touching many files to replace raw uint8_t arrays with the new struct. The PR also correctly deprecates several callbacks and introduces new versions that use the new struct, ensuring backward compatibility. The test suite has been updated accordingly. I've found a couple of minor issues in the implementation details, which I've commented on. Overall, this is a great improvement to the codebase.
This commit introduces ngtcp2_stateless_reset_token that stores stateless reset token as the name suggests. Previously, we use bare uint8_t[NGTCP2_STATELESS_RESET_TOKENLEN] for this purpose, then pass the array pointer to functions, assuming that it has the capacity of NGTCP2_STATELESS_RESET_TOKENLEN bytes. With ngtcp2_stateless_reset_token, the length is always explicit because of the embedded array. It also make the copy a bit easier without memcpy. This commit deprecates ngtcp2_pkt_stateless_reset, and adds ngtcp2_pkt_stateless_reset2 as a replacement. It also deprecates the following callbacks: - ngtcp2_recv_stateless_reset - ngtcp2_get_new_connection_id - ngtcp2_connection_id_status and, adds the following callbacks as their replacements: - ngtcp2_recv_stateless_reset2 - ngtcp2_get_new_connection_id2 - ngtcp2_connection_id_status2
d7898e3 to
b7bfe41
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the ngtcp2_stateless_reset_token struct to replace the raw uint8_t array, which is a great improvement for type safety and code clarity. The changes are extensive and have been applied consistently across the codebase, including documentation and tests. The handling of backward compatibility for callbacks is also well done. I've found one potential security issue regarding the use of memcmp for comparing stateless reset tokens, which could be vulnerable to timing attacks.
| int ngtcp2_stateless_reset_token_eq(const ngtcp2_stateless_reset_token *a, | ||
| const ngtcp2_stateless_reset_token *b) { | ||
| return memcmp(a->data, b->data, sizeof(a->data)) == 0; |
There was a problem hiding this comment.
The memcmp function is not guaranteed to be a constant-time comparison function. When comparing secret values like the stateless reset token, it's recommended to use a constant-time comparison function to mitigate potential timing side-channel attacks. The function ngtcp2_cmemeq is already used for this purpose elsewhere in the codebase (e.g., in ngtcp2_dcid_verify_stateless_reset_token) and should be used here as well.
int ngtcp2_stateless_reset_token_eq(const ngtcp2_stateless_reset_token *a,
const ngtcp2_stateless_reset_token *b) {
return ngtcp2_cmemeq(a->data, b->data, sizeof(a->data));
}
This commit introduces ngtcp2_stateless_reset_token that stores stateless reset token as the name suggests. Previously, we use bare uint8_t[NGTCP2_STATELESS_RESET_TOKENLEN] for this purpose, then pass the array pointer to functions, assuming that it has the capacity of NGTCP2_STATELESS_RESET_TOKENLEN bytes. With
ngtcp2_stateless_reset_token, the length is always explicit because of the embedded array. It also make the copy a bit easier without memcpy.
This commit deprecates ngtcp2_pkt_stateless_reset, and adds ngtcp2_pkt_stateless_reset2 as a replacement.
It also deprecates the following callbacks:
and, adds the following callbacks as their replacements: