SecuritySync protocol
Sync protocol
The sync crate replicates a vault through storage the user owns — a synced folder, WebDAV, an S3-compatible bucket, or a Git branch. The storage is treated as untrusted: it may read, delete, replay or modify anything it stores.
Layers
- Vault ops are already sealed with the vault key (see Vault cryptography).
- They travel in immutable segment files that add an outer AEAD layer and a per-device hash chain.
- Because the vault is a CRDT, segments from different devices can be applied in any order.
Segment files
vault-<vault-uuid>/segments/<device-hex16>/<first:016x>-<last:016x>-<random16>.segEvery device numbers its segments 1, 2, 3 … on a backend. A delta segment has first == last; a snapshot written by compaction has first == 0 and contains every op the device knew. The random suffix makes names collision-free, so writers never overwrite each other.
file = "SSHSEG01" ‖ XChaCha20-Poly1305(segment key, aad, json(body))
aad = "vaultport/segment/v1|<vault id>|<device>|<counter>|<delta|snapshot>"
body = { vault, device, counter, kind, prev = SHA-256(previous file of this device), ops, covers? }- The segment key is an HKDF subkey of the vault key.
- The AAD is reconstructed from the file name, so renaming a segment to another device, counter or kind makes it fail authentication.
prevlinks each segment to the complete previous file of the same device, forming a hash chain.- Object names are restricted to
[A-Za-z0-9._-]path segments, so a hostile listing cannot cause path traversal in any backend.
Integrity checks
For each device, the engine remembers the newest verified (counter, hash). While syncing it reports — and does not apply anything suspicious from that device:
| Issue | Meaning |
|---|---|
| Gap | A segment is missing in the middle of a device's chain (truncation, or a file not yet propagated) |
| Rollback | The storage shows an older state of a device than this device has already seen |
| Tampered | A segment fails authentication or validation |
| Fork | Two different segments claim the same position in a device's chain (e.g. a restored backup) |
Other devices continue to sync. If this device's own uploads were rolled back, its next upload is a full snapshot that re-seeds the storage.
Limitation: hiding the newest segments of a device (tail truncation) cannot be detected by a device that has never seen them; a device that has seen them reports a rollback.
Compaction
Compaction first syncs, then writes a snapshot containing all ops this device has applied, recording for every other device the head it covers. Only after the snapshot is stored are older segments deleted: always this device's own, and other devices' only when explicitly requested, when the preceding sync reported no issue, and only up to the covered head. Readers that later meet such a gap apply the snapshot first, which keeps every chain verifiable.
Backends
| Backend | Notes |
|---|---|
| Folder | Atomic writes (temporary file, flush, rename); create-only writes via hard links; sync-tool conflict copies are skipped |
| WebDAV | PROPFIND, conditional PUT (If-None-Match / If-Match), Basic authentication over rustls, redirects not followed |
| S3 | AWS Signature V4, any S3-compatible endpoint over HTTPS, conditional writes |
| Git | Pure Rust (gix), one branch (refs/heads/vaultport-sync), set-of-files three-way merge that is always conflict-free. Smart protocol v0 over an exec channel of the app's SSH engine (same authentication and host-key verification as host connections); pushes are compare-and-swap on the old branch value, so a concurrent push is detected and re-merged |
Encrypted export (.vaultport)
"VAULTPRT" ‖ version u16 ‖ header length u32 ‖ header JSON ‖ payload
header = { vaultId, kdf: { memoryKib, iterations, parallelism, salt }, createdAt, opCount, wrappedKey }
payload = XChaCha20-Poly1305(export key, "vaultport/export/v1|" ‖ SHA-256(header), json([SealedOp]))wrappedKey is the vault key wrapped with Argon2id(passphrase). Any change to the header or payload is detected. Because the payload contains the vault's own sealed ops, an imported file is the same CRDT replica and can keep syncing with the original devices.
Device pairing
Pairing copies the vault from the device that has it (the offering device, A) to a new device (the joining device, B) directly over the local network. No sync storage is involved; if A has a sync target, its settings and secret travel along so B keeps syncing.
Offer
A binds a TCP listener on a random port on its LAN addresses (private IPv4 first, then IPv6 unique-local and global; loopback, link-local and container/VM adapters are left out; at most six) only while the pairing screen is open: it closes after one successful transfer, after 10 minutes, after three wrong codes, or when the screen is closed. A shows:
- a QR payload (also available as copyable pairing text):
vaultport-pair:2:‖ base64url(JSON{ version, vaultId, nonce, expiresAt, port, addrs }). It contains no key material. - separately, an 8-character pairing code (40 bits of OS randomness, e.g.
K7QM-2XPA).
Handshake
B connects to all advertised addresses at once and uses the first that answers (trying the next if a connection turns out not to be A). Every frame is u32 length ‖ body.
binding = SHA-256("vaultport/pairing/v2/offer" ‖ version ‖ vault id ‖ nonce ‖ expiry ‖ port ‖ addresses)
pw = HKDF-SHA256(salt = binding, ikm = code, info = "vaultport/pairing/v2/password")
B → A "VPPAIR" ‖ 0x02 ‖ nonce ‖ SPAKE2(pw) message
A → B 0x00 ‖ SPAKE2(pw) message ‖ confirm_A (0x01: unknown or expired offer)
B → A confirm_B
th = SHA-256("vaultport/pairing/v2/transcript" ‖ binding ‖ hello ‖ A's message)
keys = HKDF-SHA256(salt = th, ikm = SPAKE2 key) → confirm_A, confirm_B, key A→B, key B→ASPAKE2 (Ed25519 group, RustCrypto spake2) is a password-authenticated key exchange: both sides derive the same key only if they used the same code and the same QR payload, and neither the transcript nor a confirmation lets anyone test other codes offline. Confirmations are compared in constant time. B stops at a wrong confirm_A; A reads nothing from the vault before confirm_B checks out.
Transfer
Every later frame is ChaCha20-Poly1305(key of its direction, nonce = 0⁴ ‖ frame counter, type ‖ body):
A → B MANIFEST { vaultId, vaultKey, opCount, totalBytes, backend, backendSecret }
A → B OPS json([SealedOp]) ≈ 512 KiB each
A → B DONE
B → A ACKThe ops are the vault's own sealed operations — the same format as sync segments and .vaultport exports, still encrypted with the vault key — so B becomes a replica of the same vault (same vault id, its own device id) that can sync with A through any target later. Only syncable operations are sent: data marked device-local (device-local secrets and settings, such as each device's sync targets and their credentials) never leaves A, except the sync target secret the app includes explicitly.
B treats everything as untrusted, also after authentication: frames are at most 1 MiB, the manifest at most 256 KiB and the transfer at most 256 MiB (10 million ops), checked before allocating; the vault id must match the QR payload; byte and op counts must match the manifest exactly; duplicate ops are refused; the data counts only after DONE. Building the replica authenticates every op with the vault key, and nothing is stored if any check fails.
Threat model
| Attacker | Outcome |
|---|---|
| Passive, on the network (sees all traffic and the QR code) | Learns nothing: the payload has no key material, and SPAKE2 session keys cannot be computed from a transcript, even with the code |
| Active, on the network or impostor (also saw the QR code) | One online guess of the 40-bit code per connection. A counts a guess whenever it answered a hello without receiving a valid confirm_B and stops listening after three; B stops at the first wrong confirmation. Success probability: a few in 2⁴⁰ (≈ 10⁻¹²) |
| Edits the QR payload (addresses, expiry, nonce) | Changes the binding, so the handshake fails. Redirecting B to itself gives the attacker one guess |
| Tampers with, replays, reorders or truncates frames | Detected by the AEAD with per-direction counters and the explicit end message |
| Sees both the QR code and the code (shoulder surfing) | Can pair instead of your device if it reaches A first. Pair in private; codes expire after 10 minutes and A stops after one transfer |
| Floods A with connections | Delays pairing (one connection at a time, 15 s handshake timeout); garbage does not count as a guess |
Expiry is checked by both devices. A connection whose nonce belongs to an older offer is told so without using up a guess.