Skip to main content

Module validation

Module validation 

Source
Expand description

Refuse-by-default validation invariants — the operational core of the threat model (SSoT: Threat Model — Validation Invariants).

These are pure, key-less structural checks: the protocol/capability handshake (protocol) and the server-side manifest envelope (structural). They mirror the client-side checks in verify_asset, and the server write paths consume them today — the envelope gate, the ops surface, the feed, federation pull, and the drop routes all validate through here. This module used to describe those consumers as deferred; they are six live call sites, and the checks are the only thing standing between a key-free server and a malformed write.

Upload-transport-specific invariants (chunk offset/4 KiB alignment, cumulative size) live with the deferred upload protocol.

Structs§

EnvelopeContext
Context a key-less server holds when validating a non-upload lifecycle manifest.

Enums§

EnvelopeReject
A keyless envelope decision over a manifest core plus the server-known context.
HandshakeReject
A handshake rejection. Each maps to a fail-closed rule and an HTTP status.

Functions§

album_pin_matches
Part of invariant 6: the album’s pinned protocol_version equals the request’s.
amk_version_monotonic
Invariant 18: amk_version never regresses for an album (server’s structural backstop; MLS is the authority on the ceiling — see verify_asset).
check_manifest_envelope
Run the keyless envelope checks (2, 6, 7, 8, 17, 18) over a lifecycle manifest core. Returns the first invariant violated, or Ok(()).
check_metadata_blob_envelope
Invariant 25 as a refuse-by-default decision: run on any write whose bundle carries a metadata blob (a create bundle, at finalization, or a non-upload metadata-update). The blob’s content hash must equal the manifest’s committed metadata_blob_hash. Key-free — the server never decrypts (SSoT: Threat Model — invariant 25, Metadata — Local and Server Metadata Equivalence).
check_sidecar_schema
Reject a sidecar_schema above the receiver’s max known (Postel cross-version closure).
check_suite
Reject a crypto_suite_id the receiver does not implement (invariant 2).
content_type_allowed
Invariant 5: content_type is in the closed allow-list for this protocol version.
device_added_before
Invariant 7 (time half): the device’s directory added_at precedes the manifest timestamp. None on an unparseable timestamp (the caller rejects with 400).
hash_length_ok
Invariant 3: the declared content hash length matches the digest size for the suite. (Type-level true for Hash32, but checked explicitly for wire-decoded lengths.)
metadata_blob_hash_matches
Invariant 25 (key-free): the metadata blob in the bundle has a content hash equal to the manifest’s committed metadata_blob_hash. The server holds no key, but it hashes the ciphertext object it stores and compares it against the signed manifest field, so a client cannot present a metadata blob different from the one its manifest is signed over. false when the manifest commits to no hash — a bundle carrying a blob must be committed to.
prior_hash_matches
Invariant 17: prior_provenance_hash equals the last accepted manifest’s hash for this asset. stored_head is None for a never-seen asset (only a create is valid then).
protocol_gate
Gate a request’s protocol_version against the server-advertised [min, max] window. Reads succeed for any past version (callers skip this on read paths); this is the write gate.
size_in_bounds
Invariant 4: declared size is in (0, max_file_size].
timestamp_within_drift
Invariant 8: the self-asserted timestamp is within ±drift_days of the server clock. A non-security gross-drift guard. None on an unparseable timestamp.