Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS - SocketIO over SSL with websocket transport

I have a NodeJS-socketIO server that has clients listening from JS, PHP & Python. It works like a charm when the communication happens over plain HTTP/WS channel.

Now, when i try to secure this communication, the websocket transport is not working anymore. It falls back to xhr-polling(long polling) transport. Xhr-polling still works for JS client but not on python which purely depends on socket transport.

Things i tried:

  1. On node, Using https(with commercial certificates) instead of http - Works good for serving pages via Node but not for socketIO
  2. Proxy via HAProxy (1.15-dev19). From HTTPS(HAProxy) to HTTP(Node). Couldn't get Websocket transport working and it falls back to xhr-polling on JS. Python gets 502 on handshake.
  3. Proxy via STunnel (for HTTPS) -> HAProxy(Websocket Proxy) -> Node(SocketIO) - This doesnt work either. Python client still gets 502 on handshake.
  4. Proxy via Stunnel(HTTPS) -> Node(SocketIO) - This doesnt work too. Not sure if STunnel support websocket proxy
  5. node-http-proxy : Throws 500(An error has occurred: {"code":"ECONNRESET"}) on websocket and falls back to xhr-polling

Im sure its a common use case and there is a solution exist. Would really appreciate any help.

Thanks in advance!

like image 385
Karthik Jayapal Avatar asked Nov 13 '22 00:11

Karthik Jayapal


1 Answers

My case seems to be a rare one. I built this whole environment on a EC2 instance based on Amazon Linux. As almost all the yum packages are not up to date, i had to install pretty much every yum packages from source. By doing so i could have missed configuration unchanged/added. Or HAProxy required lib could have been not the latest.

In any case, i tried building the environment again on ubuntu 12.04 based EC2 instance. HAProxy worked like a charm with a bit of configuration tweaks. I can now connect my SocketIO server from JS, Python & PHP over SSL without any problem. I could also create a Secured TCP Amazon ELB that listens on 443 and proxy it to non-standard port (8xxx).

Let me know if anyone else encounters a similar problem, I will be happy to help!

like image 165
Karthik Jayapal Avatar answered Nov 15 '22 01:11

Karthik Jayapal