Skip to content

Commit eedefde

Browse files
authored
Update Project_Architecture.md
1 parent df322e3 commit eedefde

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

docs/Project_Architecture.md

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
**CipherMQ** is a high-performance, secure message broker designed to transmit encrypted messages between senders and receivers using a push-based architecture. It ensures **zero message loss** and **exactly-once delivery** through robust acknowledgment mechanisms, with messages temporarily held in memory (except for logs and receiver output). The system leverages **hybrid encryption** (RSA + AES-GCM) for message confidentiality and authenticity and **Transport Layer Security (TLS)** for secure client-server communication.
55

66
This version introduces TLS support, enhancing transport-layer security, as implemented in `connection.rs` and `main.rs`, with configuration via `config.toml`. The project consists of:
7-
- **Server** (`main.rs`): A Rust-based message broker for routing and delivering messages over TLS or TCP.
7+
- **Server** (`main.rs`): A Rust-based message broker for routing and delivering messages over TLS.
88
- **Sender** (`Sender.py`): A Python script that encrypts and sends messages in batches with retry logic.
99
- **Receiver** (`Receiver.py`): A Python script that receives, decrypts, deduplicates, and stores messages.
1010

1111
This document provides a comprehensive overview of the architecture, covering server, clients, TLS, encryption, and acknowledgment mechanisms.
1212

1313
## 2. Architecture Overview
14-
CipherMQ operates as a message broker with **queues** and **exchanges**, supporting both TLS and TCP connections via a text-based protocol. Key features include:
14+
CipherMQ operates as a message broker with **queues** and **exchanges**, supporting both TLS connections via a text-based protocol. Key features include:
1515
- **TLS Support**: Secures client-server communication using `tokio-rustls` (server) and Python’s `ssl` module (clients), configurable via `config.toml`.
1616
- **Hybrid Encryption**: Combines RSA for session key encryption and AES-GCM for message encryption and authentication.
1717
- **Zero Message Loss**: Sender and server retries with acknowledgments ensure reliable delivery.
@@ -61,32 +61,17 @@ The server is the core of CipherMQ, managing message routing, delivery, and secu
6161
- **reset_stats**: Clears `message_status` and `request_times`.
6262

6363
#### 3.1.3. Connection Management (`connection.rs`, `main.rs`)
64-
- **Protocol**: Text-based protocol over TLS or TCP (e.g., `publish <exchange> <routing_key> <message_json>`).
64+
- **Protocol**: Text-based protocol over TLS (e.g., `publish <exchange> <routing_key> <message_json>`).
6565
- **TLS Support**:
6666
- Uses `tokio-rustls` for TLS connections via `TlsConnection` and `TlsAcceptor`.
6767
- Loads certificates and keys via `load_tls_config` using `rustls-pemfile`.
6868
- Configured in `config.toml` with `connection_type`, `cert_path`, and `key_path`.
69-
- **TCP Support**: Fallback for non-TLS connections using `TcpStream`.
7069
- **Asynchronous Handling**: Tokio’s `TcpListener` and `tokio::select!` manage concurrent connections.
7170
- **Acknowledgment**:
7271
- Sends `ACK <message_id>` to sender after queuing.
7372
- Sends `ACK_CONFIRMED <message_id>` to receiver after acknowledgment.
7473
- **Error Handling**: Logs errors via `tracing` (e.g., `TLS handshake failed`) and sends error messages to clients.
7574

76-
#### 3.1.4. Architectural Features
77-
- **Reliability**: Retries unacknowledged messages and checks for duplicates.
78-
- **Concurrency**: `DashMap` and `RwLock` ensure thread-safe operations.
79-
- **Flexibility**: Supports TLS or TCP via `config.toml`.
80-
- **Logging**: Detailed logs for connection, message, and ACK events.
81-
82-
#### 3.1.5. Configuration (`config.rs`)
83-
- **Config Struct**:
84-
- `connection_type: String`: `tls` or `tcp`.
85-
- `address: String`: Listening address (e.g., `127.0.0.1:5672`).
86-
- `cert_path: Option<String>`: Path to `server.crt` (TLS only).
87-
- `key_path: Option<String>`: Path to `server.key` (TLS only).
88-
- **Loading**: Reads `config.toml` using `toml::from_str`.
89-
9075
### 3.2. Sender (`Sender.py`)
9176
The sender encrypts and sends messages in batches with retry logic.
9277

@@ -148,19 +133,6 @@ The receiver retrieves, decrypts, and stores messages.
148133
2. Message is encrypted with AES-GCM, producing `ciphertext`, `nonce`, and `tag`.
149134
3. Receiver decrypts session key with private key (`receiver_private.pem`) and message with AES-GCM, verifying `tag`.
150135

151-
### 3.5. TLS Implementation
152-
- **Server-Side** (`connection.rs`, `main.rs`):
153-
- Uses `tokio-rustls` to establish TLS connections via `TlsAcceptor`.
154-
- Loads `server.crt` and `server.key` with `load_tls_config` using `rustls-pemfile`.
155-
- Configured via `config.toml` (`connection_type="tls"`, `cert_path`, `key_path`).
156-
- Falls back to `TcpStream` for `connection_type="tcp"`.
157-
- **Client-Side** (`Sender.py`, `Receiver.py`):
158-
- Uses `ssl.SSLContext` with `PROTOCOL_TLS_CLIENT` and `verify_mode=ssl.CERT_REQUIRED`.
159-
- Loads `server.crt` from `server_cert_path` in `config.json`.
160-
- Disables hostname verification for self-signed certificates (`check_hostname=False`, `server_hostname="localhost"`).
161-
- **Security**: Encrypts transport layer, complementing hybrid encryption for messages.
162-
- **Configuration**: Dynamic switching between TLS and TCP via `config.toml`.
163-
164136
## 4. Component Interactions
165137
1. **Key and Certificate Generation**:
166138
- `RSA.py` or OpenSSL generates `receiver_public.pem` and `receiver_private.pem` for hybrid encryption.

0 commit comments

Comments
 (0)