Search code examples
sslstunnelratchet

warping ratchet with stunnel


I have ratchet webSocket server running and it works well. the problem is that some of the connections are closing right after the handshake.

after searching stackOverflow and google I found out that I should use wss, because using ssl will prevent the connections from being closed. after some more reading I found that wss is not implemented yet in ratchet, and that the solution is to warp ratchet with stunnel. I searched again for help on how to implement this but found non .

how do I warp ratchet with stunnel? is there a better way to solve this problem? I'm really a newbie will all the ssl issue.

thanks!


Solution

  • Set up your ratchet websocket to accept only local connections:

    $webSock = new Server($loop);
    $webSock->listen(8080, '127.0.0.1'); // local connections only
    $session = $this->getContainer()->get('session.provider');
    $server = new IoServer(new WsServer($session), $webSock, $loop);
    

    Generate a server certificate. Nice instructions for ubuntu here.

    Now install stunnel. Ubuntu instructions here.

    Configure stunnel to use the new certificate and accept connections on a secure port and tunnel them to your websocket server:

    cert = /etc/ssl/certs/server.crt
    key = /etc/ssl/private/server.key
    ...
    [websockets]
    accept = 8443
    connect = 8080
    

    Start stunnel, and you should be off to the races.