A console-based secure chat application demonstrating application-layer cryptography: PKI, Diffie-Hellman key exchange, AES encryption, RSA signatures, and non-repudiation through signed transcripts.
app/
├── client.py # Client implementation
├── server.py # Server implementation
├── crypto/ # Cryptographic primitives (AES, RSA, DH, PKI)
├── common/ # Protocol definitions and utilities
└── storage/ # Database and transcript management
scripts/
├── gen_ca.py # Root CA generation
└── gen_cert.py # Certificate issuance
tests/manual/ # Security testing scripts
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtCreate .env file with your MySQL credentials:
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_user
DB_PASSWORD=your_password
DB_NAME=securechat
SERVER_HOST=localhost
SERVER_PORT=5000Initialize the database:
python -m app.storage.db --initCreate root CA:
python scripts/gen_ca.py --name "SecureChat CA"Generate server certificate:
python scripts/gen_cert.py --cn server.local --out certs/serverGenerate bootstrap client certificate (used during registration):
python scripts/gen_cert.py --cn client.local --out certs/clientRequired files in certs/:
ca-cert.pem,ca-key.pemserver-cert.pem,server-key.pemclient-cert.pem,client-key.pem(bootstrap only)
python -m app.serverThe server listens on localhost:5000 by default.
python -m app.client --register --username alice --email alice@example.com --password alicepass123During registration:
- Server generates a per-user certificate with
CN=username - Client saves certificate to
certs/alice-cert.pemandcerts/alice-key.pem - Password is salted and hashed (SHA-256) before storage
python -m app.client --username alice --email alice@example.com --password alicepass123During login:
- Client loads user-specific certificate from
certs/alice-cert.pem - Server validates certificate CN matches username
- Diffie-Hellman key exchange establishes session key
After successful login:
- Type messages and press Enter
- Messages are AES-encrypted and RSA-signed
- Type
quitto end session and receive signed receipt
After ending a session:
- Transcript saved to
transcripts/client_SESSION_ID_TIMESTAMP.txt - Receipt saved to
receipts/receipt_SESSION_ID.json - Both can be verified offline using
tests/manual/verify_nonrepudiation.py
- Client and server exchange X.509 certificates
- Both validate against root CA (signature, expiry, CN/SAN)
- Per-user certificates: each user has
CN=username
- Registration: Client provides salt, server generates per-user certificate
- Login: Client requests salt, hashes password, server validates
- Passwords stored as
SHA256(salt || password)in MySQL
- Diffie-Hellman establishes session key
- Temporary key for auth, separate session key for chat
- Keys derived:
AES-128-key = SHA256(shared_secret)[:16]
- Messages encrypted with AES-128
- Each message signed with RSA (SHA-256 digest)
- Sequence numbers prevent replay attacks
- All messages logged to append-only transcript
- Server computes SHA-256 hash of transcript
- Server signs hash with private key
- Receipt proves both parties participated in conversation
| Property | Mechanism |
|---|---|
| Confidentiality | AES-128 encryption |
| Integrity | RSA-SHA256 signatures |
| Authenticity | PKI certificates + signatures |
| Non-repudiation | Signed transcripts + receipts |
| Replay protection | Sequence numbers |