Skip to main content

๐Ÿช The Secret Meeting Room

Secure Group Chat with Multiple Layersโ€‹

In 20 minutes: Real-world group messaging tutorial
Prerequisite: Basic AES encryption


๐ŸŽฏ The Simple Storyโ€‹

Alice, Bob, and Charlie want a secure group chat.

Problem: Messages sent over the internet, can Eve read them?

Solution: Multiple layers of protection:

Message: "Meet at 5pm"

Layer 1 (AES): "Meet at 5pm" โ†’ "x7k!m$#L"
Layer 2 (Signal): "x7k!m$#L" โ†’ "$9x!mL#k7"
Layer 3 (MLS): "Meet at 5pm" โ†’ "Z$mk!7xL$"
Layer 4 (DK): "Z$mk!7xL$" โ†’ "P!z$#mL"

Eve sees: "P!z$#mL"
Eve tries: "I don't have Alice's password + Bob's ratchet + Group secrets!"

Result: "P!z$#mL" = Gibberish! Eve gives up!

๐Ÿง  Mental Modelโ€‹

Hold this picture in your mind:

Secure Group Chat (Nested Protection):

Layer 4 (Outermost): DH Handshake
โ”œโ”€ "Alice and Bob agree on a secret"
โ”œโ”€ "Only their devices can derive this"
โ””โ”€ Eve doesn't have either device!

Layer 3: MLS (Meeting Room):
โ”œโ”€ "Alice, Bob, Charlie can all chat together"
โ”œโ”€ "Group secret known only to members"
โ””โ”€ "Eve can't join the meeting room!"

Layer 2: Signal (Phone Booth):
โ”œโ”€ "Every message gets a new key"
โ”œโ”€ "Old keys deleted (forward secrecy)!"
โ””โ”€ "Eve can't read old messages!"

Layer 1 (Innermost): AES (Safe Deposit):
โ”œโ”€ "Each message also has password protection"
โ””โ”€ "Eve would need every message's password!"

Result: Like a castle with moat + guards + safe!

๐Ÿ“Š How It Works Togetherโ€‹

Why all these layers?

  • AES (innermost): Final password protection
  • Signal (middle): Forward secrecy for messages
  • MLS (middle): Group membership and context
  • DH (outermost): Initial key establishment

๐ŸŽญ The Story: Castle with Multiple Defensesโ€‹

Eve wants to read Alice, Bob, and Charlie's conversation:

Castle Defense Systemโ€‹

Eve's Attack 1: Try just reading
Castle says:
โŒ Outer Lock: DH (need devices!)
Even if Eve has Alice's phone โ†’ DH protects without her phone!

Eve's Attack 2: Try intercepting messages
Castle says:
โŒ Layer 2 Signal: Forward secrecy!
Even if Eve steals phone after message โ†’ Key deleted!

Eve's Attack 3: Try joining the group
Castle says:
โŒ Layer 3 MLS: Group access!
Eve isn't a member โ†’ Can't read!

Eve's Attack 4: Stealing encrypted messages
Castle says:
โŒ Layer 1 AES: Password needed!
Eve doesn't have Alice's every password!

Defense in Depthโ€‹

Layer 1 (AES): 1 in 100 chance to break  
Layer 2 (Signal): 1 in 1,000 chance to break
Layer 3 (MLS): 1 in 1,000,000 chance to break
Layer 4 (DH): 1 in 1,000,000,000 chance to break

Eve's chances to break ALL layers:
1/100 ร— 1/1,000 ร— 1/1,000,000 ร— 1/1,000,000
= 1/1,000,000,000,000,000,000

That's 1 in a QUADRILLION!

Even if Eve breaks one layer...

Scenario: Quantum computer breaks AES

Ciphertext: "P!z$#mL"
โ†“
Eve quantum computer attacks: BREAKS AES!
โ†“
Eve still needs: Signal + MLS + DH...

Still protected:
โŒ Signal (forward secrecy)
โŒ MLS (group access)
โŒ DH (devices)

โš™๏ธ Setting Up Multiple Layersโ€‹

Complete Exampleโ€‹

import {
CascadingCipherManager,
AESCipherLayer,
DHCipherLayer,
SignalCipherLayer,
MLSCipherLayer
} from "cryptography/CascadingCipher";

// 1. Create manager
const manager = new CascadingCipherManager();

// 2. Add layers in ORDER (bottom-to-top):
// AES first (simple, no dependencies)
manager.addLayer(new AESCipherLayer());

// DH second (key exchange)
const dhLayer = new DHCipherLayer();
dhLayer.initialize({
aliceKey: aliceDHKeyPair.privateKey,
bobKey: bobDHKeyPair.privateKey
});

manager.addLayer(dhLayer);

// Signal third (forward secrecy)
const signalWasm = await loadSignalWasm();
const signalState = await createDoubleRatchetState();
manager.addLayer(new SignalCipherLayer(signalWasm, signalState));

