Skip to content

Security: masterconi/encrypted-messanger

Security

docs/SECURITY.md

Security Model and Threat Analysis

Threat Model

This document defines the explicit threat model for the Ultra-Secure Messenger system.

Assumed Adversaries

  1. Nation-State Attackers

    • Sophisticated, well-funded
    • Access to advanced cryptanalysis
    • Potential for traffic analysis
    • Long-term persistence
  2. Malicious Servers

    • Compromised server infrastructure
    • Insider threats
    • Government coercion
    • Server-side attacks
  3. Compromised Clients

    • Malware on client devices
    • Physical device access
    • Side-channel attacks
    • Memory scraping
  4. Network Attackers

    • Man-in-the-middle (MITM)
    • Traffic analysis
    • Replay attacks
    • Denial of service

Security Goals

  1. Confidentiality: Messages remain secret from unauthorized parties
  2. Integrity: Messages cannot be modified without detection
  3. Authentication: Participants can verify each other's identity
  4. Forward Secrecy: Past messages remain secure after key compromise
  5. Post-Compromise Security: Future messages become secure after key update
  6. Deniability: Sender can plausibly deny sending (optional)

Threat Analysis

T1: Passive Network Eavesdropping

Threat: Adversary monitors network traffic between clients and server.

Mitigation:

  • All messages encrypted end-to-end
  • Server cannot decrypt messages
  • Traffic analysis resistance (message padding, timing)
  • TLS/WebSocket encryption for transport

Residual Risk: Low

  • Adversary can observe metadata (message sizes, timing)
  • Cannot read message contents

T2: Active Man-in-the-Middle (MITM)

Threat: Adversary intercepts and modifies traffic.

Mitigation:

  • Cryptographic authentication (Ed25519 signatures)
  • Handshake authentication prevents MITM
  • Message authentication codes (MACs)
  • Certificate pinning (recommended)

Residual Risk: Low

  • Requires compromise of identity keys
  • Detected by authentication failures

T3: Compromised Server

Threat: Server infrastructure is compromised.

Mitigation:

  • Zero-knowledge architecture (server cannot decrypt)
  • No plaintext message storage
  • Stateless design (minimal data exposure)
  • Rate limiting prevents abuse

Residual Risk: Medium

  • Adversary can observe metadata
  • Can perform denial of service
  • Cannot read message contents

T4: Compromised Client

Threat: Client device is compromised (malware, physical access).

Mitigation:

  • Forward secrecy (past messages protected)
  • Secure key storage (OS secure enclave when available)
  • Automatic key rotation
  • Minimal key exposure

Residual Risk: High (unavoidable)

  • Adversary can read current messages
  • Can impersonate user
  • Past messages remain protected (forward secrecy)

T5: Replay Attacks

Threat: Adversary replays old messages.

Mitigation:

  • Timestamps in handshake
  • Message sequence numbers
  • Nonces in handshake
  • Clock skew tolerance

Residual Risk: Low

  • Replayed messages detected and rejected

T6: Key Compromise Impersonation (KCI)

Threat: Adversary compromises long-term key and impersonates user.

Mitigation:

  • Ephemeral keys in handshake
  • Double Ratchet provides post-compromise security
  • Key rotation
  • Trust-on-first-use with upgrade paths

Residual Risk: Medium

  • Initial compromise allows impersonation
  • Future messages become secure after key update

T7: Traffic Analysis

Threat: Adversary analyzes message patterns, sizes, timing.

Mitigation:

  • Message padding (future enhancement)
  • Timing randomization (future enhancement)
  • Minimal metadata exposure

Residual Risk: Medium

  • Some metadata leakage unavoidable
  • Message contents remain protected

T8: Denial of Service (DoS)

Threat: Adversary disrupts service availability.

Mitigation:

  • Rate limiting per client
  • Connection limits
  • Graceful degradation
  • Distributed architecture

Residual Risk: Medium

  • DoS attacks possible but mitigated
  • Service can degrade gracefully

T9: Side-Channel Attacks

Threat: Adversary exploits timing, power, or other side channels.

Mitigation:

  • Constant-time operations where possible
  • Secure memory handling
  • Minimal key exposure

Residual Risk: Medium

  • JavaScript/TypeScript limitations
  • Best-effort mitigations

T10: Metadata Leakage

Threat: Adversary learns who is talking to whom, when.

Mitigation:

  • Minimal metadata collection
  • No message content logging
  • Encrypted message storage
  • Client-side message deletion

Residual Risk: Medium

  • Some metadata necessary for operation
  • Cannot be completely eliminated

Cryptographic Security

