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 #2570: close only when TLS buffers drained #2587

Merged
merged 1 commit into from
Jan 23, 2024
Merged

Fix #2570: close only when TLS buffers drained #2587

merged 1 commit into from
Jan 23, 2024

Conversation

cpq
Copy link
Member

@cpq cpq commented Jan 23, 2024

Mongoose reads raw encrypted data into the c->rtls buffer. Then, it feeds that data to the TLS library.
Currently, if server finished sending the data, it closes the connection. Mongoose reads data into c->rtls, so c->rtls has some data to be decrypted, then Mongoose reads 0 from the socket, indicating that server has closed the connection.
And Mongoose closed the connection too, despite it has some data in c->rtls yet to be decrypted!

This PR fixes that issue and decrypts everything before closing the connection.

@cpq cpq requested a review from scaprile January 23, 2024 11:11
Comment on lines +288 to 293
} else {
if (n > 0) c->rtls.len += (size_t) n;
if (c->is_tls_hs) mg_tls_handshake(c);
if (c->is_tls_hs) return;
n = mg_tls_recv(c, buf, len);
} else if (n == MG_IO_WAIT) {
n = mg_tls_recv(c, buf, len);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

mg_tls_handshake() used to execute on n > 0, now that path is taken as long as there is no IO_ERR; even on IO_WAIT, overriding the call to mg_tls_recv().
Looks cleaner, as long as that is what's intended.

@scaprile scaprile mentioned this pull request Jan 23, 2024
@scaprile scaprile self-requested a review January 23, 2024 17:02
@scaprile scaprile merged commit 8dc62c2 into master Jan 23, 2024
130 of 133 checks passed
@scaprile scaprile deleted the tls branch January 23, 2024 17:03
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.

2 participants