Skip to content
CliprWiki

Data and encryption

What lives where, how keys are derived and how the vault works.

Storage (/data)

All data lives in the volume clipr-data, mounted at /data.

Path Contents Encrypted with
system.db Accounts, sessions, email tokens, settings, groups and invitations, mailboxes, fetch log, security log, SSO keys and grants SQLCipher, key server:system-db
exchange.db + exchange/ Intermediate storage for sharing: pairs and packets SQLCipher (server:exchange-db), packets additionally with AES-GCM per pair
stores/<uuid>/store.db Tickets, journeys, stacks, file index, the store's private X25519 key SQLCipher with the account's data key (DEK)
stores/<uuid>/files/ Original files and code images AES-256-GCM, key via HKDF from the DEK (store-files)
stores/<uuid>/inbox/ Sealed mail imports for locked vaults X25519 + HKDF + AES-GCM with the store's public key
.secret_key Only if CLIPR_SECRET_KEY was not set: generated server key – (file mode 600)

Store IDs are random UUIDs. The file system does not reveal which store belongs to whom.

Key hierarchy

flowchart TB
  K["CLIPR_SECRET_KEY<br/>(server key)"] -- "HKDF server:system-db" --> S[("system.db")]
  K -- "HKDF server:exchange-db" --> X[("exchange.db")]
  K -- "HKDF server:dek-wrap" --> W["Wrapping key"]
  K -- "HKDF server:pair-wrap" --> P["Wrap pair keys"]
  K -- "HKDF server:sso-signing" --> SSO["Wrap SSO<br/>signing key"]
  W --> DEK["DEK per account<br/>(standard mode)"]
  V["Vault password<br/>scrypt"] --> DEK2["DEK per account<br/>(vault mode)"]
  RC["Recovery code<br/>scrypt"] --> DEK2
  DEK --> ST[("store.db")]
  DEK2 --> ST
  ST -- "HKDF store-files" --> F["Files"]
  • Server key (CLIPR_SECRET_KEY, at least 32 characters): separate purpose-bound keys are derived from it via HKDF-SHA256 (crypto.server_key(purpose)). No key is used for two purposes.
  • DEK (data key, 256 bit, one per store). It is wrapped (AES-GCM with a context of account and store ID)
    • in standard mode with the wrapping key (dek_server). The server can open the store at any time; this is why mail fetching, auto-archiving and delivery of shares work in the background.
    • in vault mode with a key from the vault password (scrypt, dek_vault) and additionally with the recovery code (dek_recovery). dek_server is deleted.
  • Passwords are hashed with scrypt (N=2¹⁷, r=8, p=1, following OWASP); the number of parallel computations is limited.
  • IMAP passwords are encrypted with a Fernet key derived from the server key.

Whoever has CLIPR_SECRET_KEY and the volume can read all data in standard mode. Only vaults stay closed. This is why the key must be kept separate from the server – see Backups.

Vault

Turning it on: Clipr creates a new DEK, re-encrypts the database with PRAGMA rekey, re-encrypts all files, wraps the DEK with the vault password and the recovery code and deletes dek_server.

Unlocking: the server creates a random session key K. The session row holds AES-GCM(K, DEK); K itself is only in the cookie __Host-clipr_vault (HttpOnly, Secure, SameSite=Strict). An unlock thus survives a server restart without the DEK ever being stored in plain text. It locks on expiry (Lock automatically), on sign-out or by hand.

Locked: all ticket endpoints answer 423 vault_locked. Mail attachments are sealed with the store's public X25519 key in inbox/ and imported on unlock. Control packets from sharing are applied on unlock.

Request context

The middleware resolves the session and puts a store reference into a ContextVar. The connection to the store is only opened on first access and closed at the end of the request.

Call Returns
db.conn() Store of the signed-in account (current request)
db.sys() System database
db.xchg() Intermediate storage for sharing
db.use_store(ref) An account's store for background tasks (standard mode only)

An endpoint can therefore never accidentally write into another account's store: it only knows its own.

Migrations

db.py keeps numbered migrations for the system database, the intermediate storage and the stores. They run automatically on opening and only forwards. Stores are migrated the first time they are opened after an update – vaults therefore only on unlock.