Encryption

  • Algorithm: AES-256-GCM
  • Key Size: 256 bits
  • IV: 96 bits (12 bytes), randomly generated
  • Authentication: Built-in GCM authentication tag

Security Level: 128 bits (quantum-resistant: 256 bits)

Key Exchange

  • Algorithm: X25519 (Curve25519)
  • Key Size: 256 bits
  • Security Level: ~128 bits (quantum-resistant: 256 bits)

Digital Signatures

  • Algorithm: Ed25519
  • Key Size: 256 bits
  • Security Level: ~128 bits (quantum-resistant: 256 bits)

Key Derivation

  • Algorithm: HKDF-SHA-256
  • Output: 256 bits
  • Security Level: 256 bits

Random Number Generation

  • Source: crypto.getRandomValues() (Web Crypto API)
  • Quality: Cryptographically secure
  • Platform: OS-provided CSPRNG

Forward Secrecy

Double Ratchet Protocol

The system implements the Double Ratchet protocol for forward secrecy:

  1. Per-Message Keys: Each message uses a unique encryption key
  2. Key Evolution: Keys evolve with each message
  3. Chain Keys: Separate chains for sending and receiving
  4. Key Deletion: Old keys deleted after use

Properties:

  • Compromise of current key does not reveal past messages
  • Compromise of past key does not reveal future messages
  • Automatic key rotation

Key Rotation

  • Trigger: Every message (via Double Ratchet)
  • Method: HKDF-based key derivation
  • Storage: Keys stored only in memory
  • Deletion: Keys zeroed after use (best-effort)

Post-Compromise Security

Recovery Mechanism

After key compromise:

  1. New Handshake: Establishes new shared secret
  2. Key Update: Ratchet state updated
  3. Future Messages: Protected by new keys
  4. Past Messages: Remain protected (forward secrecy)

Recovery Time: Immediate (next message after key update)

Security Guarantees

What We Guarantee

  1. End-to-End Encryption: Messages encrypted, server cannot decrypt
  2. Forward Secrecy: Past messages secure after key compromise
  3. Authentication: Participants authenticated via cryptographic signatures
  4. Integrity: Message tampering detected via MACs
  5. Replay Protection: Replayed messages rejected

What We Don't Guarantee

  1. Metadata Privacy: Some metadata (timing, sizes) may leak
  2. Traffic Analysis Resistance: Patterns may be observable
  3. Deniability: Messages are authenticated (not deniable)
  4. Perfect Forward Secrecy: Requires perfect key deletion (best-effort)
  5. Side-Channel Resistance: Limited by JavaScript/TypeScript

Security Best Practices

For Users

  1. Secure Key Storage: Use OS secure enclave when available
  2. Regular Updates: Keep software updated
  3. Device Security: Use device encryption, strong passwords
  4. Trust Verification: Verify identity keys out-of-band
  5. Key Backup: Secure backup of identity keys (encrypted)

For Operators

  1. Server Security: Harden server infrastructure
  2. Monitoring: Monitor for abuse and attacks
  3. Updates: Keep dependencies updated
  4. Audits: Regular security audits
  5. Incident Response: Plan for security incidents

Known Limitations

  1. JavaScript Memory: Cannot guarantee secure memory zeroing
  2. Timing Attacks: Some operations may have timing variations
  3. Metadata: Some metadata leakage unavoidable
  4. Client Compromise: Cannot protect against fully compromised client
  5. Quantum Computing: Not quantum-resistant (but can be upgraded)

Security Audit Recommendations

Before production deployment:

  1. Cryptographic Review: Audit all cryptographic implementations
  2. Protocol Review: Verify protocol correctness
  3. Code Review: Security-focused code review
  4. Penetration Testing: Adversarial testing
  5. Fuzz Testing: Automated fuzz testing
  6. Side-Channel Analysis: Timing and power analysis

Incident Response

If Keys Are Compromised

  1. Revoke Identity: Generate new identity key
  2. Notify Contacts: Inform contacts of compromise
  3. Re-establish Sessions: Perform new handshakes
  4. Audit Logs: Review for suspicious activity

If Server Is Compromised

  1. Isolate: Isolate compromised servers
  2. Rotate Keys: Rotate server identity keys
  3. Notify Users: Inform users of incident
  4. Forensics: Investigate compromise
  5. Remediate: Fix vulnerabilities

Compliance and Standards

  • NIST Guidelines: Follows NIST cryptographic guidelines
  • OWASP: Addresses OWASP security concerns
  • Signal Protocol: Inspired by Signal Protocol security model
  • Noise Framework: Based on Noise Protocol Framework principles

There aren’t any published security advisories