[share] Share links and the browser build: custos-share (blob v1, key in the fragment, optional password), custos-wasm (JSON ABI, no wasm-bindgen), docs/SHARE.md, threat model (v0.3.0)

This commit is contained in:
2026-10-31 18:20:51 +01:00
parent 4aac99fb47
commit 5ee1c0da6b
16 changed files with 1153 additions and 5 deletions
+4
View File
@@ -196,3 +196,7 @@ and an identical `.bak`. Leftover `.tmp` files are ignored and overwritten by th
A change that old readers would misread bumps `version`. Readers refuse versions they do not know rather
than guess. Adding JSON members or new slot kinds does not need a bump.
## Share links
Shares are not vault files; their blob and link format is in `docs/SHARE.md`.
+71
View File
@@ -0,0 +1,71 @@
# 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`.
+12
View File
@@ -16,6 +16,9 @@ just as plainly, what it does not.
| Thief or sync server | The `.custos` file (any number of old versions) | Item count and sizes roughly (the ciphertext length), the KDF parameters. Nothing else. | XChaCha20-Poly1305 over the whole body; titles, URLs and usernames are inside it too. |
| Offline guesser | The file and a GPU farm | One Argon2id evaluation (64 MiB, 20 passes by default, ≈ 0.75 s on a desktop CPU) per guess | A 4-word memorable password with digits (~65 bits) is out of reach; a weak master password is not. **The master password is the whole defence here.** |
| Tamperer | Write access to the file | Can destroy it, or roll it back to an older version they saw. Cannot change, reorder, add or remove items unnoticed. | The header is the body's AAD; each slot's parameters are its wrap's AAD. |
| Share server operator | Every share blob, its id, size, expiry, view count, the uploader's login and the recipients' IP addresses | Nothing of the secret | The key is in the link's `#fragment`, which browsers never send; the server stores ciphertext only (docs/SHARE.md). |
| Someone who gets a share link | The link (chat history, a forwarded mail) | The secret, if the share still has views left; with a password share, also one Argon2id evaluation (19 MiB) per password guess | That is what a link is. Use 1 view (the default): once it is opened, it is gone, and the sender learns about interception when the recipient finds it used. |
| Link-preview bot | The link, fetched by a chat app | Nothing; the view is not used | The page asks for a click on *Reveal* before it fetches the share. |
| Someone who crashes the machine mid-save | — | Nothing | Atomic save: temp file, fsync, rename; the previous version is kept as `.bak`. |
## What is NOT protected
@@ -41,6 +44,15 @@ just as plainly, what it does not.
- **Metadata.** File size and modification times reveal roughly how much is stored and when it changed.
- **Side channels.** No effort beyond what the RustCrypto crates provide (constant-time tag comparison).
- **The web vault trusts the server that serves its code.** In the browser, the page, its JavaScript and the
WebAssembly come from the home server on every visit. Whoever controls that server (or its TLS
certificate) can serve a modified page that sends the master password away the next time someone unlocks
in the browser. The desktop app does not have this problem. Authelia keeps strangers out; it does not
protect against the server itself. The same holds for the share page and the recipient.
- **Browser memory.** In the web vault the key and the decrypted items live in WebAssembly memory, and a
revealed or copied value passes through JavaScript strings, which cannot be wiped. Lock (or close the tab)
when done.
## Design rules that follow from this
- No custom cryptography: Argon2id (`argon2`), XChaCha20-Poly1305 (`chacha20poly1305`), the OS CSPRNG