A console-based secure chat system implementing Confidentiality, Integrity, Authenticity, and Non-Repudiation (CIANR) using AES-128, RSA, Diffie-Hellman, and X.509 certificates.
Deadline: Monday, 17th Nov, 2025, 11:59 AM (noon)
GitHub: https://github.com/AhmedMufti/infosec3.git
pip install -r requirements.txt# Option 1: Automated
python setup_database.py
# Option 2: Manual
mysql -u root -p < database/schema.sqlpython scripts/gen_ca.py
python scripts/gen_cert.py server
python scripts/gen_cert.py clientCreate .env file:
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=securechat
SERVER_HOST=localhost
SERVER_PORT=9999# Terminal 1 - Start Server
python server.py
# Terminal 2 - Start Client
python client.pypython server.pyExpected Output:
Connected to database: securechat
Server listening on localhost:9999
New connection from ('127.0.0.1', 54321)
Control plane: Certificates exchanged and validated
User registered: alice (alice@example.com)
Key agreement: Session key established
Data plane: Starting encrypted chat
[alice]: Hello, this is a test message
python client.pyExpected Output:
Connected to server localhost:9999
Control plane: Certificates exchanged and validated
1. Register
2. Login
Enter choice (1/2): 1
Email: alice@example.com
Username: alice
Password: ********
Registration successful!
Key agreement: Session key established
Data plane: Starting encrypted chat
Type messages and press Enter to send
Type 'quit' to end the session
Hello, this is a test message
[Server]: Message 1 received
quit
Session receipt generated: transcripts/client_alice_*.txt
CREATE DATABASE securechat;
USE securechat;mysql -u root -p < database/schema.sqlpython setup_database.pypython test_db.pyClient Input:
1. Register
Email: alice@example.com
Username: alice
Password: testpass123
Server Output:
User registered: alice (alice@example.com)
Key agreement: Session key established
Client Output:
Registration successful!
Key agreement: Session key established
Client Input:
Hello, this is encrypted!
How are you?
quit
Server Output:
[alice]: Hello, this is encrypted!
[alice]: How are you?
Client Output:
[Server]: Message 1 received
[Server]: Message 2 received
Session receipt generated
python run_all_tests.py# Certificate validation
python test_cert_validation.py
# Database setup
python test_db.py
# Invalid certificate
python test_invalid_cert.py
# Tampering detection
python test_tampering.py
# Replay attack
python test_replay.py
# Non-repudiation
python test_non_repudiation.pySee TESTING_GUIDE.md for detailed testing instructions.
.
├── server.py # Server implementation
├── client.py # Client implementation
├── crypto_utils.py # Cryptographic utilities
├── scripts/
│ ├── gen_ca.py # CA generation
│ └── gen_cert.py # Certificate generation
├── database/
│ └── schema.sql # MySQL schema
├── certs/ # Certificates (not committed)
├── transcripts/ # Session transcripts (not committed)
├── test_*.py # Test scripts
├── requirements.txt # Dependencies
├── README.md # This file
├── FILE_PURPOSE.md # File purpose explanation
└── TESTING_GUIDE.md # Testing instructions
- Root CA creation (
scripts/gen_ca.py) - Server/client certificate issuance (
scripts/gen_cert.py) - Mutual certificate validation
- Invalid certificate rejection
- MySQL database setup
- Encrypted credential transmission
- Salted password hashing:
SHA256(salt || password) - Certificate + credential verification
- DH key exchange after login
- Session key derivation:
K = Trunc16(SHA256(Ks)) - Unique session keys per session
- AES-128 encryption with PKCS#7 padding
- Sequence numbers (replay protection)
- Timestamps
- SHA-256 hashing
- RSA digital signatures
- Message verification
- Session transcripts
- Transcript hashing
- Signed receipts
- Offline verification
- Confidentiality: AES-128 encryption
- Integrity: SHA-256 + RSA signatures
- Authenticity: X.509 certificate validation
- Non-Repudiation: Signed session receipts
- Replay Protection: Sequence number enforcement
- Ensure certificates are generated:
python scripts/gen_ca.py - Check certificate files exist in
certs/directory
- Verify MySQL is running
- Check database exists:
python test_db.py - Verify
.envfile has correct credentials
- Check server is running
- Verify port 9999 is available
- Check firewall settings
- FILE_PURPOSE.md - Explains each file's purpose and assignment goals
- TESTING_GUIDE.md - Detailed testing instructions for all required tests
- README.md - This file (main documentation)
- GitHub repository (private, ≥10 commits)
- MySQL schema + sample records
- README.md (this file)
- Report
- Test Report
- Wireshark screenshots
- All test evidence (invalid cert, tampering, replay, non-repudiation)
Muhammad Ahmed Mufti - i22-1088
Academic use only.