A Combined Computer Security & Computer Networks Final Project
4Auth is a hardened authentication framework written in Python that enforces four identity factors before granting access:
- Password (bcrypt-hashed)
- TOTP (authenticator app)
- Face recognition (DeepFace + OpenCV)
- Device & context checks (MAC binding + time skew)
It uses a TLS-secured clientβserver architecture, an encrypted SQLite database, and a JSON-based protocol over sockets.
Core files:
server.pyβ TLS server, database, crypto, verification pipelineclient.pyβ TLS client, webcam capture, login/register/recovery flows
4Auth integrates objectives from:
- Multi-factor authentication
- Password hashing (bcrypt)
- Biometric verification (DeepFace)
- Symmetric encryption (Fernet/AES)
- Time-based One-Time Passwords (TOTP)
- Device identity checking (MAC binding)
- Enforcement of password policy
- Tamper-resistant time validation
- Full logging and auditability
- TCP socket communication
- TLS encryption layer
- Application protocol design
- JSON serialization
- Length-prefixed network framing
- Multi-threaded client handling
- Certificate-driven communication
- Hashed with bcrypt using per-user salt.
- Enforced password policy:
- Min 8 characters
- Must contain uppercase, digit, or special char
- Verified server-side in constant time.
- Server generates a new Base32 TOTP secret on registration.
- Stored encrypted via Fernet.
- A provisioning URI + QR code is returned to the client.
- User scans QR with Google/Microsoft Authenticator.
- Login uses a 6-digit TOTP verified via
pyotp.
- Client captures a webcam frame via OpenCV.
- Encodes JPEG β base64 β sends over TLS.
- Server decrypts stored face image.
- DeepFace performs a verification match.
- Requires real-face presence at login and recovery.
Somewhere You Are + When You Are
- Account locked to deviceβs physical MAC.
- Prevents replay or reuse on unregistered devices.
- Client sends UTC timestamp.
- Server fetches NTP time via
pool.ntp.org. - Rejects login if skew > 120 seconds.
- Prevents replay attacks and clock manipulation.
The server stores:
- Encrypted TOTP secret
- Encrypted facial template (PNG bytes)
- Bcrypt password hash
- Bound MAC address
| Field | Description |
|---|---|
username |
primary key |
password_hash |
bcrypt hash |
face_image_enc |
encrypted PNG |
totp_secret_enc |
encrypted Base32 |
mac_address |
bound device identity |
| Field | Description |
|---|---|
id |
autoincrement PK |
ts_utc |
server UTC timestamp |
username |
nullable user |
action |
login/register/recovery |
success |
1/0 |
detail |
message/details |
Every login, register, recovery attempt is logged.
- Raw TCP socket
- Wrapped fully in TLS 1.2+
- Certificate & private key:
cert.pem,key.pem
Each message uses:
[4-byte big-endian length][JSON payload]
This avoids partial reads and guarantees framing even inside TLS.
| Code | Meaning |
|---|---|
"100" |
Login |
"200" |
Register (admin-only) |
"300" |
Recover TOTP |
"310" |
Recover password |
"320" |
Recover face |
"330" |
Update MAC address |
Client sends β server responds with JSON containing:
status:"ok"or"error"message: human-readable text- Optional fields like
qr_png_b64orprovisioning_uri
Log in
Register Account (admin only)
Recovery Options
Exit
- Username
- Password
- 6-digit TOTP
- Face capture
- MAC + timestamp auto-attached
- Server returns success/failure
login()returns True/False
- Admin secret required
- Username, password
- Face capture + MAC
- Server returns TOTP QR + provisioning URI
Recover TOTP
Recover Password
Recover Face
Recover MAC
Each path requires a different combination of MFA components.
- Loads/creates
fernet.key - Creates/open SQLite DB
- Ensures tables exist
- Creates TLS context
- Listens on port 65432
- Spawns threads per client
- Enforce authentication logic
- Verify each MFA factor
- Handle secure storage of secrets
- Perform biometric matching
- Log every action
- Return structured JSON
python server.py
markdown Copy code
python client.py
4Auth is a complete, production-style authentication system demonstrating:
- Bcrypt password hashing
- DeepFace biometric authentication
- TOTP provisioning and verification
- Fernet-encrypted face and TOTP storage
- MAC address device binding
- Time-skew access protection
- End-to-end TLS communication
- Full logging of all security events
- Custom JSON protocol over sockets
- Secure clientβserver architecture
This project satisfies the learning objectives of Computer Security and Computer Networks, merging them into one cohesive final deliverable.
opencv-python numpy Pillow deepface pyotp qrcode bcrypt cryptography ntplib