Skip to main content

End-to-End Encryption

Muti Metroo provides end-to-end encryption for all stream data, ensuring that only the ingress (entry) and exit agents can read the payload. Transit agents forward encrypted data without being able to decrypt it.

Overview

Stream data is encrypted using modern cryptographic primitives:

  • Key Exchange: X25519 elliptic curve Diffie-Hellman
  • Encryption: ChaCha20-Poly1305 authenticated encryption (AEAD)
  • Key Derivation: HKDF-SHA256

This provides:

PropertyDescription
ConfidentialityOnly ingress and exit can read stream data
IntegrityTampering is detected and rejected
Forward SecrecyEach stream uses ephemeral keys
Transit OpacityTransit agents see only ciphertext

How It Works

Key Exchange Flow

When a stream is opened, ingress and exit agents perform an ephemeral key exchange:

Session Key Derivation

After the ECDH key exchange, both sides derive identical session keys:

  1. Shared Secret: Computed via X25519 ECDH
  2. Key Derivation: HKDF-SHA256 with stream ID as context
  3. Nonce Management: Direction-aware counters prevent nonce reuse
SharedSecret = X25519(local_private, remote_public)
SessionKey = HKDF-SHA256(SharedSecret, "muti-metroo-e2e" || stream_id || initiator_pub || responder_pub)

Encryption Details

Each STREAM_DATA frame payload is encrypted:

ComponentSizeDescription
Nonce12 bytesCounter + direction bit
CiphertextVariableEncrypted data
Auth Tag16 bytesPoly1305 authentication tag

Total overhead: 28 bytes per frame

Nonce Structure

Nonces are constructed to be unique and direction-aware:

Nonce (12 bytes):
- Bytes 0-7: 64-bit counter (incremented per message)
- Byte 8: Direction bit (0 = initiator->responder, 1 = responder->initiator)
- Bytes 9-11: Zero padding

This ensures:

  • No nonce reuse within a stream
  • Different nonces for each direction
  • Safe concurrent bidirectional encryption

Security Properties

Forward Secrecy

Each stream uses freshly generated ephemeral keys. Compromising long-term keys does not reveal past stream data.

Authenticated Encryption

ChaCha20-Poly1305 provides:

  • Confidentiality: Data is encrypted
  • Integrity: Any modification is detected
  • Authentication: Origin is verified via shared secret

Transit Opacity

Transit agents:

  • Forward encrypted payloads unchanged
  • Cannot derive the shared secret (no private keys)
  • See only destination metadata (address/port)

Key Zeroing

Ephemeral private keys are zeroed immediately after computing the shared secret, minimizing exposure window.

What Is Encrypted

DataEncryptedNotes
Stream payload (STREAM_DATA)YesApplication data
Destination address/portNoRequired for routing
Stream IDNoRequired for multiplexing
Frame headersNoRequired for framing

Public Key Distribution

Each agent has a long-term X25519 keypair stored alongside its identity:

  • Private key: {data_dir}/agent_key (0600 permissions)
  • Public key: {data_dir}/agent_key.pub (0644 permissions)

Public keys are distributed via NODE_INFO_ADVERTISE frames, allowing agents to verify identity.

Protocol Changes

STREAM_OPEN

Added field:

  • EphemeralPubKey (32 bytes): Initiator's ephemeral X25519 public key

STREAM_OPEN_ACK

Added field:

  • EphemeralPubKey (32 bytes): Responder's ephemeral X25519 public key

NODE_INFO_ADVERTISE

Added field:

  • PublicKey (32 bytes): Agent's long-term X25519 public key

Performance Impact

MetricImpact
CPU~5-10% increase for encryption/decryption
LatencyNegligible (stream open adds ~1ms)
Bandwidth+28 bytes per frame
Memory+64 bytes per stream (session key state)

ChaCha20-Poly1305 is highly optimized and runs at several GB/s on modern CPUs.

Threat Model

Protected Against

ThreatProtection
Passive eavesdropping at transitData encrypted
Compromised transit agentCannot decrypt payloads
Replay attacksNonce prevents replay
Message tamperingPoly1305 detects modification
Future key compromiseForward secrecy via ephemeral keys

Not Protected Against

ThreatMitigation
Compromised ingress/exitHost security hardening
Traffic analysisUse constant-rate padding (not implemented)
Metadata leakageDestination visible for routing

Troubleshooting

Decryption Failures

If streams fail with decryption errors:

  1. Version mismatch: Ensure all agents are updated
  2. Corrupted frames: Check network reliability
  3. Clock skew: Verify system time is synchronized

Key Generation Issues

# Verify keypair exists
ls -la {data_dir}/agent_key*

# Regenerate if corrupted (will change identity)
rm {data_dir}/agent_key*
muti-metroo init -d {data_dir}

Next Steps