3

I am trying to send data to cloud using secure websocket (wss). The cloud interface only allows secure websocket ( HTTP, non-secure websocket etc are not allowed)

I tried the latest master,dev builds from nodemcu-build.com , but there SSL is failing. Even HTTPs is not working. So I tried the "1.5.4.1-final" build. Here I verified SSL is working for HTTPS:

conn=net.createConnection(net.TCP, 1)
> conn:on("receive", function(sck, c) print(c) end )
> conn:on("connection", function(conn)
print("connected")
conn:send("HEAD / HTTP/1.1\r\n"..
"Host: google.com\r\n"..
"Accept: */*\r\n"..
>> "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
"\r\n\r\n")
end )
> conn:on("disconnection", function(conn)  print("disconnected") end )
> conn:connect(443,"google.com")
> connected
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: https://www.google.co.in/?gfe_rd=cr&ei=HWhHWffUGojT8ge-wrS4Cw
Content-Length: 262
Date: Mon, 19 Jun 2017 05:58:53 GMT
Alt-Svc: quic=":443"; ma=2592000; v="38,37,36,35"

But when I tried both non-secure websocket and secure websocket, only non-secure websocket worked. This is the log for successful non-secure connection:

ws = websocket.createClient()
> ws:on("connection", function()
print('connection opened', status)
end)
> ws:on("receive", function(_, msg, opcode)
print('got message:', msg, opcode) -- opcode is 1 for text message, 2 for binary
end)
> ws:on("close", function(_, status)
print('connection closed', status)
ws = nil -- required to lua gc the websocket client
end)
> ws:connect('ws://echo.websocket.org/')
> connection opened nil

And this is for failed secure connection:

> ws = websocket.createClient()
> ws:on("connection", function()
>> print('connection opened', status)
end)
> ws:on("receive", function(_, msg, opcode)
print('got message:', msg, opcode) -- opcode is 1 for text message, 2 for binary
end)
> ws:on("close", function(_, status)
>> print('connection closed', status)
ws = nil -- required to lua gc the websocket client
end)
> ws:connect('wss://echo.websocket.org/')
> connection closed -128

Is secure websocket not supported in nodemcu ? If not, how can I get secure websocket working? Is there any extra code required for secure websocket compared non-secure?

Kiran
  • 119
  • 1
  • 9
  • FYI, the SSL/TLS/HTTPS issue is tracked in https://github.com/nodemcu/nodemcu-firmware/issues/1707 – Marcel Stör Jun 19 '17 at 20:21
  • Looking at [websocketclient.c](https://github.com/nodemcu/nodemcu-firmware/blob/master/app/websocket/websocketclient.c) it seems like it should be supported. Have you checked the box that says `TLS/SSL support provided by mbed TLS: TLS 1.0 / 1.1 / 1.2 and most common cipher suites including DH/ECDH (ECDSA-based disabled by default).` on https://nodemcu-build.com/ ? – Forivin Jun 20 '17 at 08:48
  • @Forivin Yes. Thats why HTTPS is working – Kiran Jun 20 '17 at 11:31
  • In your question you said that SSL including HTTPS is failing for builds from nodemcu-build.com . That's why I mentioned the checkbox. – Forivin Jun 20 '17 at 11:36
  • When I said " Here I verified SSL by testing HTTPS:", I meant HTTPS is working. I will update the question for clarity – Kiran Jun 20 '17 at 12:15

0 Answers0