Skip to content

SSL websocket client certificate validation failure results in connection timeout #199

@nfd

Description

@nfd

In trio-websocket, when running as a client, connecting to a server using SSL: Because SSL connection happens during the initial handshake, if there is an SSL issue such as a failure to validate the server's certificate, Trio's SSL connection will be set to _state.BROKEN and trio-websocket's reader_task will exit, but because the exception is translated to ConnectionClosed by _send the reader_task will exit normally and the nursery will stick around, meaning the connection will time out rather than immediately exit.

It's fixable by doing something unpleasant like this in _send's exception handler:

if isinstance(exc.__cause__, _stdlib_ssl.CertificateError):
    raise exc.__cause__

But that's a bit unpleasant. I tried instead having reader_task's _initial_request handler re-raise the exception, but that seems too broad.

Any thoughts? Happy to write something. I'm hitting this issue because a client running on Windows is sometimes unable to validate certificates, and it would be useful to know early rather than waiting for a connection timeout (which also obscures the cause of the error).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions