Skip to content

FIX: Alert handling in ASIO stream and HTTP Server#3795

Merged
reneme merged 3 commits intorandombit:masterfrom
Rohde-Schwarz:fix/tls_http_alert
Nov 5, 2023
Merged

FIX: Alert handling in ASIO stream and HTTP Server#3795
reneme merged 3 commits intorandombit:masterfrom
Rohde-Schwarz:fix/tls_http_alert

Conversation

@reneme
Copy link
Copy Markdown
Collaborator

@reneme reneme commented Nov 2, 2023

Turns out that #3778 seems to be caused by a long-standing bug in the ASIO stream wrapper. Consider a client sending a ClientHello that a server has to reject with a lack of compatible ciphersuites. Botan's TLS server would signal that with a TLS_Exception(Alert::HandshakeFailure, "...").

The TLS stream wrapper (as the server) didn't properly handle that (as in: send a fatal alert message, terminate the connection and report a reasonable error code back to ASIO). Instead it just closed the connection immediately.
Likewise, when receiving a fatal alert message from a peer, the ASIO stream wrapper didn't report that back to the application as an error code but also simply terminated the connection.

This surfaced because the TLS Anvil nightly test is based on ./botan tls_http_server, which is now based on the ASIO stream: #3763. Here we add proper handling for both cases and a suitable regression test.

Fortunately, the buggy behavior was arguable "okayish": The connection was hard-reset. Just, the application and the peer didn't get a proper error message. TLS-Anvil isn't satisfied with just that, though.

@FAlbertDev Let's verify tomorrow that this helps with #3778.

Co-Authored-By: Fabian Albert <fabian.albert@rohde-schwarz.com>
@reneme reneme added the bug label Nov 2, 2023
@reneme reneme added this to the Botan 3.3.0 milestone Nov 2, 2023
@reneme reneme self-assigned this Nov 2, 2023
@coveralls
Copy link
Copy Markdown

coveralls commented Nov 2, 2023

Coverage Status

coverage: 91.69% (-0.01%) from 91.704%
when pulling 8ac28bf on Rohde-Schwarz:fix/tls_http_alert
into d0ce04a on randombit:master.

@reneme reneme force-pushed the fix/tls_http_alert branch from c7d9fb8 to 42e32c1 Compare November 3, 2023 08:02
@reneme
Copy link
Copy Markdown
Collaborator Author

reneme commented Nov 3, 2023

Force pushed to explain it again for MSVC. It produced warnings for unreachable code that were false positives. 🤷‍♂️

@FAlbertDev
Copy link
Copy Markdown
Collaborator

FAlbertDev commented Nov 3, 2023

Nice! TLS-Anvil is not yet fully satisfied but many failing tests were fixed by these changes (see TLS-Anvil CI for this PR). Before we had 62 failing tests, now we only have 8. We'll look into these as well.

@reneme reneme force-pushed the fix/tls_http_alert branch 3 times, most recently from 86672dd to 9a21fe3 Compare November 3, 2023 14:46
@reneme
Copy link
Copy Markdown
Collaborator Author

reneme commented Nov 3, 2023

8ac28bf contains another fix. On application level (./botan tls_http_server) this time. We need to make sure that the server always calls .async_shutdown(), even if a TLS exception is thrown. This will flush outstanding data from the server's write buffer: e.g. a TLS alert message emitted by the stream during async_read().

Co-Authored-By: Fabian Albert <fabian.albert@rohde-schwarz.com>
@reneme reneme force-pushed the fix/tls_http_alert branch from 9a21fe3 to 8ac28bf Compare November 3, 2023 15:28
@reneme reneme changed the title FIX: Handshake alert handling in ASIO stream FIX: Alert handling in ASIO stream and HTTP Server Nov 3, 2023
Copy link
Copy Markdown
Owner

@randombit randombit left a comment

Choose a reason for hiding this comment

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

👍

@reneme reneme merged commit 4fb6ec9 into randombit:master Nov 5, 2023
@reneme reneme deleted the fix/tls_http_alert branch December 11, 2023 14:50
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.

4 participants