// MLS fourth (group security)
const mlsManager = new MLSManager("alice@example.com");
await mlsManager.initialize();
await mlsManager.createGroup("team-chat");
manager.addLayer(new MLSCipherLayer(mlsManager, "team-chat"));

Encrypting a Messageโ€‹

// Bob wants to send: "Meeting at 5pm"
const message = "Meeting at 5pm";
const plaintext = new TextEncoder().encode(message);

const keys = {
"AES-GCM-256": { password: "my-password" },
"DH-AES-GCM": {
privateKey: aliceDHKeyPair.privateKey,
publicKey: bobDHKeyPair.publicKey
},
"X3DH-DoubleRatchet": { doubleRatchetState },
"ML": { mlsManager, groupId: "team-chat" }
};

// CASCADING ENCRYPTION HAPPENS HERE!
const encrypted = await manager.encrypt(plaintext, keys);

Decrypting a Messageโ€‹

// Charlie receives the message
const keys = {
"AES-GCM-256": { /* all the same keys */ },
"DH-AES-GCM": { /* all the same keys */ },
"X3DH-DoubleRatchet": { /* all the same keys */ },
"ML": { mlsManager, groupId: "team-chat" }
};

// CASCADING DECRYPTION HAPPENS HERE!
const decrypted = await manager.decrypt(encrypted, keys);

const message = new TextDecoder().decode(decrypted);
// "Meeting at 5pm"

๐ŸŽฎ Try It Yourselfโ€‹

Details

Question 1: What's the order of decryption for AES + Signal + MLS? Answer: REVERSE of encryption! Since encryption was AES โ†’ Signal โ†’ MLS, decryption is MLSโปยน โ†’ Signalโปยน โ†’ AESโปยน. You can't decrypt AES first because Signal still scrambled the message! So: MLS โ†’ Signal โ†’ AES


Question 2: If Eve steals Charlie's phone, how many layers does she need to break?

Answer: Even if Eve has Charlie's phone, she would need:

  1. Charlie's AES password (she might guess it!)
  2. Charlie's DH private key AND Bob's DH private key
  3. Charlie's and Bob's Signal double ratchet states
  4. Charlie's and Bob's MLS group secrets

That's 4 layers to break. And even if she gets 1, 2, or 3 layers broken, layer 4 might still protect the message (like the quantum-resistant DH layer)!


Question 3: What happens to the conversation if Eve breaks one layer but not any others?

Answer: It depends WHICH layer!

If Eve breaks the innermost (AES): She can read raw messages but only the ones without additional layers! If the message has 4 layers and she breaks AES but not the other 3 layers, the data she gets is still scrambled by Signal + MLS + DH. She has the message body ("Meeting at 5pm") but can't make sense of it because it's still encrypted by layers 2, 3, and 4!

If Eve breaks just Signal but not AES/MLS/DH: They can read plaintext from AES but without double ratchet keys they can't understand which message belongs to which ratchet!

If Eve breaks MLS but not AES/Signal/DH: They can decrypt DH but not the group structure of MLS, so they can read messages but not know WHO sent them!

Each layer protects different things, but they're all needed together for complete security!


๐Ÿ’ก Real-World Scenario: Corporate Messagingโ€‹

Scenario: Company uses cascading cipher for secure internal messages

Threats:

  1. Quantum computers breaking AES in the future
  2. Current attacks on Signal's double ratchet
  3. Compromised MLS groups
  4. Malicious insider compromising passwords

Cascading cipher provides:

Quantum resistance: ML-KEM to protect from future threats
Forward secrecy: Signal protects from key exposure after compromise
Group membership: MLS protects from unauthorized members joining
Password protection: AES protects against weak passwords
Key establishment: DH protects the initial key exchange

Result: Breach in one layer โ‰  Breach of all!

โœ… Quick Checkโ€‹

**Can you explain defense in depth to a 5-year-old?

Try saying this out loud:

"A lockbox is good, but a lockbox inside a safe, inside a vault, inside a fortress with multiple guards is even better! Even if someone breaks ONE lock, they still have 3 MORE to break! That's why we use cascade layers. Breaking one doesn't break everything!"


๐ŸŽ“ Key Takeawaysโ€‹

โœ… Multiple layers = Defense in depth
โœ… Each layer protects differently = Compromise in one โ‰  All!
โœ… Order matters = Encrypt AESโ†’Signalโ†’MLS, Decrypt MLSโปยนโ†’Signalโปยนโ†’AESโปยน
โœ… Quantum-resistant layers = Future-proof your data
โœ… Forward secrecy = Past messages stay secret
โœ… Group access = Only members can join the chat
โœ… Compromise resilience = One layer broken โ‰  game over


๐ŸŽ‰ What You'll Learn Nextโ€‹

Now you know how to build a secure group chat! But there's more:

๐ŸŽ„ Continue: Maximum Security

We'll add ML-KEM for quantum protection - the ultimate layer!


Now you can build secure group chats. Next: Maximum security with quantum protection!