A secure, in-browser messaging application that facilitataes communication via an SSH tunneling service and doesn't store your chats.
Both participants need to run this program on their computers.
A node server is locally set up at a chosen port (default=3001) which is going to serve as the incoming message server. This local server is exposed via a secure ssh tunnel. A service called localhost.run is used for this purpose; however, you can use any other service of your choice (like serveo.net, ngrock, etc) by modifying the code in host.js
accordingly.
On receiving messages, the server temporarily stores them in a variable and returns its value (i.e., all unread messages) when the client sends an HTTP request at /fetch
.
The client can interact with the program through a simple in-browser UI (HTML webpage). Every 0.5s, a function asynchronously checks for available unread messages and puts them on the HTML page.
When the client wants to send a message to their peer, an HTTP POST request is sent at the /
of the peer's exposed node server which then receives the message and stores it, until requested by the peer's client UI, in a variable.
- Node.js.
- A free TCP port (default 3001) that Node.js is allowed to access.
- Firewall access given to Node.js and SSH.
- If you're on Windows, make sure that
ssh
is available as a shell command. SSH is a default shell command on Linux and MacOS but you can set it up in your Windows CMD by installing third party software like Putty or Git Desktop.
As defined under ['dependencies'] in package.json
Start the program by executing the host.js
file. After navigating to the root directory of this program in the command line, execute:
node host.js
This will start the local server and set up the SSH tunnel (ssh tunnel will be set up as a subprocess). When these steps are completed, the program will automatically open the web client.
The webpage will ask for a peer ID, which is the user address of your peer. After entering the Peer ID, you'll see a chat page and you can start exchanging text messages.
The user address is basically the URL that your local server is publicly accessible through. When you start the SSH tunnel using something like localhost.run you'll see that URL returned in the terminal. To have a consistent address for your peers, you can use a domain or subdomain that points to the current tunneled URL of your server (you'll have to update the DNS records of your domain every time you start the tunnel because that URL is randomly generated every time).
I've used localhost.run as the service to demonstrate the working of this code. You can directly modify the statement according to your service of choice.
Since the working of this program relies on an external application - like localhost.run or serveo.net - for the SSH tunnel, issues in the tunnelling app's server will cause this program to malfunction as well.