72 lines
3.6 KiB
Markdown
72 lines
3.6 KiB
Markdown
# Private share links (`custos-share`), format version 1
|
|
|
|
A share link hands one secret to someone who has no Custos. The sender's app (desktop or web) encrypts it;
|
|
the share server stores only ciphertext; the key travels in the link's fragment, which browsers never send
|
|
to a server.
|
|
|
|
```
|
|
https://custos.example/s/<id>#k=<link key> no password
|
|
https://custos.example/s/<id>#k=<link key>&p=1 the recipient also needs a password, told separately
|
|
```
|
|
|
|
- `<id>`: chosen by the server (128 random bits, base64url, 22 characters). It is not secret.
|
|
- `<link key>`: 32 random bytes from the OS CSPRNG, base64url without padding (43 characters).
|
|
- `p=1` only tells the recipient page to ask for a password before it fetches anything. The blob's own
|
|
flag decides; a link with `p=1` removed still needs the password.
|
|
|
|
## Keys
|
|
|
|
```
|
|
no password: K = link key
|
|
with password: P = Argon2id(password (UTF-8), salt, m, t, p) → 32 bytes
|
|
K = HKDF-SHA256(salt = salt, ikm = link key ‖ P, info = "custos-share v1") → 32 bytes
|
|
```
|
|
Both the link and the password are needed; neither alone gives anything, and the server has neither.
|
|
Default share KDF: m = 19 MiB (19,456 KiB), t = 2, p = 1 (OWASP's Argon2id minimum; it runs in a phone
|
|
browser in about a second). It only has to slow down guessing by someone who already holds the link.
|
|
|
|
## Blob (what the server stores), all integers little-endian
|
|
|
|
| Offset | Size | Field |
|
|
|:--|:--|:--|
|
|
| 0 | 4 | magic `CSH1` |
|
|
| 4 | 1 | flags: bit 0 = password; other bits must be 0 |
|
|
| 5 | 28 | only if bit 0: `m_cost_kib` u32, `t_cost` u32, `p_cost` u32, salt (16 bytes) |
|
|
| … | 24 | nonce |
|
|
| … | rest | XChaCha20-Poly1305 ciphertext and 16-byte tag; AAD = every byte before it (magic to nonce) |
|
|
|
|
Limits a reader enforces before running Argon2: m from 8 MiB to 256 MiB, t from 1 to 16, p from 1 to 4.
|
|
A whole blob is at most 64 KiB.
|
|
|
|
## Plaintext
|
|
|
|
UTF-8 JSON, `{"v":1,"title":"…","kind":"web-login","fields":[{"name":"password","value":"…","secret":true}],"notes":"…"}`.
|
|
`kind` and `notes` may be missing. Built from an item by `Payload::from_item`, which leaves out empty
|
|
fields, the TOTP seed (sharing it would hand over the second factor too) and the auto-type settings.
|
|
|
|
## Errors (none contains secret material)
|
|
|
|
| Error | When | Says |
|
|
|:--|:--|:--|
|
|
| `Malformed` | wrong magic, too short, unknown flags, too large | not a Custos share |
|
|
| `BadLink` | fragment missing, not `k=` + 43 base64url characters | the link is incomplete |
|
|
| `PasswordRequired` | the blob has the password flag and no password was given | — |
|
|
| `UnsupportedKdf` | parameters outside the limits | — |
|
|
| `DecryptFailed` | the tag does not verify: wrong key, wrong password, or any byte changed | never garbage: nothing is returned |
|
|
|
|
A wrong password and a tampered blob give the same `DecryptFailed`; the page says "wrong password, or the
|
|
link or share is damaged".
|
|
|
|
## Server rules (the private app's share service implements them)
|
|
|
|
- Stores the blob, an expiry (1 hour, 1 day or 7 days; default 1 day) and a view count (default 1).
|
|
- `open` returns the blob and counts one view; the last view deletes it. Expired, used up and unknown ids
|
|
answer the same 404.
|
|
- Logs only the id, the time and the status code. Never a body, never a full URL.
|
|
|
|
## The browser build (`custos-wasm`)
|
|
|
|
The web vault and the recipient page run this repository's code compiled to `wasm32-unknown-unknown`,
|
|
with no wasm-bindgen: a JSON-in/JSON-out `call` export and a `random_fill` import backed by
|
|
`crypto.getRandomValues` (getrandom's custom backend). The ABI is documented in `crates/custos-wasm/src/lib.rs`.
|