This is an end to end encrypted chat application build on top of Rabbitmq.
- End to end encrypted chat
- User authentication
-
Rabbitmq (amqp) for pub/sub
-
Nodejs
-
Expressjs
-
Socket.IO
-
Postgresql
-
ReactJS (with ChakraUI and Zustand)
-
Docker (for setting up pg and rabbitmq)
-
ECDH algorithm for generating shared secret key
-
AES encryption
I had learnt about Event brokers and message queues in the past. And I was quite interested in cryptography that I had previously took a course on it. I wanted to learn how to use it in a real world application. And this felt like the perfect project for learning both.
I first used Deffie-Hellman algorithm to generate shared secret key. But there wasn't any package available to do so in the browser. So I had to research a bit and found out ECDH method, and it had a great open source package available.
This was a learning project where I focused on learning software architecture design, so I used a lot of libraries on the frontend instead of doing to from scratch.
It was quite hard because I had to learn about event brokers and how to use them. I tried out Kafka, heard about few others from friends and eventually settled for rabbitmq because of how straightforward it was.
There was also a lot of thinking and planning required to get the project up and running. More so I was thinking than writing any code.
- User registers and logs in
- A private key is generated and stored on browser.
- A public key is generated and stored on server.
- When user sends message to another user (through SocketIO), the other user's public key is used to generate a shared encrypted key and the message is encrypted using the shared secret key before being sent.
- The server now receives the message (encrypted) and adds to a Rabbitmq Queue (each user had individual queues).
- Once the other user logs in, the Rabbitmq queue is consumed and the message is sent back through SocketIO.
- The other user now uses the first users public key to generate the shared secret key and decreypts the message.
- The message is then stored on other users browser.
You will need Docker and Nodejs installed on your system.
- Go to
./server
and dodocker compose up
to startup postgres and rabbitmq. - Create a
.env
file by copying contents of.env.example
file. - Use command
yarn install
ornpm install
to install dependencies. - Run
yarn start
ornpm start
to start the server. - Go to
./client
and runyarn install
ornpm install
to install dependencies. - Run
yarn start
ornpm start
to start the client server. - Now visit
localhost:3000
in your browser.
Thank you for reading so far :D Enjoy! Any contributions are welcome.