This project is a Secure Chat System built in C++ that provides robust user authentication and encrypted communication between a client and a server. The system ensures the confidentiality, integrity, and security of user credentials and messages.
- User Registration: Users can register with a unique username and password.
- User Login: Authentication is done using SHA-256 hashed passwords.
- Diffie-Hellman Key Exchange: Secure key exchange mechanism for shared secret key generation.
- AES-128 Encryption: All messages exchanged between the client and server are encrypted using AES in CBC mode.
- Credential Storage: User credentials (username, email, and hashed password with a salt) are stored securely in
creds.txt
. - Super User (Admin) Functionality: An admin can add, remove, update, and view the credentials of registered users.
Client
: Responsible for user registration, login, and sending encrypted chat messages.Server
: Handles registration requests, login authentication, and facilitates encrypted message exchange between clients.
- Password Hashing: Passwords are hashed using SHA-256 with a unique salt for each user.
- Key Exchange: Diffie-Hellman key exchange protocol is used to establish a secure shared key.
- Encryption: AES-128 bit CBC mode is used for encrypting user credentials and chat messages.
- Salting: Each password is salted with a random 32-bit value to prevent rainbow table attacks.
- The client sends a registration request to the server.
- The server prompts the client for an email, username, and password.
- A mutual key is exchanged using Diffie-Hellman.
- The user's credentials (email, username, password) are encrypted using AES with the mutual key.
- The server decrypts the registration request and checks for username uniqueness.
- If the username is unique, the password is hashed with a random salt and stored in
creds.txt
along with the username and email.
- The client sends a login request to the server.
- The server prompts the user for username and password.
- Another Diffie-Hellman key exchange is performed for mutual key generation.
- The credentials are encrypted with AES and sent to the server for verification.
- The server decrypts the message and compares the stored hashed password with the user's entered password.
- After login, the client and server exchange a new key using Diffie-Hellman.
- The shared key, combined with the username, is used for encrypting messages with AES-128.
- The client sends encrypted messages, and the server decrypts and replies with encrypted responses.
- Add User: Admin can manually register a new user.
- Remove User: Admin can delete a registered user from
creds.txt
. - Update Credentials: Admin can update user credentials.
- View Credentials: Admin can view the list of all registered users and their credentials.
updated_creds.txt
: Stores user credentials in the format:email, username, hashed password, salt
.creds.txt
: Stores user credentials in the format:email, username, text password
.Client.cpp
: Contains the logic for user interaction, registration, login, and encrypted message exchange.Server.cpp
: Manages user credentials, verifies login details, and facilitates encrypted communication.HEADER.h
: COntains all the libraries that were required for smooth workflow.ADMIN.h
: Contains all the admin functions like:Remove user, Edit User, See User data, etc
.USER.h
: Contains all the user functions like:Register, Login, and Chatting
.key_exchange.cpp
: Throgh classes visualize how the things work in Deffie Helmin Key Exchange Mechanism.deffie_helmin.cpp
: This was additional code. Here you can enter the final shared key and brute force the P, alpha, a, b, and both the public keys for that shared key.
- C++
- SHA-256 for password hashing
- AES-128 bit CBC mode for encryption
- Diffie-Hellman for secure key exchange
To analyze traffic and validate the encryption process of your chat application, follow these steps:
-
Open Wireshark:
- Launch the Wireshark application on your computer.
-
Select Loopback Interface:
- In the main Wireshark window, look for the network interfaces list.
- Select the Loopback Interface (often labeled as
lo
orLoopback
).
-
Set Capture Filter (Optional):
- Although this is optional, setting a capture filter can help you focus on the relevant traffic.
- In the capture options, you can specify a filter, but it’s usually not necessary for loopback. You can proceed without it.
-
Start Capturing Packets:
- Click on the Start capturing packets button (the shark fin icon) to begin capturing traffic on the loopback interface.
-
Set Display Filter:
- Once the capture starts, in the display filter bar (located at the top), enter the following filter:
ip.addr == 127.0.0.1
- This filter will show only the packets that are transmitted to and from the localhost.
- Once the capture starts, in the display filter bar (located at the top), enter the following filter:
-
Perform Chat Actions:
- While Wireshark is capturing packets, initiate a chat between the client and server. Send some messages to generate traffic.
- Ensure that both the client and server applications are running simultaneously.
-
Stop the Capture:
- After you've sent a few messages, return to Wireshark and click on the Stop capturing packets button (the red square icon).
-
Analyze Captured Packets:
- Review the captured packets in the main window.
- Click on individual packets to view their details in the packet details pane below.
- Check the protocols used (e.g., TLS/SSL) to verify that encryption is being utilized for your chat messages.
- You can expand the details for specific protocols (like TLS) to view more information about the encryption and any transmitted data.
-
Inspect Decrypted Data (if applicable):
- If your application is configured to log or display decrypted messages, compare the captured packets with what you see in the client and server console/logs to validate that the encryption and decryption processes are functioning correctly.
-
Export or Save Captured Data (Optional):
- If you need to share or review the captured packets later, go to File > Save As and choose a location to save the capture file.
- Highlight Encryption: Look for packets marked as encrypted (e.g., showing
TLS
orSSL
), which indicates that your chat messages are protected during transmission. - Use Expert Information: Wireshark has an "Expert Information" feature (found in the Analyze menu) that can help identify potential issues or noteworthy events in the captured data.
- Implementing time-based key expiration for additional security.
- Encrypt
creds.txt
for even more secure storage like using a tool called crypter. - Adding more detailed logging and error-handling mechanisms.
- Clone this repository:
git clone https://github.com/yourusername/SecureChatSystem.git
- Command for execution:
g++ server.cpp -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl -lcrypto g++ client.cpp -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl -lcrypto
- Additional Notes: Please compile the server first so it will be up for listening otherwise the client alone would not be able to make a connection solely.
If you encounter any errors, bugs, or have suggestions for improvements, feel free to reach out to me.
You can contact me via email at: [email protected]
Errors and omissions are accepted!