Skip to content

sahar-hub2/Security-Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Secure Overlay Chat Protocol (SOCP)

Version: 1.3 – Federated Secure Chat (Updated 23-10-2025)
Scope: Class-wide standard.

Overview

SOCP 1.3 implements a federated end-to-end encrypted chat network. Each user connects to a local server; servers exchange signed presence and messages through a trusted introducer. Every payload is cryptographically signed and encrypted.

Key features

  • End-to-end encryption (RSA-OAEP + SHA-256).
  • Digital signatures (RSA-PSS + SHA-256) for message authenticity.
  • Secure federation via introducer announcement channel.
  • Dynamic user advertisement and revocation between servers.
  • Command-driven CLI client (/tell, /all, /list, /sendfile, /quit).
  • Full cryptographic key persistence between sessions.
  • Optional sandboxed β€œbackdoored_version/”.

SOCP Compliance

This implementation conforms to SOCP v1.3 (Protocol Freeze: 17-09-2025).
Implemented mandatory features include:

  • RSA-4096 encryption (RSA-OAEP, SHA-256)
  • RSASSA-PSS signatures for message integrity
  • End-to-end encrypted direct messages (E2EE)
  • Server ↔ Server gossip for presence updates
  • Bootstrap introducer flow for network join
  • Public channel broadcasting and key distribution
  • Canonical JSON envelope format (one per WebSocket message)

Architecture Overview


                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚        Introducer        β”‚
                   β”‚ (user advertisements +   β”‚
                   β”‚  federation directory)   β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                       β”‚                        β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Server A    │◄─────►│   Server B     │◄──────►│   Server C     β”‚
β”‚ Local Users  β”‚       β”‚ Local Users    β”‚        β”‚ Local Users    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                        β”‚                         β”‚
     alice                    bob, carol                 dave
  • Introducer: maintains a live registry of known servers and users; all communications are signed.
  • Servers: verify incoming signatures, enforce local access control, and relay encrypted payloads.
  • Clients: hold private keys; only clients can decrypt or sign messages.

Security Model

  • Encryption β€” Messages are encrypted with the recipient’s RSA public key using RSA-OAEP (SHA-256).
  • Integrity β€” All messages are signed with RSA-PSS (SHA-256).
  • Verification β€” Servers verify signatures before routing.
  • Privacy β€” Servers cannot decrypt user payloads.
  • Replay Protection (Phase 3 planned) β€” Timestamp + nonce validation.

Project Structure

Security-Programming/
β”‚
β”œβ”€β”€ Documentation/
β”‚   β”œβ”€β”€ Developer Setup Guide (Phase 2).md   # Archived: Secure Overlay Chat Protocol overview
β”‚   β”œβ”€β”€ SCOP.pdf                             # Standard protocol agreement / reference document
β”‚   └── Reflection_Report/                   # Team reflection and lessons learned
β”‚      β”œβ”€β”€ Reflective Commentary.pdf         # General reflection: protocols, AI used, testing, peer review, member contributions
β”‚      └── Appendix/                         # Supporting documents
β”‚         β”œβ”€β”€ BACKDOOR_README(PoC).md
β”‚         β”œβ”€β”€ Peer_Review/                   # Holding for both received and given peer reviews
β”‚         └── Testing Report.pdf             # Testing approach and evidence
β”‚
β”œβ”€β”€ Implementation/
β”‚   β”œβ”€β”€ secure_version/                      # Secure implementation (production-ready)
β”‚   β”‚   β”œβ”€β”€ client.py                        # Client application (connects to server)
β”‚   β”‚   β”œβ”€β”€ server.py                        # Main server program handling connections
β”‚   β”‚   β”œβ”€β”€ keys.py                          # Key generation and management logic
β”‚   β”‚   β”œβ”€β”€ datavault.py                     # Local encrypted data storage and retrieval
β”‚   β”‚   β”œβ”€β”€ gen_introducer_keys.py           # Utility to generate introducer (server) keys
β”‚   β”‚   β”œβ”€β”€ introducers.yaml                 # Introducer list (server discovery info)
β”‚   β”‚   β”œβ”€β”€ requirements.txt                 # Python dependencies
β”‚   β”‚   β”œβ”€β”€ data_vault.sqlite                # SQLite database file
β”‚   β”‚   β”œβ”€β”€ data_vault.sqlite-shm            # SQLite shared memory file
β”‚   β”‚   β”œβ”€β”€ data_vault.sqlite-wal            # SQLite write-ahead log
β”‚   β”‚   β”œβ”€β”€ downloads/                       # Folder for downloaded files
β”‚   β”‚   └── __pycache__/                     # Compiled Python bytecode cache
β”‚
β”‚   β”œβ”€β”€ backdoored_version/                     # Insecure / vulnerable version
β”‚   β”‚   β”œβ”€β”€ quarantine/                         # PoC attack scripts (for testing/hardening)
β”‚   β”‚   β”‚   β”œβ”€β”€ poc_inject_unsigned_advert.py   # PoC: send unsigned USER_ADVERTISE to test BACKDOOR_TRUST_GOSSIP
β”‚   β”‚   β”‚   └── poc_weak_key_register.py        # PoC: register user with intentional 1024-bit RSA key
β”‚   β”‚   └── ...                                 # Same structure as secure_version but with flaws
β”‚
β”œβ”€β”€ Testing/
β”‚   β”œβ”€β”€ test_cases/
β”‚   β”‚   β”œβ”€β”€ test_client.py                   # Tests for client-side behavior
β”‚   β”‚   β”œβ”€β”€ test_server.py                   # Tests for server-side operations
β”‚   β”‚   β”œβ”€β”€ test_keys.py                     # Tests for key handling and persistence
β”‚   β”‚   β”œβ”€β”€ test_integration.py              # Full integration tests (end-to-end)
β”‚   β”‚   β”œβ”€β”€ test_security_hardening.py       # Security hardening tests for secure_version
β”‚   β”‚   └── __pycache__/                     # Cached test bytecode
β”‚
└── README.md                                # Entry point (this file)


