-
Notifications
You must be signed in to change notification settings - Fork 717
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
Conversation
edb3afb
to
4039a9d
Compare
tls/s2n_record_read.c
Outdated
/* 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); |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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)
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.