niv / websocket.nim

websockets for nim
http://niv.github.io/websocket.nim/docs/0.1.1/websocket.html
Other
101 stars 25 forks source link

SSL3_GET_RECORD:wrong version number on newAsyncWebsocket #26

Closed metagn closed 6 years ago

metagn commented 6 years ago

On Windows 10 x64

Code:

let ws = waitFor newAsyncWebSocket("gateway.discord.gg", Port 80, "?encoding=json&v=6", ssl = true)

Error (ws.nim(10) is the code above):

Traceback (most recent call last)
ws.nim(10)               ws
asyncdispatch.nim(271)   waitFor
asyncdispatch.nim(326)   poll
asyncdispatch.nim(180)   processPendingCallbacks
asyncdispatch.nim(1271)  :anonymous
asyncfutures.nim(118)    complete
asyncmacro.nim(34)       cb
asyncmacro.nim(334)      sendPendingSslDataIter
asyncfutures.nim(118)    complete
asyncmacro.nim(34)       cb
asyncnet.nim(237)        connectIter
net.nim(421)             getSslError
net.nim(431)             raiseSSLError
[[reraised from:
ws.nim(10)               ws
asyncdispatch.nim(271)   waitFor
asyncdispatch.nim(326)   poll
asyncdispatch.nim(180)   processPendingCallbacks
asyncdispatch.nim(1271)  :anonymous
asyncfutures.nim(118)    complete
asyncmacro.nim(34)       cb
asyncmacro.nim(334)      sendPendingSslDataIter
asyncfutures.nim(118)    complete
asyncmacro.nim(50)       cb
asyncfutures.nim(156)    fail
asyncmacro.nim(34)       cb
asyncmacro.nim           newAsyncWebsocketIter
asyncfutures.nim(220)    read
]]
[[reraised from:
ws.nim(10)               ws
asyncdispatch.nim(1345)  waitFor
asyncfutures.nim(220)    read
]]
Error: unhandled exception: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number
  connect's lead up to read of failed Future:
    Traceback (most recent call last)
    ws.nim(10)               ws
    asyncdispatch.nim(271)   waitFor
    asyncdispatch.nim(326)   poll
    asyncdispatch.nim(180)   processPendingCallbacks
    asyncdispatch.nim(1271)  :anonymous
    asyncfutures.nim(118)    complete
    asyncmacro.nim(34)       cb
    asyncmacro.nim(334)      sendPendingSslDataIter
    asyncfutures.nim(118)    complete
    asyncmacro.nim(34)       cb
    asyncnet.nim(237)        connectIter
    net.nim(421)             getSslError
    net.nim(431)             raiseSSLError
  newAsyncWebsocket's lead up to read of failed Future:
    Traceback (most recent call last)
    ws.nim(10)               ws
    asyncdispatch.nim(271)   waitFor
    asyncdispatch.nim(326)   poll
    asyncdispatch.nim(180)   processPendingCallbacks
    asyncdispatch.nim(1271)  :anonymous
    asyncfutures.nim(118)    complete
    asyncmacro.nim(34)       cb
    asyncmacro.nim(334)      sendPendingSslDataIter
    asyncfutures.nim(118)    complete
    asyncmacro.nim(34)       cb
    asyncnet.nim(237)        connectIter
    net.nim(421)             getSslError
    net.nim(431)             raiseSSLError
    [[reraised from:
    ws.nim(10)               ws
    asyncdispatch.nim(271)   waitFor
    asyncdispatch.nim(326)   poll
    asyncdispatch.nim(180)   processPendingCallbacks
    asyncdispatch.nim(1271)  :anonymous
    asyncfutures.nim(118)    complete
    asyncmacro.nim(34)       cb
    asyncmacro.nim(334)      sendPendingSslDataIter
    asyncfutures.nim(118)    complete
    asyncmacro.nim(50)       cb
    asyncfutures.nim(156)    fail
    asyncmacro.nim(34)       cb
    asyncmacro.nim           newAsyncWebsocketIter
    asyncfutures.nim(220)    read
    ]] [SslError]

Tried changing the SSL context version to SSLv23 and TLSv1 yet still the same error.

Discord doesn't allow ssl = false and gives a 400 Bad Request on websocket upgrade.

dom96 commented 6 years ago

What's your OpenSSL version? My guess is it's too old.

metagn commented 6 years ago

openssl version gives OpenSSL 1.1.0g 2 Nov 2017

dom96 commented 6 years ago

weird, maybe you could Nim devel?

nitely commented 6 years ago

Port should be 443 not 80. That fixes for me if I don't verify the certificate while on port 80 won't work at all.

metagn commented 6 years ago

When I tried before with 443 it gave the same error, but now when I do port 80 it says wrong protocol and 443 gives 400 bad request on websocket upgrade. Guess this was on Discord.

nitely commented 6 years ago

Bad request may have been due to #28 . So, clone the repo or pull latest changes and try again on port 443. This should work:

import asyncdispatch, asyncnet, net
import websocket

let ws = waitFor newAsyncWebsocket(
  "wss://gateway.discord.gg:443/?encoding=json&v=6",
  ctx=newContext(verifyMode=CVerifyNone))
# ...

I tried on Linux, btw and port 80 gave me the same error as you

metagn commented 6 years ago

Holy crap thanks, it worked