Files
CustosPublic/docs/SEAL.md
T

2.7 KiB
Raw Permalink Blame History

Sealed boxes (custos-seal)

The two-factor services (docs/FACTORS.md, types 3 and 4) pass factor material through a mailbox on the home server. The mailbox must never be able to read it. So the device that wants a secret makes a one-time X25519 key pair, sends only the public half, and whoever releases the secret seals it to that key. The same box carries a secret from the user's PC to a Claude Code cloud session.

The box, version 1

sealed = "CSL1" ‖ E (32) ‖ nonce (24) ‖ XChaCha20-Poly1305(K, nonce, plaintext, aad)

E      the sender's ephemeral X25519 public key (a fresh one per box)
R      the recipient's one-time public key
K      HKDF-SHA256(ikm = X25519(e, R), salt = E ‖ R, info = "custos seal v1" ‖ context)
aad    "CSL1" ‖ E ‖ context
  • context names the purpose, for example approval:<factor id>:<request id> or cloud:<request id>. A box opens only with the context it was sealed for, so a box for one request does not work as another.
  • A low-order public key is refused on both sides: the shared secret must be contributory.
  • Plaintext limit: 32 KiB.
  • The recipient's secret half lives only in memory, as x25519_dalek::StaticSecret with zeroize, and is wiped on drop. Nothing writes it to disk.

The match code

Six digits that the requesting screen and the approving screen both show:

match = u32_be(SHA-256("custos match v1" ‖ R)[0..4]) mod 1 000 000, zero-padded to 6 digits

If they differ, someone else's request is waiting: deny it. The code is not a secret. It only ties the approval to the key the box is sealed for.

Test vector: R = 07 × 32 → 684361.

The sender code

The match code of a box's ephemeral key E (sender_code). When the receiver must know who sealed a box, as when a PC adds a phone's factors, the sealing screen shows this code and the receiving screen asks the person to confirm it. E is fresh for every box, so each box has its own code.

At rest

The factor service keeps each TOTP share sealed with its own key, which comes from a systemd credential that is not in its state directory:

at rest = "CSR1" ‖ nonce (24) ‖ XChaCha20-Poly1305(HKDF-SHA256(key, salt = "", info = "custos rest v1" ‖ context),
                                                   nonce, plaintext, "CSR1" ‖ context)

What this protects: a leaked copy of /var/lib/custos-factors without the credential gives nothing. What it does not protect: anyone who controls the running server. That is one factor, which is why a factor is never enough alone.

Crates

x25519-dalek 2 (dalek-cryptography, the X25519 sibling of the ed25519-dalek used for key pairs), chacha20poly1305, hkdf, sha2, and rand's SysRng.