4.2 KiB
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
contextnames the purpose, for exampleapproval:<factor id>:<request id>orcloud:<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 in memory as
x25519_dalek::StaticSecretwithzeroize, and is wiped on drop. One-time keys (Recipient::generate) are the default and nothing writes them to disk.
A kept key (core 0.11.0)
The recipient's secret may now be kept by the caller, for one purpose: the PC's Provisio sealing key
(docs/10_provisio.md in the app), the key the server seals offers to. Custos makes it once with
Recipient::generate, keeps Recipient::secret_bytes() DPAPI-sealed in <data>actors\provision.key, and
restores it with Recipient::from_secret at every start. Everything else (approvals, pairing, a Provisio ask)
still uses a fresh one-time key per request.
Recipient::from_secret(Zeroizing<[u8; 32]>) -> Result<Recipient, SealError> // BadKey for a known key
Recipient::secret_bytes(&self) -> Zeroizing<[u8; 32]> // only for a key that is kept
from_secretrefuses (BadKey) a secret that X25519 clamps to zero (all zeros: a wiped or never-filled buffer) and, as for public keys, one whose shared secrets would not be contributory.- A kept key opens every box ever sealed to it, so the context carries the binding: an offer is sealed for
provision-offer:<store>:<item>, and the PC checks the plaintext's item, store, kind and code key against the offer before it shows a card. The mailbox refuses an offer whose ephemeral key it has seen (replay). secret_byteshands out the secret in aZeroizingbuffer. It goes to the caller's sealed storage and nowhere else: never a log, a message or a file in the clear.Debugof aRecipientprints[redacted].
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.