Skip to content

Commit b90b9c6

Browse files
author
test
committed
Implemented proper encryption for cold storage / snapshots // TODO: Read snapshots data
1 parent 89e3982 commit b90b9c6

7 files changed

Lines changed: 276 additions & 36 deletions

File tree

Cargo.lock

Lines changed: 116 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ openssl = { version = "0.10", features = ["vendored"] }
2020
chrono = "0.4.40"
2121
jsonwebtoken = "9.3.1"
2222
log = "0.4.27"
23+
rand_core = "0.9.3"
24+
aes-gcm = "0.10" # AES-GCM (AEAD) implementation
25+
aead = "0.5" # traits for Aead, KeyInit, etc.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ With its advanced real‑time update capabilities, DynaRust pushes live changes
4747
- **Enforcement:** All `PUT` and `DELETE` operations require an `Authorization` header. The server verifies that the requester matches the record’s owner.
4848

4949
- **Cluster Security:**
50-
- Each node should have a JWT_SECRET set, without this env var the node won't even start
51-
- Each node must present a **secret token** (set via the `CLUSTER_SECRET` environment variable) to join the cluster, ensuring only trusted nodes participate.
50+
- At compile time a SHA256 encryption key is embeded in the compiled binary (if that changes somehow in the future (recompile binary with different key) you won't be able to load the table, steps to properly compile are: run bash encryption.sh && cargo build --release and distribute only the binary under target/release/ to your nodes);
51+
- Each node should have a JWT_SECRET set, without this env var the node won't even start
52+
- Each node must present a **secret token** (set via the `CLUSTER_SECRET` environment variable) to join the cluster, ensuring only trusted nodes participate.
5253

5354
- **Transport Security (HTTPS):**
5455
- **Easy Certificate Generation:**

encryption.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
KEY_FILE="encryption.key"
5+
KEY_SIZE=32 # 32 bytes = 256 bits
6+
7+
if [[ -e "$KEY_FILE" ]]; then
8+
echo "Error: $KEY_FILE already exists. Remove or rename it and retry."
9+
exit 1
10+
fi
11+
12+
# Method 1: Using /dev/urandom
13+
head -c "$KEY_SIZE" /dev/urandom > "$KEY_FILE"
14+
15+
# Alternatively, with OpenSSL:
16+
# openssl rand -out "$KEY_FILE" "$KEY_SIZE"
17+
18+
# Restrict file perms so only the owner can read/write
19+
chmod 600 "$KEY_FILE"
20+
21+
echo "Generated a $KEY_SIZE-byte key at $KEY_FILE (permissions 600)."

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async fn main() -> std::io::Result<()> {
163163
}
164164

165165
// Spawn the periodic cold save task.
166-
tokio::spawn(cold_save(state.clone(), 30));
166+
tokio::spawn(cold_save(state.clone(), 5));
167167

168168
// Initialize cluster data with dynamic membership.
169169
let mut initial_nodes = HashMap::new();

0 commit comments

Comments
 (0)