-
-
Notifications
You must be signed in to change notification settings - Fork 0
Encrypted Queue and Audit
Mailbridge maintains two separate SQLite concerns:
-
data/mailbridge.db: audit events and their integrity chain -
secrets/secrets.db: active retry-queue metadata and per-message secret material
Raw queued mail is never stored in either database.
Queued messages are serialized and encrypted under data/queue/:
- Generate a random 32-byte per-message secret.
- Derive an AES-256 key with HKDF-SHA256 using
QUEUE_MASTER_KEY, the per-message secret, and the queue ID. - Encrypt the envelope sender, recipient, raw message, and target with AES-256-GCM.
- Store the encrypted file with mode
0600. - Store the per-message secret and non-content metadata in
secrets/secrets.db.
Decryption therefore requires both the queue file, the secrets database, and the configured master key.
Generate the master key with the interactive setup or:
openssl rand -base64 32 | tr -d '\n'Changing QUEUE_MASTER_KEY while messages remain queued makes those messages unrecoverable.
The queue processor handles up to 50 oldest messages per pass and prevents overlapping runs. For every attempt it records an audit event, delivers to either local SMTP or the selected outbound provider, and then:
- deletes the queue row and encrypted file after success
- deletes permanent failures after recording the failure
- increments attempts and stops the current batch after a temporary failure
- drops items that reached
QUEUE_MAX_ATTEMPTSafter recording the outcome
Audit records include event type, direction, target, outcome, attempt number, status/error metadata, and HMAC-derived hashes of sender, recipient, and source IP. They do not store full raw message content.
Events form a signed chain derived from the queue master key, allowing the application to link successive audit entries. Old audit records are pruned according to AUDIT_LOG_RETENTION_DAYS.
On startup, Mailbridge migrates older queue tables and databases into the encrypted file-backed design. Legacy plaintext queue rows are encrypted before the old table is removed. Current queue metadata found in the audit database is moved into secrets/secrets.db.
Back up data/, secrets/, and the master key together when queued-message recovery matters. Protect secrets/ more strictly than ordinary runtime data.
Copyright (c) 2026 Voxvey Research LLC, a Helio company.