I'm looking to host some websocket based applications, which should only be accessible via an https page. As such, the server generates the https page with a random key inside. I want to use this key to protect against someone from the outside from accessing the websockets indirectly.
I could have each web socket client send the key to the websocket servers, and close the connection if the key does not match. I would prefer, however, to update the websockets themselves to pass the key, and automatically reject the connection if the key does not match. (this way, if a new app is introduced, there's no chance of forgetting to implement the check).
I've looked around, and am not finding much in-depth documentation on how websockets work.
Is the initial handshake of a wss connection sent in the clear (if I attached the key to those packets, could a man-in-the-middle intercept them?). If not, is there a standard way to send this sort of meta data on the connection, or should I just hack the websocket source files?
I'm using libwebsockets on the server side, and jquery.websockets for the client side.