Web platform · Security

CartelRed

End-to-end encrypted messaging where the server is architecturally incapable of reading your messages — client-side PGP, keys that never leave the device, and a zero-knowledge design enforced on both ends.

Role
Architect & sole developer
Stack
React · Vite · Tailwind · Firebase
Domain
End-to-end encrypted messaging
Status
Phase 5 complete
cartelred main window
Main window
E2E encrypted, server can't read
0 keys leave the device
QR identity exchange

The premise

"Zero knowledge" is a claim you can't make with a privacy policy — you have to make it architectural. In CartelRed, the encryption happens before the network request, which means Firestore only ever stores ciphertext. There's no plaintext to leak, subpoena, or accidentally log, because it never reached the server in the first place.

I built it as a PWA so it installs like an app, works on mobile and desktop, and gets push notifications — without a native codebase to maintain.

The non-negotiable constraints

  • No plaintext ever leaves the client. Message text and file data are encrypted locally before any network call.
  • Private keys never touch the server. They're generated on-device and stored in IndexedDB, not uploaded.
  • Zero-knowledge enforced by design. Client-side encryption isn't an option in the code — it's the only path.

Identity and keys

Each user generates an OpenPGP key pair. The public key goes to Firestore so others can encrypt to you. The private key stays on your device, wrapped in an encrypted envelope.

Identity is exchanged by QR code: your own code contains your user ID and public key fingerprint, and scanning a contact's code adds them to your trusted list. That makes fingerprint verification something you do in person, which is the only way it's actually meaningful.

Local key hardening

The current implementation stores the private key as an AES-GCM envelope rather than in plaintext:

  • Argon2id key derivation with conservative mobile parameters, targeting under 1.5 seconds to unlock on a mid-range phone.
  • PBKDF2 fallback at 150,000+ iterations on mobile and 200,000+ on desktop, for environments without WASM support.
  • The derived data key is never persisted — the decrypted private key lives in memory only, and is cleared on lock or page unload.

There's also a migration path: users with an older legacy key format get a one-time prompt to upgrade to the envelope format and re-upload an upgraded backup, with the old format retained during a grace period and rollback available via a feature flag.

Sending and receiving

Messages are encrypted with the recipient's public key and signed with the sender's private key. That means you get confidentiality (only the recipient can read it) and authenticity (the recipient can verify who sent it) from the same operation.

To send, the client fetches the recipient's public key, encrypts the plaintext, signs it, and uploads only the encryptedData and signature fields. To receive, the client listens on the messages collection, decrypts with the local private key, and verifies the sender's signature with their public key.

Encrypted to both parties

Messages are encrypted for the recipient and the sender. Without that, you'd lose your own message history the moment you signed out — a small detail that ruins otherwise good encrypted messengers.

File transfer

Files under 1 MB are encrypted as Base64 chunks and stored in a separate collection. Since the app is serverless, Firestore's onSnapshot acts as the transport — a real-time channel without running a real-time server. The UI shows a decrypting-in-progress indicator while a file arrives.

The repository also has P2P scaffolding: a drag-and-drop transfer zone and a signaling collection ready for WebRTC offer/answer exchange. The UI entry points exist; the full peer-to-peer path is deliberately left as the next phase rather than half-built.

Adaptive UI

One codebase serves both form factors. A responsive hook detects the viewport and swaps the shell:

  • Mobile — bottom navigation for chats, contacts, and settings, with the chat occupying the full screen.
  • Desktop — the classic two-column layout: contacts sidebar on the left, active conversation on the right.

Theming

Eight curated palettes ship with the app — Dark, Light, Deep Ocean, Ember Glow, Neon Pulse, Forest Dusk, Silk Steel, and Warm Canvas. Selecting one updates CSS variables globally and persists to local storage, with the picker previewing each palette using three color dots.

Adding a theme is a single record in the theme configuration, so the set is meant to grow.

Abuse resistance

An encrypted messenger still has to defend its own infrastructure. The invite system uses KMS-managed keys: token hashes are stored HMAC'd, payloads are AES-GCM encrypted, and invites have short TTLs with a single use.

Rate limits are enforced in pure, independently testable logic — 3 attempts per 10 minutes on login challenges, 20 per 5 minutes per user/IP on token minting, with an admin bypass. The rate-limit core is unit tested, including the exactly-at-the-limit case, because off-by-one bugs in rate limiting are how you either lock everyone out or let everyone in.

Log hygiene

A sanitized logging helper replaces direct error logging throughout, emitting only stage and error codes with hashed identifiers where needed. Tokens, signatures, passwords, and private keys are structurally prevented from reaching logs — not filtered out afterwards.

Secret management

Server-side secrets resolve through a layered abstraction: in-memory cache, then environment variables for development, then Google Secret Manager, with optional KMS unwrapping. Rotation is supported by carrying a current and previous HMAC key so signatures verify during the rotation window.

Push notifications

Optional FCM push notifies users of new messages and contact actions. The implementation uses a data-only payload strategy so notifications are styled by the app's own service worker — which avoids the duplicate-notification problem that plagues naive FCM setups, and keeps the branding consistent.

Users opt in from the settings toggle; the app then requests permission, registers the service worker, and stores an FCM token on the user record. Tokens are keyed rather than stored as a list, which supports multiple devices cleanly.

Phases

PhaseDelivered
1 — Initialization & authProject scaffold, Firebase setup, email/password and phone sign-in, key-presence routing.
2 — Cryptography layerKey generation and import, local private-key storage, QR identity, trusted contacts.
3 — Adaptive UIResponsive shell, bottom navigation on mobile, split-pane on desktop, theme system.
4 — Encrypted messagingEncrypt-sign-send pipeline, snapshot-based receive, in-memory decrypted state, signature verification.
5 — Files & P2P scaffoldingEncrypted file chunks, progress UI, WebRTC entry points and signaling collection.
Honest status

The repository describes this as a demo. In production you'd tune the Argon2id parameters per device class, enable proper key rotation, and verify fingerprints out of band. Those are named in the docs rather than glossed over — I'd rather list the remaining work than imply it's finished.

Related projects