python-websockets / websockets

Library for building WebSocket servers and clients in Python
https://websockets.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5.15k stars 512 forks source link

Missing Alert Message before disconnection when a TLS connection error occurs #1503

Open m4su6747 opened 23 hours ago

m4su6747 commented 23 hours ago

Hello, I am testing the secure WebSocket connection. The server will send an invalid certificate to test the client's disconnection behavior.

The following is the result I captured using Wireshark. image The Client immediately disconnected right after the Server Hello which contains a invalid certificate. Therefore the Server didn't know the reason.

Accroding to the The TLS alert protocol https://gnutls.org/manual/html_node/The-TLS-Alert-Protocol.html I expect there to be an Alert Message before the disconnection.

This is another capture with JAVA WebSocket Client. image Here I can see the Alert (Level: Fatal, Description: Certificate Expired) is sended before the disconnection.

How can I achieve this behavior as well?

aaugustin commented 20 hours ago

This part are handled by Python's ssl module. I think you'd get the same result if you created a client socket directly, without involving websockets -- as shown here or there.

If so, it's a Python problem, not a websockets problem.