βš™οΈ Setup & Installation

Requirements

  • Python 3.11+ recommended.
  • Linux/Ubuntu dev container (this workspace uses Ubuntu 24.04.2 LTS).
  • Install dependencies via requirements.txt:
    • pytest
    • pytest-asyncio
    • websockets
    • pyyaml
    • cryptography
# from Implementation/secure_version/
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

Setup Instructions

1. Navigate to the Project Directory:

cd Security-Programming

2. Create and Activate a Virtual Environment: macOS/Linux:

python3 -m venv .venv
source .venv/bin/activate

Windows (PowerShell):

python -m venv venv
venv\Scripts\activate

3. Install Dependencies:

python -m pip install --upgrade pip
python -m pip install -r Implementation/secure_version/requirements.txt

4. Generate keys
Before the first run, generate the introducer’s RSA keys and configuration file:

cd Implementation/secure_version
python gen_introducer_keys.py

Run Instructions

1. Start the Introducer

cd Implementation/secure_version
python3 server.py --id 11111111-1111-4111-8111-111111111111 --name introducer1 --port 9001 --introducer

Expected output:

loaded existing keys
[keys] Loaded keys for introducer1 β†’ .keys/introducer1.priv.pem / .pub.pem
[vault] SQLite database initialised and public channel ready.
[11111111-1111-4111-8111-111111111111] Listening on ws://127.0.0.1:9001

2. Start Server A and Server B

cd Implementation/secure_version
python3 server.py --name serverA --port 8764
python3 server.py --name serverB --port 8765

Expected output:

loaded existing keys
[keys] Loaded keys for serverA β†’ .keys/serverA.priv.pem / .pub.pem
[bootstrap] OK via ws://127.0.0.1:9001 β†’ assigned_id=53e96a0e-f124-4013-a0e9-f5e8df110b9b
[bootstrap] Using server ID: 53e96a0e-f124-4013-a0e9-f5e8df110b9b
[vault] SQLite database initialised and public channel ready.
[53e96a0e-f124-4013-a0e9-f5e8df110b9b] Listening on ws://127.0.0.1:8764

3. Start Clients

cd Implementation/secure_version
python3 client.py --user alice --server ws://127.0.0.1:8764 
python3 client.py --user bob --server ws://127.0.0.1:8765

Expected output:

loaded existing keys
Connected to ws://127.0.0.1:8764 as alice (id=ee5966e5-e61d-40e0-a398-6ce2b807931d)
[bootstrap] learned SERVER pubkey for serverA (53e96a0e-f124-4013-a0e9-f5e8df110b9b)

Once connected, each server advertises its local users to others through the introducer.

Example Scenario

Step 1: List active users
On Alice’s terminal:

/list

Expected output:

Connected users:
- bob (ce4732e1-fc12-4c62-a89a-74d5a915b93d)

Step 2: Send an encrypted message

/tell bob Hello Bob, this is a secure message!

Alice’s client:

  • Encrypts with Bob’s public key (RSA-OAEP, SHA-256).
  • Signs message with Alice’s private key (RSA-PSS, SHA-256).
  • Sends to Server A β†’ Introducer β†’ Server B.
    Bob’s client decrypts and displays:
alice (ee5966e5-e61d-40e0-a398-6ce2b807931d): Hello Bob, this chat is secure!

Supported commands: /tell, /all, /list, /sendfile, /quit

Troubleshooting

Issue Cause Fix
Address already in use Port conflict Change --port argument
cryptography build failed Missing system headers macOS: brew install openssl β†’ re-install deps
Connection refused Server not started or wrong port Verify introducer + server ports match
UnicodeDecodeError Non-UTF8 payload Delete old keys and restart
β€œNo active users” shown Introducer not reachable Ensure introducer is running first

Testing

To verify that the system functions correctly, you can run all automated tests using pytest.
These tests cover individual modules (client.py, server.py, keys.py) as well as end-to-end message exchange.

Run All Tests

From the root directory:

pytest -v

Note: Ensure that all required dependencies and environment variables are properly set up before running the tests.

Backdoor Disclaimer

The backdoored_version/ directory is provided for educational and testing purposes only.
It intentionally includes insecure patterns to illustrate common vulnerabilities; it is not intended for production use and should be run only in isolated, controlled environments.
For demonstrations or any live testing, we recommend using the secure_version/ implementation.

Author:

Developed by group 12 for the University of Adelaide Security Programming course, 2025.

MEMBERS:

  1. Debasish Saha Pranta (a1963099, debasishsaha.pranta@student.adelaide.edu.au)
  2. Samin Yeasar Seaum (a1976022, saminyeasar.seaum@student.adelaide.edu.au)
  3. Abidul Kabir (a1974976, abidul.kabir@student.adelaide.edu.au)
  4. Sahar Alzahrani (a1938372, sahar.alzahrani@student.adelaide.edu.au)
  5. Mahrin Mahia (a1957342, mahrin.mahia@student.adelaide.edu.au)
  6. Maria Hasan Logno (a1975478, mariahasan.logno@student.adelaide.edu.au)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7

Languages