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

fix: parse fragmented sslv2 client hellos #4425

Merged
merged 7 commits into from
Feb 20, 2024
Merged

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Feb 18, 2024

Description of changes:

Fixes an issue where parsing sslv2 messages fails if the first call to conn->recv doesn't return the whole message.
Usually we block in that case and try again later. But we weren't rereading conn->header_in for sslv2, so the second attempt would try to read a whole new header and fail because conn->header_in was already full of the actual header. After I fixed that, I also found that we were removing the sslv2 bit flag while parsing, so the second attempt wouldn't be detected as sslv2.

I also added a conn->header_in reread before attempting to read a new header, just in case there's another code path that leads to us not rereading conn->header_in. conn->header_in is a 5-byte static stuffer, so in order for it to contain a full 5-byte header the read cursor always needs to be 0. I didn't consider that sufficient to solve the problem though, since non-sslv2 headers are available immediately after parsing and some code could theoretically rely on that fact. So I still think the reread at the end of the header parsing methods is necessary.

Testing:

New tests for sslv2 header parsing and fragmented sslv2 messages.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Feb 18, 2024
@lrstewart lrstewart force-pushed the sslv2 branch 3 times, most recently from edb3afb to 4039a9d Compare February 18, 2024 07:55
@lrstewart lrstewart marked this pull request as ready for review February 19, 2024 15:48
tls/s2n_record_read.c Outdated Show resolved Hide resolved
tls/s2n_record_read.c Outdated Show resolved Hide resolved
Comment on lines 43 to 46
/* The first bit of the length must be set to indicate SSLv2,
* so the raw fragment length must be adjusted.
*/
*fragment_length ^= (S2N_TLS_SSLV2_HEADER_FLAG << 8);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote a bunch of unit tests for this in s2n_record_read_test, but still please sanity check my math :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The shift math is correct 😄. I'm just a bit concerned about the XOR: #4425 (comment)

tls/s2n_record_read.c Outdated Show resolved Hide resolved
@lrstewart lrstewart requested a review from camshaft February 19, 2024 18:29
tls/s2n_record_read.c Show resolved Hide resolved
tls/s2n_record_read.c Show resolved Hide resolved
@lrstewart lrstewart requested a review from maddeleine February 19, 2024 23:34
@lrstewart lrstewart enabled auto-merge (squash) February 20, 2024 00:11
@lrstewart lrstewart merged commit 80a6913 into aws:main Feb 20, 2024
31 checks passed
@lrstewart lrstewart deleted the sslv2 branch February 29, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants