Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I establish a secure connection to a websocket on localhost?

We have an application which we run on a POS terminal, that should receive data from an application running on the same machine, while displaying content from a remote site which is loaded over HTTPS.

To receive the data from the local application, we want to use websockets, which is working fine so far. However, when the site we're displaying is loaded over HTTPS, the websocket connection is required to be encrypted as well.

Because we can't really get a proper certificate for localhost, we're just using a self-signed one. But Chrome won't connect to a websocket that uses a self-signed certificate.

How can we resolve this problem? We can't use an unencrypted websocket, we can't use a self-signed certificate for the encrypted one and we can't get a signed certificate for localhost. What option am I missing?

like image 270
Oliver Salzburg Avatar asked Sep 25 '14 11:09

Oliver Salzburg


People also ask

How do I run a WebSocket server on localhost?

What you can do is place all your code inside onopen event handler that you want to execute on successful connection. So it would be like... var webSocket = new WebSocket("ws://localhost:8025/myContextRoot"); webSocket. onopen = function() { // code you want to execute };

How do I enable WebSocket connection?

- In Control Panel, click Programs and Features, and then click Turn Windows features on or off. Expand Internet Information Services, expand World Wide Web Services, expand Application Development Features, and then select WebSocket Protocol. Click OK. Click Close.

How are WebSocket connection established?

The client establishes a WebSocket connection through a process known as the WebSocket handshake. This process starts with the client sending a regular HTTP request to the server. An Upgrade header is included in this request which informs the server that the client wishes to establish a WebSocket connection.


1 Answers

If you have admin privileges on the POS terminals, how about adding a line to the HOSTS file like:

127.0.0.1 localhost.mycompany.com

Now you can use a real certificate for localhost.mycompany.com in the server application.

like image 73
dricket Avatar answered Sep 17 '22 15:09

dricket