Search code examples
python-3.xsslwebsocket

Python Websocket connection ssl.SSLError: [SSL: WRONG_SIGNATURE_TYPE] wrong signature type (_ssl.c:997)


I try to connect through websocket connecton, but get ssl error

    url = "wss://my.site/websocket"
    ws = websocket.create_connection(url, sslopt={
        "check_hostname": False,
        "cert_reqs": ssl.CERT_NONE
    })
File "C:\Python3\lib\ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_SIGNATURE_TYPE] wrong signature type (_ssl.c:997)

I use Python 3.10.10 and this library for websocket https://websocket-client.readthedocs.io/en/latest/index.html

For regular requests I use

class SslAdapter(requests.adapters.HTTPAdapter):
    def init_poolmanager(self, connections, maxsize, block=False):
        ctx = ssl.create_default_context()
        ctx.set_ciphers('DEFAULT@SECLEVEL=0')

        self.poolmanager = urllib3.poolmanager.PoolManager(
            ssl_version=ssl.PROTOCOL_TLS,
            ssl_context=ctx)

And then use it like this

        self.session = requests.Session()
        self.session.mount("https://my.site/", SslAdapter())

Seems like I should make something like that for websockets

website connection info:

        "Protocol version:": "TLSv1.2",
        "Cipher suite:": "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
        "Key Exchange Group:": "P256",
        "Signature Scheme:": "RSA-PKCS1-SHA1"

Solution

  • Based on the documentation you could use sslopt also to set the cipher, similar to what you do with requests:

    ws = websocket.create_connection(url, sslopt={
        "check_hostname": False,
        "cert_reqs": ssl.CERT_NONE,
        "ciphers": "DEFAULT:@SECLEVEL=0",  # allow weaker settings
    })
    

    Note though that if you care about the security of the data you should refrain from disabling certificate and hostname validation.