đ Inside MemCloudâs Secure Peer Authentication: How Devices Safely Share RAM Over LAN
Source: Dev.to
When I released MemCloud (a distributed RAM engine for macOSâŻ&âŻLinux), the biggest question I got was:
âIsnât letting other devices store your RAM risky? How is it secured?â
Below is a deepâdive into the authentication, encryption, and trust model behind MemCloud â written for engineers who love protocols, threat models, and cryptographic design. This post focuses purely on the SecurityâŻ&âŻAuthentication layer.
(If youâre new to MemCloud, see the intro blog â this assumes familiarity.)
Threat Model
| Threat | Example |
|---|---|
| Impersonation | Rogue device pretends to be a trusted peer |
| MITM Attack | Attacker intercepts or mutates handshake traffic |
| Replay Attack | Reusing old handshake messages |
| Unauthorized Memory Access | Device silently joins the cluster |
| Session Hijacking | Stealing or predicting traffic keys |
MemCloudâs protocol addresses all of them.
Identity Keys
Every device has a longâterm identity keypair stored at:
~/.memcloud/identity_key
- Algorithm: Ed25519 (fastâŻ+âŻsecure)
- Purpose: Only used to sign handshake transcripts â never for encryption.
This behaves like a device certificate without the complexity of PKI.
Authentication Flow (NoiseâŻXX)
MemCloud uses an authentication flow inspired by the Noise Protocol Framework, specifically the Noise_XX pattern, chosen because:
- Both sides begin unauthenticated
- Supports TrustâOnâFirstâUse (TOFU)
- Offers mutual authentication
- Ensures forward secrecy
Simplified Handshake
A â B : eA, nonceA
B â A : eB, nonceB
A â B : identity proof (encrypted)
B â A : identity proof (encrypted)
eA and eB are ephemeral X25519 public keys.
Each handshake message is hashed into a transcript:
H = Hash(H || message)
This prevents replay, downgrade, and crossâsession attacks, and the transcript is later fed into key derivation.
Key Derivation & Identity Proof
-
Compute the shared secret:
shared_secret = DH(eA, eB) -
Derive the session key:
session_key = HKDF(shared_secret + transcript_hash) -
Each device signs the transcript hash with its longâterm identity key:
signature = Sign(TranscriptHash, IdentityKey)- The signature is encrypted, bound to the transcript, and cannot be replayed.
- If verification fails, the connection is closed immediately.
Traffic Encryption
Final traffic keys are derived as shown above and used with ChaCha20âPoly1305 AEAD, which is perfect for highâspeed LAN communication.
Trusted Peers
Trusted peers are stored in:
~/.memcloud/trusted_devices.json
Future connections to a known peer:
- Remain cryptographically authenticated
- Skip interactive approval
- Cannot be silently spoofed or replaced
What Happens When Auth Fails?
MemCloud rejects the session if any of the following occur:
- Identity signature fails
- Transcript mismatch occurs
- Handshake is malformed
- Device is untrusted
- The consent layer blocks authorization
Rejected peers cannot:
- Read your RAM
- Receive block data
- Join the cluster
- Impersonate a previous peer
Why Not TLS?
TLS is powerful but not ideal for a P2P LAN memory engine:
- MemCloud aims for zeroâconfig; Noise provides that out of the box.
- Desired latency is subâ10âŻms; Noiseâs lightweight binary protocol is faster.
- Requirements such as mutual authentication, identity hiding, forward secrecy, and TOFU are naturally satisfied by the Noise pattern.
Test Results
| Attack Attempt | Result |
|---|---|
| Replay | Blocked via transcript mismatch |
| MITM | Blocked (identity proof mismatch) |
| Impersonation | Blocked (signature invalid) |
| Downgrade attempt | Impossible |
| Payload tampering | Blocked (MAC failure) |
So far the protocol has held up extremely well in realâworld LAN conditions.
Planned Improvements
- đ Trust revocation broadcasting
- đĽ GUI trust manager
- đĄ Optional hardwareâbacked identity keys
- đ Session resumption
- đŚ Encrypted replication across peers
Contributors are welcomed.
Resources
- Authentication Code:
memnode/src/net/auth - Main Repository:
- Documentation:
- CLI Trust Manager:
memcli trust
MemCloud may look simple on the surfaceââdevices sharing RAM over LANââbut underneath is a carefully engineered secure protocol designed to make that actually safe.
If youâd like a followâup on the P2P binary protocol, memory isolation model, quota enforcement, or zeroâcopy streaming design, just let me know!