Skip to content

Re-raise SSLErrors produced by TLS alerts as HandshakeErrors.#201

Open
sasozivanovic wants to merge 1 commit intopython-trio:masterfrom
sasozivanovic:ssl_errors
Open

Re-raise SSLErrors produced by TLS alerts as HandshakeErrors.#201
sasozivanovic wants to merge 1 commit intopython-trio:masterfrom
sasozivanovic:ssl_errors

Conversation

@sasozivanovic
Copy link
Copy Markdown

@sasozivanovic sasozivanovic commented Mar 28, 2026

This pull request relies on the bugfix proposed in PR python-trio/trio#3413 to address issue #199 — which means that it definitely should not be accepted until the fate of that PR is resolved! In fact, some of the new tests introduced here must fail until run against an updated Trio.

From the user's perspective, the issue was that a TLS client hanged after submitting an invalid (e.g. expired) client certificate.

The trio bugfix makes sure that the server (in general, peer) sends out the TLS alert after catching a ssl.CertificateError. In this commit, we do two things.

First, we intercept ssl.SSLErrors created by the alerts when receiving data from the stream (WebSocketConnection._reader_task) and sending data to the stream (WebSocketConnection._send), and wrap them into a HandshakeError.

Second, we catch and ignore these HandshakeErrors in WebSocketServer._handle_connection, so that a certificate error does not crash the server. Here, I'm unsure whether we should ignore all SSL errors (currently, this is the case), or maybe only those generated by alerts, or only those having to do with certificates, and neither do I know how to compile a comprehensive list of the latter, if that is what should be done.

This commit relies on the bugfix proposed in PR python-trio/trio#3413 to
address issue python-trio#199.

From the user's perspective, the issue was that a TLS client hanged after
submitting an invalid (e.g. expired) client certificate.

The trio bugfix makes sure that the server (in general, peer) sends out the TLS
alert after catching a `ssl.CertificateError`.  In this commit, we do two
things.

First, we intercept `ssl.SSLError`s created by the alerts when receiving data
from the stream (`WebSocketConnection._reader_task`) and sending data to the
stream (`WebSocketConnection._send`), and wrap them into a `HandshakeError`.

Second, we catch and ignore these `HandshakeError`s in
`WebSocketServer._handle_connection`, so that a certificate error does not
crash the server.  Here, I'm unsure whether we should ignore *all* SSL
errors (currently, this is the case), or maybe only those generated by alerts,
or only those having to do with certificates, and neither do I know how to
compile a comprehensive list of the latter, if that is what should be done.
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.

1 participant