1

I am implementing a Local Websocket server in Express nodeJS. Data is sent from the front-end to the server by creating a new WebSocket(ws://<private_ip>:3000); as soon as <private_ip>:3000 is opened in a phone browser. (notice the ws)

This Local Websocket server will not be hosted on a public server but only on personal machines e.g. your own windows/mac machine. The reasoning behind this is not related to this post and will be omitted.

I have a basic understanding of how certificates work. I know that self-signed certificates are usually imported to the browser to be trusted. The goal is to use something like new WebSocket(wss://<private_ip>:3000); at the client side (notice the wss).

I fail to understand how the socket client created by code will trust a self-signed certificate, hence the question: is there a way to secure the connection/communication to/with a locally hosted Webserver

RawiSader
  • 21
  • 7
  • Do you really need wss if the traffic is only on the local machine? – jfriend00 Sep 27 '22 at 21:42
  • @jfriend00 yes, I am not in a position to disclose the underlying details but I do need to secure communication between two machines – RawiSader Oct 02 '22 at 15:44
  • If you want a browser to trust a self-signed certificate, it seems you will have to import that cert into the browser as a trusted certificate. See [Getting Chrome to accept self signed cert](https://stackoverflow.com/questions/7580508/getting-chrome-to-accept-self-signed-localhost-certificate) for several approaches. – jfriend00 Oct 02 '22 at 17:12
  • Yes in the browser you trust a new root certificate by importing. What I am looking for is a secure communication between code. I am not using Chrome. Does it make sense to have local certificates and private keys that are used by nodeJS on each machine? – RawiSader Oct 03 '22 at 13:16
  • What is the front-end environment then? You've said it's not Chrome, so what is it. Environments each have their own way of importing certificates that they will trust. – jfriend00 Oct 03 '22 at 20:56
  • @jfriend00 i am using nodeJS to create my Websocket client and express server, more specifically they are running inside electron which is similar to chrome – RawiSader Oct 04 '22 at 17:14

0 Answers0