feat(encryption): client-side encryption works, from the plan to the restore #55

Merged
james.maes merged 1 commits from feature/client-side-encryption into develop 2026-11-24 10:41:03 +00:00
Owner

What changes

Client-side encryption (CLIENT_AES256_GCM, spec 11.2) works. The transform plumbing was in place, but nothing installed a cipher and nothing handed one to a run, so a plan that asked for encryption was refused.

  • BackupsQBitConfig.withKeyProvider(QKeyProviderInterface) installs StreamingCipherTransform, built on the streaming cipher of the QQQ crypto package (Tink streaming AEAD, a fresh data key per object, wrapped by the referenced key).
  • A run of a plan that asks for encryption gets the cipher for the plan's key reference. With no key for it, the run is refused and nothing is written in the clear.
  • A plan is not saved when the provider has no key for its reference.
  • Verification and restore read through the same provider. A rotated key still reads what its older version wrote.
  • A run records the key reference and a fingerprint (v<version>:<16 hex of a labelled hash>), never the key.

A defect found by the new restore test

The file index of an encrypted run (files/index-00001.jsonl.gz: tables, record keys and where each file came from) was written in the clear while the catalog recorded it as encrypted, and a restore from an encrypted run could not read it. It is now encrypted like every other object of the run. No release could encrypt before this one, so no stored run is affected. The verifier already reads either form.

Why

A host that backs up customer data and email content has only the bucket's own encryption today. Found while configuring the installed nightly plan of an application that includes sensitive fields.

How it was tested

./mvnw verify: 225 tests, guardrails and coverage pass. New:

  • StreamingCipherTransformTest (6): round trip, a changed or cut-off object refused, another key refused, no key gives no transform, rotation, the fingerprint is not the key.
  • An encrypted run from the plan through the coordinator: the objects are ciphertext, it passes verification by content and a test restore, a new run after a rotation is written under version 2 while the old run still verifies, and without the key a run is refused with nothing written.
  • A restore from an encrypted backup (rows and a file), and its refusal without the key.
  • Plan validation with a key provider.

Not in this change

  • Test destination does not yet decrypt a probe with the current key (spec 11.2).
  • The home does not yet show "runs still needing key version N".
  • Downloads of an encrypted run are still ciphertext only.

Written by an AI agent (Claude Code) working through the repository owner's access. Every key in the tests is random and made for the test.

🤖 Generated with Claude Code

## What changes Client-side encryption (`CLIENT_AES256_GCM`, spec 11.2) works. The transform plumbing was in place, but nothing installed a cipher and nothing handed one to a run, so a plan that asked for encryption was refused. - `BackupsQBitConfig.withKeyProvider(QKeyProviderInterface)` installs `StreamingCipherTransform`, built on the streaming cipher of the QQQ crypto package (Tink streaming AEAD, a fresh data key per object, wrapped by the referenced key). - A run of a plan that asks for encryption gets the cipher for the plan's key reference. With no key for it, the run is refused and nothing is written in the clear. - A plan is not saved when the provider has no key for its reference. - Verification and restore read through the same provider. A rotated key still reads what its older version wrote. - A run records the key reference and a fingerprint (`v<version>:<16 hex of a labelled hash>`), never the key. ## A defect found by the new restore test The file index of an encrypted run (`files/index-00001.jsonl.gz`: tables, record keys and where each file came from) was written in the clear while the catalog recorded it as encrypted, and a restore from an encrypted run could not read it. It is now encrypted like every other object of the run. No release could encrypt before this one, so no stored run is affected. The verifier already reads either form. ## Why A host that backs up customer data and email content has only the bucket's own encryption today. Found while configuring the installed nightly plan of an application that includes sensitive fields. ## How it was tested `./mvnw verify`: 225 tests, guardrails and coverage pass. New: - `StreamingCipherTransformTest` (6): round trip, a changed or cut-off object refused, another key refused, no key gives no transform, rotation, the fingerprint is not the key. - An encrypted run from the plan through the coordinator: the objects are ciphertext, it passes verification by content and a test restore, a new run after a rotation is written under version 2 while the old run still verifies, and without the key a run is refused with nothing written. - A restore from an encrypted backup (rows and a file), and its refusal without the key. - Plan validation with a key provider. ## Not in this change - *Test destination* does not yet decrypt a probe with the current key (spec 11.2). - The home does not yet show "runs still needing key version N". - Downloads of an encrypted run are still ciphertext only. Written by an AI agent (Claude Code) working through the repository owner's access. Every key in the tests is random and made for the test. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
james.maes added 1 commit 2026-11-24 10:38:55 +00:00
feat(encryption): client-side encryption works, from the plan to the restore
maven / build (push) Successful in 2m2s
build / maven (push) Successful in 2m2s
478bd4363b
A plan could ask for CLIENT_AES256_GCM and was refused: the transform
plumbing was there, but nothing installed a cipher and nothing handed one
to a run.

- BackupsQBitConfig.withKeyProvider installs the streaming cipher of the
  QQQ crypto package (StreamingCipherTransform: Tink streaming AEAD, a
  fresh data key per object, wrapped by the referenced key)
- a run of a plan that asks for encryption gets the cipher for the plan's
  key reference; with no key for it the run is refused and nothing is
  written in the clear
- a plan is not saved when the provider has no key for its reference
- verification and restore read through the same provider; a rotated key
  still reads what its older version wrote
- a run records the key reference and a fingerprint (v<version>:<16 hex
  of a labelled hash), never the key

Fixed on the way: the file index of an encrypted run was written in the
clear while the catalog recorded it as encrypted, and a restore from an
encrypted run could not read it. It is encrypted like every other object
of the run. No release could encrypt before this, so no stored run is
affected.

Tests: StreamingCipherTransformTest (6: round trip, tampering and
truncation refused, another key refused, no key gives no transform,
rotation, the fingerprint is not the key); an encrypted run from the plan
(objects are ciphertext, verified by content and by test restore, rotated,
refused without the key with nothing written); a restore from an encrypted
backup, rows and a file, and its refusal without the key; plan validation
with a key provider. ./mvnw verify: 225 tests, guardrails and coverage
pass.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
james.maes merged commit 47ba7b3f9a into develop 2026-11-24 10:41:03 +00:00
Sign in to join this conversation.