A multi-component encrypted communication platform built for the ST5062CEM Programming and Algorithm 2 coursework.
BlackBox is a secure dead drop system — users deposit encrypted messages that recipients can retrieve without sender and receiver ever communicating directly. Intelligence agencies use this technique to prevent interception.
| Feature | Implementation |
|---|---|
| Session Encryption | AES-256-CBC with HMAC-SHA256 (encrypt-then-MAC) |
| Key Exchange | Diffie-Hellman (RFC 3526 Group 14, 2048-bit prime) — custom implementation |
| Forward Secrecy | New DH keypair generated every connection |
| Identity | RSA-1024 keypair per user — custom Miller-Rabin prime generation |
| Replay Attack Prevention | Custom hash-table Nonce Registry (300s TTL) |
| DoS Prevention | Custom Token Bucket rate limiter (per-IP) |
| Tamper Detection | HMAC-SHA256 on every message |
| Audit Log | SHA-256 linked blockchain — tamper-evident |
| Data at Rest | All message bodies AES-encrypted before DB storage |
| Self-Destruct | Messages forensically wiped from DB after retrieval |
blackbox/
├── core/
│ ├── crypto_engine.py # DH, AES, RSA, NonceRegistry, TokenBucket
│ └── database.py # SQLite + AuditChain (blockchain log)
├── server/
│ └── server.py # Multi-threaded TCP server
├── client/
│ └── client_lib.py # Client library
├── tests/
│ └── test_blackbox.py # 30+ unit + integration tests
├── blackbox_gui.py # Main GUI (Tkinter)
└── requirements.txt
pip install cryptography pytest# Launch the full GUI (starts server internally)
python blackbox_gui.py- CONNECT — Start server, register/login
- DEAD DROP — Compose and deposit encrypted messages
- INBOX — List and retrieve drops
- SERVER INTEL — Live stats, user list, rate limiter status
- AUDIT CHAIN — View and verify blockchain audit log
python -m pytest tests/test_blackbox.py -vTests cover:
- DH key exchange (shared secret agreement, forward secrecy)
- AES encryption/decryption, tamper detection, wrong-key rejection
- RSA key generation, encrypt/decrypt, sign/verify
- Miller-Rabin primality test
- Nonce Registry replay attack detection (including thread-safety)
- Token Bucket rate limiting and refill
- Envelope (full crypto pipeline) round-trip
- Audit chain integrity and tamper detection
- Database CRUD + self-destruct behaviour
- Full client-server integration (register → login → drop → retrieve)
- NonceRegistry: Custom polynomial hash table with chaining (not Python dict)
- TokenBucket: Custom per-IP rate limiter with time-based refill
- AuditChain: Custom linked-list blockchain with SHA-256 block hashing
- DiffieHellman: Full DH implementation over 2048-bit RFC 3526 prime
- RSAKeyPair: Custom Miller-Rabin prime generation, modular inverse via Extended Euclidean Algorithm
main
├── feature/crypto-engine
├── feature/server
├── feature/client
├── feature/gui
├── feature/database
└── feature/tests
- RFC 3526: More Modular Exponential (MODP) Diffie-Hellman groups
- NIST SP 800-38A: AES-CBC mode specification
- HMAC: RFC 2104
- Miller-Rabin: Probabilistic primality testing algorithm
- DoD 5220.22-M: Data sanitisation standard (forensic erasure)