Efficient C implementation of E2EE chat based on distributed server and database system easily scalable using Docker. GUI implemented using Nuklear library allowing for private and group chats.
MIT License
Secure Chat is a C program that allows you host decentralized system and chat securely with your friends. -It implements Diffie-Hellman (DH) key exchange to prevent man-in-the-middle (MitM) attacks, it uses the RSA algorithm to create sessions and AES algorithm for message end-to-end (EE2E) encryption-. Messages are stored in SQLite3 (ultimately other, distributed) database and can be read by the recipient only. Sending messages in optimized for maximum performance and resource usage.
[!IMPORTANT] This project is still in development and does not contain server distribution yet.
The application uses the OpenSSL library for HTTPS connection, encryption, and decryption. The server acts as a buffer and router for clients. The following algorithms are used:
The server does not store any messages, only the public keys of the clients. The messages are stored in the SQLite3 database and can be read by the recipient only. The server does not have access to the messages.
Client connects to the server via HTTPS:
Client authentication:
Public/Private Key Exchange:
Client A prepares a message for Client B:
DH Key Exchange:
AES Encryption:
Message transmission:
Decryption:
If Client A sends a message to Client B, and Client B is either offline or no prior DH key exchange has occurred (e.g., first-time contact):
Client A retrieves Client B’s public RSA key:
AES Key Generation:
Message Encryption:
Message and AES key transmission:
Client B retrieves the encrypted data:
Decryption:
Unique DH Key Exchange:
Fetching stored messages:
Old Messages:
Multiple Devices:
Reusing existing keys:
Fetching stored messages:
Decryption:
Key derivation:
Key rotation:
Forward secrecy:
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
For a Debian-based system, you can install the following packages:
sudo apt install git gcc make sqlite3 libz-dev xorg-dev libc6-dev libxi-dev libssl-dev libuv1-dev libx11-dev libxrandr-dev libsqlite3-dev netcat-openbsd libasound2-dev libwayland-dev build-essential mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libcurl4-openssl-dev libxkbcommon-x11-dev libxkbcommon-dev
This should also work with Ubuntu and Linux Mint.
git clone https://github.com/mldxo/secure-chat
cd secure-chat
make
Run the server and client executables in separate terminals.
server/build/bin/server
client/build/bin/client
You can download server and client from the releases page.
You can also run the server using Docker.
docker pull mlsh/secure-chat
docker run -d -p 12345:12345 mlsh/secure-chat
Server is responsible for handling client connections, retrieving messages from the database and sending messages to the recipients. It also manages user registration and authentication according to the protocol. Multithreading is used to allow many concurrent requests and connections. Client connections are stored in a thread-safe hash map and only one logged instance of a client is allowed. Messages before handling are stored in thread-safe queue. Server facilitates CLI for system administration. Server logs all requests, client connections and errors.
Client connects to the server, sends messages and receives messages from the server. GUI is planned to be implemented with Raylib in next few PRs.
Common generates static library that is used by both server and client, i.e. communication protocol, encryption and decryption functions. It also defines the message structure, signal codes, data structures and functions that are shared between server and client.
SQLite3 database is utilized at the moment. There is planned usage of distributed database system Cassandra or MongoDB in the further project iterations.
Navigate to database for detailed database schema documentation.
This project is licensed under the MIT License - see the LICENSE file for details.
Please refer to CONTRIBUTING.md. We appreciate your help!