You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**CipherMQ** is a secure, high-performance message broker designed for encrypted message transmission between senders and receivers using a push-based architecture. It leverages **hybrid encryption** (RSA + AES-GCM) for message confidentiality and authenticity, combined with **Mutual TLS (mTLS)** for secure client-server communication. The system ensures **zero message loss** and **exactly-once delivery** through robust acknowledgment mechanisms, with messages temporarily held in memory and routed via exchanges and queues.
12
+
**CipherMQ** is a secure, high-performance message broker designed for encrypted message transmission between senders and receivers using a push-based architecture. It leverages **hybrid encryption** (x25519 + AES-GCM-256) for message confidentiality and authenticity, combined with **Mutual TLS (mTLS)** for secure client-server communication. The system ensures **zero message loss** and **exactly-once delivery** through robust acknowledgment mechanisms, with messages temporarily held in memory and routed via exchanges and queues. Public keys are securely stored in an SQLite database with AES-GCM encryption, and receivers register their public keys with the server for secure distribution to senders.
13
13
14
-
This version introduces **TLS support**, enhancing security for client-server connections.
15
14
16
-
You can see some benchmarks regarding CipherMQ at [benchmark_report](benchmarks/benchmark_report.md). Initial architecture of CipherMQ is as follows:
15
+
16
+
Initial architecture of CipherMQ is as follows:
17
17
18
18
19
19
@@ -23,6 +23,8 @@ You can see some benchmarks regarding CipherMQ at [benchmark_report](benchmarks/
23
23
24
24
25
25
26
+
27
+
26
28
## Table of Contents
27
29
1.[Features](#features)
28
30
2.[Prerequisites](#prerequisites)
@@ -39,16 +41,17 @@ You can see some benchmarks regarding CipherMQ at [benchmark_report](benchmarks/
39
41
40
42
## Features
41
43
42
-
-**Mutual TLS (mTLS)**: Secure client-server communication with two-way authentication using X.509 certificates.
43
-
-**Hybrid Encryption**: RSA encrypts session keys, and AES-GCM ensures message encryption and authentication.
44
+
-**Mutual TLS (mTLS)**: Ensures secure client-server communication with two-way authentication using ECDSA P-384 certificates.
45
+
-**Hybrid Encryption**: Utilizes x25519 for session key encryption and AES-GCM-256 for message encryption and authentication.
46
+
-**Public Key Registration**: Receivers register their public keys with the server using the `register_key` command, which are securely stored and retrievable by senders via the `get_key` command.
44
47
-**Zero Message Loss**: Sender retries until server acknowledgment (`ACK <message_id>`), and server retries delivery until receiver acknowledgment (`ack <message_id>`).
45
48
-**Exactly-Once Delivery**: Receiver deduplicates messages using `message_id` to prevent reprocessing.
46
49
-**Batch Processing**: Sender collects and sends messages in batches, ensuring all queued messages are delivered.
47
50
-**Asynchronous Processing**: Built with Tokio for concurrent, high-performance connection handling.
48
51
-**Push-Based Messaging**: Messages are delivered to connected consumers.
49
52
-**Thread-Safe Data Structures**: Uses `DashMap` for safe multi-threaded operations.
50
53
-**Flexible Routing**: Supports exchanges and queues with routing keys for efficient message delivery.
51
-
-**Clear Acknowledgment Logging**: Both sender and receiver log ACKs for visibility (e.g., `✅ [SENDER] Server ACK received`and `✅ [RECEIVER] Server confirmed ACK`).
54
+
-**Secure Key Storage**: Public keys are encrypted with AES-GCM and stored in an SQLite database.
52
55
53
56
54
57
@@ -57,7 +60,8 @@ You can see some benchmarks regarding CipherMQ at [benchmark_report](benchmarks/
57
60
To run CipherMQ with TLS, you need:
58
61
-[Rust](https://www.rust-lang.org/): Version 1.56 or higher (for the server).
59
62
-[Python](https://www.python.org/): Version 3.8 or higher (for Sender and Receiver).
60
-
-[Key Generation](https://slproweb.com/products/Win32OpenSSL.html): Use OpenSSL or the provided `RSA.py` script to generate keys.
63
+
- Certificates Generation: Use the provided `generate_certs.py` script to generate mTLS certificates.
64
+
- Key Generation: Use the provided `key_maker.py` script to generate x25519 key pairs.
61
65
62
66
63
67
@@ -74,22 +78,13 @@ cd CipherMQ
74
78
cargo build --release
75
79
```
76
80
### 3. Generate mTLS Certificates
77
-
Generate a CA certificate, server certificate, and client certificate for mTLS:
81
+
Run the provided `generate_certs.py` script to generate CA certificates, server certificate, and client certificate for mTLS:
> **Note**: Store `ca.key` securely and do not distribute it. It is only used for certificate generation.
103
98
99
+
### 4. Generate x25519 Keys
104
100
105
-
106
-
107
-
108
-
### 4. Generate RSA Keys
109
-
Run the provided `RSA.py` script to generate RSA key pairs for hybrid encryption:
101
+
Run the provided `key_maker.py` script to generate x25519 key pairs for hybrid encryption for the receiver:
110
102
```bash
111
103
cd src/client
112
-
pip install pycryptodome
113
-
python RSA.py
104
+
python key_maker.py
114
105
```
115
-
This creates:
116
-
-`receiver_private.pem`: Receiver's private key for decryption.
117
-
-`receiver_public.pem`: Public key for sender encryption.
118
106
107
+
This creates:
108
+
-`receiver/certs/receiver_private.key`: Receiver's private key for decryption.
109
+
-`receiver/certs/receiver_public.key`: Public key for sender encryption.
119
110
120
111
121
112
@@ -124,41 +115,40 @@ This creates:
124
115
### Server Configuration
125
116
Create a `config.toml` file in the `CipherMQ` root directory:
126
117
```toml
118
+
[server]
127
119
connection_type = "tls"
128
120
address = "127.0.0.1:5672"
121
+
122
+
[tls]
129
123
cert_path = "certs/server.crt"
130
124
key_path = "certs/server.key"
131
125
ca_cert_path = "certs/ca.crt"
126
+
127
+
[database]
128
+
dbname = "public_keys.db"
129
+
130
+
[encryption]
131
+
aes_key = "YOUR_BASE64_ENCODED_32_BYTE_AES_KEY"
132
132
```
133
133
134
-
### Client Configuration
135
-
Create a config.json file in the src/client directory for Sender and Receiver, ensuring the following values are set:
136
-
```json
137
-
{
138
-
"exchange_name": "ciphermq_exchange",
139
-
"queue_name": "ciphermq_queue",
140
-
"routing_key": "ciphermq_key",
141
-
"server_address": "127.0.0.1",
142
-
"server_port": 5672,
143
-
"tls": {
144
-
"certificate_path": "certs/ca.crt",
145
-
"client_cert_path": "certs/client.crt",
146
-
"client_key_path": "certs/client.key",
147
-
"protocol": "PROTOCOL_TLS_CLIENT",
148
-
"verify_mode": "CERT_REQUIRED",
149
-
"check_hostname": false
150
-
}
151
-
}
134
+
> **Note**: Replace `YOUR_BASE64_ENCODED_32_BYTE_AES_KEY` with a 32-byte key encoded in base64. Generate it using:
135
+
```bash
136
+
openssl rand -base64 32
152
137
```
153
138
139
+
### Client Configuration
140
+
`config.json` file in both `sender/` and `receiver/` directories:`
141
+
154
142
> **Note**: Ensure `exchange_name`, `queue_name`, and `routing_key` match across Sender, Receiver, and server for proper message routing.
155
143
156
-
> **Security Note**: Restrict access to `server.key`, `client.key`, and `receiver_private.pem` (e.g., `chmod 600`).
144
+
> **Security Note**: Restrict access to `server.key`, `client.key`, and `receiver_private.key (e.g., `chmod 600`).
145
+
157
146
158
147
159
148
## Usage
149
+
160
150
### 1. Run the Server
161
-
Start the server with mTLS support:
151
+
Start the server with TLS support:
162
152
```bash
163
153
cd root
164
154
cargo run --release
@@ -167,46 +157,49 @@ cargo run --release
167
157
### 2. Run the Receiver
168
158
Start the receiver to subscribe to messages:
169
159
```bash
170
-
cd src/client
160
+
cd src/client/receiver
171
161
python Receiver.py
172
162
```
173
-
The receiver connects to the server via TLS, declares and binds to `ciphermq_queue`, decrypts messages, and saves them to `received_messages.jsonl`.
163
+
The receiver connects to the server via TLS, registers its public key using the `register_key` command, declares and binds to `my_queue`, decrypts messages, and saves them to `data/received_messages.jsonl`.
174
164
175
165
### 3. Run the Sender
176
-
Send encrypted messages in batches:
166
+
177
167
```bash
178
-
cd src/client
168
+
cd src/client/sender
179
169
python Sender.py
180
170
```
181
-
The sender encrypts messages using hybrid encryption, sends them in batches via `ciphermq_exchange` and `ciphermq_key`, and retries until acknowledgment.
182
-
171
+
The sender fetches the receiver's public key using the `get_key` command, encrypts messages using hybrid encryption, sends them in batches via `my_exchange` and `my_key`, and retries until acknowledgment.
183
172
184
173
185
174
## Architecture
186
175
187
176
CipherMQ is a message broker system with the following components:
188
-
-**Server** (`main.rs`, `server.rs`, `connection.rs`, `state.rs`, `config.rs`, `auth.rs`): A Rust-based broker that handles mTLS connections, message routing, and delivery using exchanges and queues.
189
-
-**Sender** (`Sender.py`): Encrypts messages with hybrid encryption (RSA + AES-GCM), sends them in batches, and ensures delivery with retries.
190
-
-**Receiver** (`Receiver.py`): Receives, decrypts, deduplicates, and stores messages in JSONL format, with acknowledgment retries.
177
+
-**Server** (`main.rs`, `server.rs`, `connection.rs`, `state.rs`, `config.rs`, `auth.rs`, `storage.rs`): A Rust-based broker that handles mTLS connections, message routing, and delivery using exchanges and queues. Public keys are encrypted with AES-GCM and stored in an SQLite database. The server supports the `register_key` command to store receiver public keys and the `get_key` command to provide them to senders.
178
+
-**Sender** (`sender.py`): Fetches receiver public keys using `get_key`, encrypts messages with hybrid encryption (x25519 + AES-GCM-256), sends them in batches, and ensures delivery with retries.
179
+
-**Receiver** (`receiver.py`): Registers its public key with the server using `register_key`, receives, decrypts, deduplicates, and stores messages in JSONL format, with acknowledgment retries.
191
180
-**mTLS Integration** (`auth.rs`, `connection.rs`): Supports secure two-way authentication using `tokio-rustls` and `WebPkiClientVerifier`.
192
-
-**Hybrid Encryption**: Combines RSA for session key encryption and AES-GCM for message encryption and authentication.
181
+
-**Hybrid Encryption**: Combines x25519 for session key encryption and AES-GCM-256 for message encryption and authentication.
182
+
-**Key Storage** (`storage.rs`): Public keys are encrypted with AES-GCM and stored in an SQLite database, accessible via `register_key` and `get_key` commands.
193
183
194
184
For a detailed architecture overview, see [CipherMQ Project Architecture](docs/Project_Architecture.md).
195
185
196
186
197
187
198
188
## Diagrams
199
189
The following diagrams, located in `docs/diagrams`, illustrate CipherMQ's architecture and mTLS flow:
200
-
-**[Sequence Diagram](docs/diagrams/Sequence_diagram.png)**: Shows the end-to-end message flow, including mTLS handshakes.
201
-
-**[Activity Diagram](docs/diagrams/Activity_Diagram.png)**: Details the operational flow, including mTLS connection setup.
190
+
-**[Sequence Diagram](docs/diagrams/Sequence_diagram.png)**: Shows the end-to-end message flow, including mTLS handshakes, public key registration, and hybrid encryption.
191
+
-**[Activity Diagram](docs/diagrams/Activity_Diagram.png)**: Details the operational flow, including mTLS connection setup, key registration, and message processing.
202
192
203
193
## Future Improvements
204
-
- Support standard protocols like AMQP or MQTT.
205
-
- Enable distributed server scaling.
206
-
- Replacing OpenSSL commands with specialized Rust libraries for generating keys and certificates.
207
-
- For generating a key to migrate from 2048-bit RSA to ECDSA(P-384)
194
+
- Support standard protocols like AMQP or MQTT for broader compatibility.
195
+
- Enable distributed server scaling for high availability.
196
+
- Replacing Python Script with specialized Rust libraries for generating keys and certificates.
208
197
- Implement certificate rotation and CRL/OCSP for enhanced security.
209
198
- Add support for Hardware Security Modules (HSM) for key management.
199
+
- Add persistent message storage to handle server restarts.
200
+
- Enhance monitoring with structured logging (optional reintroduction).
0 commit comments