-
Notifications
You must be signed in to change notification settings - Fork 327
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
Reorganize http_receive() #640
Reorganize http_receive() #640
Conversation
230b158
to
53c2d74
Compare
@DimitriPapadopoulos I don't know about SSL errors, I can't remember. All I can tell is that I tried to avoid having external dependencies, hence the HTTP decoding inside our source. |
Oh, agreed about the dependencies. I'm after small libraries that can be included in the source code. PicoHTTPParser is just two files |
53c2d74
to
c2c467e
Compare
👍 |
I have pushed the code that is stricter on SSL errors. I will keep testing it for a few days. |
OK, it appears we are lenient on SSL errors after the header has been read because of change 70dadda. Specifically the change from:
to:
The comment reads:
Yet I don't see fundamental differences in the way we process chunked encoding vs. Lines 204 to 205 in 8b0c235
If on the other hand the response is chunked-encoded, we stop as soon as we detect the last chunk terminator: Lines 198 to 202 in 8b0c235
So what is this "'safe side" about? I have verified that checking strictly for SSL errors still works when parsing chunked-encoded responses. The code that handles the chunked encoding has been introduced in f1bfe16, a few days after 70dadda. My guess is that the "safe side" part had probably been left over because the author wasn't yet certain about the robustness of the chunked encoding code:
Yet I believe the chunked encoding code has proven quite astute and robust over the years. It believe it is time we parse HTTP following the rules - so that we can move to 3rd party HTTP parsing code if needed. |
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 have a few small comments just to be sure I have understood the changes.
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.
With the explanations now, I think the changes are good.
I'll try to provide more comprehensive explanations in the commit. |
maybe just a few buzzwords like "code cleanup and improve readability" would have lead my thoughts in the right direction :-) |
c2c467e
to
f608fce
Compare
Improve readabilty by moving conditionals that operate on 'n' right after assignment of 'n'. The conditional at the end of the loop: while (n > = 0) has been replaced by this conditional: if (n < = 0) and this one that triggers a tight 2nd loop: if (n == ERR_SSL_AGAIN) ⇔ if (n == 0) The new codes *returns from the function* with ERR_HTTP_SSL upon: if (n < 0) The previous code would only *leave the loop* upon: if (n < 0) and then return from the function with ERR_HTTP_SSL only upon: if (!header) Therefore SSL violations were silently ignored after reading the header and while reading the body of the HTTP response. Increase the HTTP buffer capacity when needed. You never know. The previous size of 32 KB used to work well from 2015 to 2020. In 2020 a case was reported where 32 KB were not enough anymore and we increased the buffer size to 64 KB. Someday 64 KB might not be enough either. Yet in most cases 32 KB are more than enough. So start with 32 KB and increase well beyond 64 KB if needed, instead of bailing out with ERR_HTTP_SSL. These changes will help introduce 3rd party HTTP parsing code if we decide to go that way.
f608fce
to
867bbe9
Compare
Prepare for adding an external HTTP library later on.
The pull request will help use external HTTP / XML libraries later on. At this point I am not certain we will benefit from using PicoHTTPParser in terms of maintainability and less code. Yet I'm opening the pull request to perform some code clean up, add a few assertions here and there, and raise a few issues.
For example we do not catch SSL errors if the header has already been read. Here is the relevant part in the new code:
https://github.com/DimitriPapadopoulos/openfortivpn/blob/230b158/src/http.c#L177-L181
and in the old code:
https://github.com/adrienverge/openfortivpn/blob/8b0c235/src/http.c#L217-L221
@adrienverge Is this on purpose? Are we lenient on purpose? On my machine I have modified the code to be strict on SSL errors, whether the HTTP header has been read or not. I haven't seen any occurrence of SSL errors.