102 lines
9.8 KiB
Markdown
102 lines
9.8 KiB
Markdown
# Encryption plan: OpenPGP mail encryption for ep-mail
|
||
|
||
Status: **Phases 1–3 and the desktop parts of 4–6 are implemented.** Android OpenPGP support and an independent human security review are still open. Automated review findings and their fixes are documented in [SECURITY_REVIEW.md](./SECURITY_REVIEW.md); see [TODO.md](./TODO.md) for follow-up work.
|
||
|
||
## 1. Format: OpenPGP with PGP/MIME (RFC 3156)
|
||
|
||
| Option | Pros | Cons |
|
||
|---|---|---|
|
||
| **OpenPGP** | Interoperates with Thunderbird, Proton, Mailvelope, GnuPG and K-9/OpenKeychain. No certificate authority needed. | Key verification is manual. |
|
||
| S/MIME | Native in Outlook and Apple Mail. | Needs CA-issued certificates; poor fit for personal accounts. |
|
||
|
||
Decision: OpenPGP only for v1; S/MIME may follow later.
|
||
|
||
- Library: [OpenPGP.js](https://github.com/openpgpjs/openpgpjs) (`openpgp`), pure JS, usable in Electron and the Android WebView.
|
||
- Messages: `multipart/encrypted` (`application/pgp-encrypted` + `application/octet-stream`), signed and encrypted together. Attachments go inside the encrypted payload.
|
||
- Keys: Curve25519 (legacy EdDSA/ECDH, OpenPGP v4). OpenPGP.js' default native Ed25519 keys are rejected by GnuPG 2.5, so the widely supported format is used.
|
||
- Also detect and decrypt legacy inline PGP (`-----BEGIN PGP MESSAGE-----`).
|
||
- Out of scope for v1: Autocrypt headers and Web Key Directory. Desktop key-server lookup and publication are described in section 9.
|
||
|
||
## 2. Key handling
|
||
|
||
**Private keys**
|
||
- One or more keys per account; never stored unprotected and never sent anywhere.
|
||
- Always protected by a passphrase (minimum 8 characters). On desktop the whole key store is also encrypted with Electron `safeStorage` (the OS credential store).
|
||
- Android: wrap with a hardware-backed Android Keystore key; optional biometric unlock (Phase 4).
|
||
- The passphrase is cached only in memory for a configurable time, then wiped (Phase 4). It is never written to disk.
|
||
- Export as ASCII-armored files; a revocation certificate is generated when a key is created and can be exported after unlocking.
|
||
- Deleting or exporting a private key requires the passphrase. Desktop users can change a key's passphrase by verifying the current one and entering the new one twice; the public key and revocation certificate are preserved.
|
||
|
||
**Public keys**
|
||
- Per-account contact keyring: address, fingerprint, trust level, source.
|
||
- Sources: file import, attached to received mail, key-server lookup, and own key attached to outgoing mail.
|
||
- Trust: trust on first use, shown with the fingerprint, plus an explicit "verified" state after out-of-band comparison. Warn loudly when a known contact's key changes.
|
||
|
||
## 3. User experience
|
||
|
||
- Compose: lock toggle, on by default when every recipient has a key. Never silently downgrade; offer to send unencrypted or cancel.
|
||
- Reader: status line such as "Encrypted and signed by X (verified)" or a warning for bad/unknown signatures.
|
||
- Message list: lock icon for encrypted mail.
|
||
- Settings: **Encryption keys** (Phase 1) for create, import, export, delete.
|
||
- Interactions: search and rules cannot read encrypted bodies (subject/sender stay plaintext); do not cache decrypted bodies; run link warnings and attachment previews only after decryption; encrypt the Sent copy to the sender's own key too.
|
||
|
||
## 4. Threat model and limits
|
||
|
||
- Protects content from the mail server and network observers.
|
||
- Does not protect metadata (sender, recipients, subject, timestamps).
|
||
- A compromised device, or a stolen key plus passphrase, defeats it.
|
||
- Losing the key means losing access to old encrypted mail; backups are the user's responsibility.
|
||
|
||
## 5. Phases
|
||
|
||
| Phase | Scope | Status |
|
||
|---|---|---|
|
||
| 1 | Foundation: OpenPGP.js, passphrase-protected key store (OS credential store on desktop), generate/import/export/delete, revocation certificate, unit tests, Settings UI | Done (desktop) |
|
||
| 2 | Receive: detect PGP/MIME and inline PGP, decrypt on open, verify signatures, status UI, missing-key and wrong-passphrase handling | Done (desktop) |
|
||
| 3 | Send: public-key keyring and contact import, encrypt and sign on compose, encrypted Sent copy, downgrade warnings | Done (desktop) |
|
||
| 4 | Trust and polish: fingerprint verification, key-change warnings, passphrase cache timeout, Android Keystore and biometric unlock | Desktop done; Android open |
|
||
| 5 | Interop testing with Thunderbird and GnuPG, large attachments, multiple recipients, corrupted payloads | Automated, GnuPG and manual Thunderbird interop checks done |
|
||
| 6 | Docs, security review, release | Docs and release done; independent review open |
|
||
|
||
## 6. Phase 1 implementation notes
|
||
|
||
- [desktop/pgp-keystore.cjs](./desktop/pgp-keystore.cjs): platform-independent key store with an injected storage backend.
|
||
- [desktop/main.cjs](./desktop/main.cjs): wraps the store with `safeStorage` (`pgp-keys.enc` in the user data folder) and exposes `pgp:*` IPC handlers; key files are saved through native dialogs.
|
||
- [desktop/preload.cjs](./desktop/preload.cjs): exposes `daybreakMail.pgp`.
|
||
- [pgp-ui.js](./pgp-ui.js): Settings → **Encryption keys**. Hidden on platforms without a key store (Android until Phase 4).
|
||
- Tests: `npm test` ([tests/pgp-keystore.test.cjs](./tests/pgp-keystore.test.cjs)).
|
||
|
||
## 7. Phases 2–5 implementation notes
|
||
|
||
- [desktop/pgp-mail.cjs](./desktop/pgp-mail.cjs): detects PGP/MIME and inline PGP, decrypts, verifies signatures (inside encrypted mail, `multipart/signed` and cleartext), builds encrypted/signed PGP/MIME messages, and keeps an in-memory passphrase cache.
|
||
- [desktop/pgp-keystore.cjs](./desktop/pgp-keystore.cjs): also stores contact public keys with trust levels (`unknown`, `trusted`, `verified`) and the passphrase-memory setting.
|
||
- Encrypted messages appear in the list as "Encrypted message"; they are decrypted on demand (`pgp:decrypt-message`) and the plaintext is never cached on disk. Attachments are read from the decrypted payload.
|
||
- Compose shows Encrypt and Sign options. Encrypt turns on by default when every recipient has a key; if a key is missing the app asks before sending unencrypted. Encryption happens before the message is sent or queued offline, so passphrases and plaintext never enter the outbox. The Sent copy is also encrypted to the sender's own key.
|
||
- Multiple outgoing attachments are included in the OpenPGP MIME payload and encrypted/signed together with the body. Android does not yet implement OpenPGP.
|
||
- Attachment selection has no app-enforced aggregate size cap; local storage capacity and mail-provider limits still apply.
|
||
- A signature from a key that differs from the one on file for the sender is flagged as a changed key.
|
||
- Interop: [tests/pgp-gnupg-interop.test.cjs](./tests/pgp-gnupg-interop.test.cjs) runs against a real GnuPG (skipped when it is not installed).
|
||
- Tests: [tests/pgp-mail.test.cjs](./tests/pgp-mail.test.cjs) (round trips, several recipients, tampering, key changes, large attachments, inline PGP).
|
||
- Limits: subjects and headers are not encrypted; drafts are stored unencrypted; opening encrypted attachments requires the passphrase to be remembered (see Settings → Encryption keys).
|
||
## 8. Risks
|
||
|
||
- Android WebView performance with large attachments (may need native handling).
|
||
- Key loss (backup flow, revocation certificate).
|
||
- User confusion about trust; keep states simple: unknown, trusted, verified.
|
||
- Decrypted HTML must not leak through remote content; blocking remote images by default should land first.
|
||
- Security-critical code: have it reviewed by someone with cryptography experience before relying on it.
|
||
|
||
## 9. Public key servers (desktop)
|
||
|
||
The desktop Settings → Encryption keys view can search and publish through:
|
||
|
||
- **keys.openpgp.org** using its [VKS API](https://keys.openpgp.org/about/api/). Email lookup only returns keys whose email addresses have been verified. After an upload, ep-mail requests verification for the key's primary email address and reports whether verification is pending or already complete.
|
||
- **keys.mailvelope.com** using HKP over HTTPS as documented by the [Mailvelope key server](https://github.com/mailvelope/keyserver#hkp-api). The server sends its own email-verification message after accepting a key upload.
|
||
- **Custom servers** using an explicitly selected HKP or VKS protocol and an HTTPS base URL. Custom server configuration is saved with the encrypted OpenPGP settings.
|
||
|
||
All built-in and custom servers start disabled. Users enable each server explicitly; disabled servers are not contacted for lookup and cannot be used for publication. Searching is user-triggered and checks every enabled server; ep-mail does not perform background lookups while composing. Search addresses are disclosed to each enabled server. Results identify their source servers and duplicate keys are merged by fingerprint. The main process validates returned OpenPGP keys before showing them, and adding a result uses the existing key-replacement confirmation. Discovered keys enter the contact keyring with `unknown` trust; server publication or lookup is never treated as fingerprint verification.
|
||
|
||
Publishing targets one explicitly selected enabled server, not all enabled servers. The destination is shown in the Settings control and named again in a native confirmation before upload. The confirmation identifies the server, email address, and fingerprint and explains that the email/key association becomes public and may be retained. Only the selected key's public material is uploaded; private keys and passphrases are never sent. A successful upload may still require the user to complete email verification before the key becomes searchable. Android key-server support is not included because Android OpenPGP support is not implemented.
|
||
|
||
Custom servers are limited to HTTPS HKP/VKS endpoints, redirects are rejected, and lookup responses are size-limited. Key-server data remains subject to the server's availability, privacy practices, and verification policy; users should independently compare fingerprints before trusting a key.
|