📚 Encyclopedia

Security & Cryptography · updated 2026-11-09

E2E key management that never loses a key (keyring, backup, re-wrap)

e2ekey-backupkeyringpbkdf2logoutshared-preferencesmulti-device

In an end-to-end encrypted app the hard part is not the cipher, it is key custody: every device, every logout, every password change, and every reinstall is a chance to lose the only key that decrypts a conversation. TLDR lost keys several times before converging on the design below. The governing rule became: never discard a key pair, ever.

How keys got lost (the failure catalog)

  1. Each device generated its own identity (web storage and Android storage never shared it), so messages encrypted for the web key were garbage on the phone and vice versa.
  2. The backup was wiped on every launch. The app upserted its public key at startup with a public-only payload, and the server's public-only branch set encrypted_private_key = NULL. A later "fix" removed a client flag but not the server null, so cross-device restore never had anything to restore.
  3. A stale "already uploaded" flag in local prefs predated the backup feature and short-circuited the upload forever. Errors in the upload were also swallowed.
  4. Logout destroyed unbacked keys: keys were "preserved" and then reset() wiped them because the restore ran before the reset.
  5. A singleton's _initialized guard survived logout, so the next login skipped the backup-migration path entirely.
  6. A debug reinstall wiped app data on a real phone. See Debug installs wipe app data, and recovering it with Android Auto Backup.

The design that holds

Local storage rules

Residual limits (inherent to E2E)

Admin password resets

An admin who sets a new password directly in the database leaves every wrap under the old password, so the user's next fresh device would rotate identity. The server can fix that only if some password that opens an existing wrap is known (for example the previous password from an earlier admin reset): export the archive, unwrap with the old password and check the result matches the published public key, re-wrap under the new password with a fresh salt and nonce, round-trip it, then append it as a new archive row and update the canonical bundle (public key unchanged). Back up the key rows first. Without a known old password this is impossible by design; the fallback is a login on a device that still holds the raw key (self-heal), or rotation. On TLDR this was done once with a one-off Dart tool using the same cryptography package as the app (2026-11-07); its copy lives in tldr project memory.

Operating procedures

See also

Linked from

Sources: tldr memory (feature-dm-keyring, feature-dm-key-backup, plan-dm-archive-rekey, release-v1.31.0-audit, incident-dm-key-wipe-recovery, feature-change-password, history-v122-v128, completed-work), post #1892, post #1893