Appearance
Content-Addressed Encrypted Blob Storage & Attachments
- Status: Standard (Track C, Issues #452, #453, #983)
- Scope: Content-oblivious encrypted attachment manifests (
EncryptedAttachmentManifest), deterministic per-chunk AEAD nonce/AAD derivation, chunked staging and reference-counted garbage collection lifecycle, and the unifiedBlobStoretrait acrossRocksDbBlobStore,LocalFsBlobStore, andS3BlobStore.
1. Architectural Motivation & Content-Oblivious Boundary
In high-throughput federated messaging, embedding large files (images, audio notes, video streams, PDF documents) directly inside single-transaction database write batches causes write amplification, LSM compaction stalls, and memory spikes.
Frank decouples the control plane from the bulk ciphertext data plane while enforcing a strict content-oblivious boundary:
- Control Plane (
RelayKvStore): Compact envelopes (), canonical Frank-CBOR attachment manifests (B_man:), staging session states (B_stg_ses:), and owner reference counts (B_ref:) are persisted in the transactionalRelayKvStore(RocksDB or FoundationDB). - Data Plane (
BlobStore): Bounded ciphertext chunks (, default ) are stored inRocksDbBlobStore,LocalFsBlobStore, orS3BlobStore(AWS S3, MinIO, Cloudflare R2, SeaweedFS). - Zero Application Metadata in
BlobStore: NeitherEncryptedAttachmentManifestnorBlobStorecontains filenames, MIME types, media kinds, image/video dimensions, audio durations, thumbnails, call associations, or commerce semantics. All application metadata lives exclusively inside the end-to-end encryptedType 8(ApplicationItem) message payload alongside the 256-bit symmetric key and 24-bytebase_nonce.
2. Two-Level Opaque Identification & Per-Chunk Cryptography
2.1 Two-Level Identifiers (AttachmentId + ChunkDigest)
AttachmentId([u8; 32]): A fresh 256-bit random capability-scoped identifier generated per upload. Addressing manifests and published chunk namespaces by randomAttachmentIdrather than a global plaintext or unkeyed ciphertext hash prevents cross-user confirmation-of-a-file attacks and deduplication side channels.ChunkDigest([u8; 32]): TheSHA-256digest of each individual encrypted chunk's ciphertext bytes (SHA-256(chunk_ciphertext_i)). Every staged upload, publication promotion, single-chunk read, and byte-range read verifies the chunk'sSHA-256against the manifest before returning bytes.
2.2 Deterministic Per-Chunk Nonce & AAD Derivation
To prevent chunk reordering, truncation, duplication, or cross-attachment chunk splicing, each chunk is encrypted with XChaCha20-Poly1305 under using a domain-separated per-chunk nonce and AAD:
3. Canonical Frank-CBOR EncryptedAttachmentManifest Schema
Manifests are encoded and decoded using deterministic frank_cbor (encode_canonical / decode_canonical) with unsigned integer map keys. Unknown keys are retained in extra_fields: BTreeMap<i128, CborValue> for forward-compatible version negotiation.
3.1 Top-Level Manifest Map Keys
| CBOR Key | Field Name | Rust Type | Normative Constraints |
|---|---|---|---|
1 | schema_version | u32 | Must equal 1 (MANIFEST_SCHEMA_VERSION). |
2 | attachment_id | [u8; 32] | 32-byte opaque capability-scoped attachment ID. |
3 | total_ciphertext_bytes | u64 | Exact sum of byte_len across all chunks (). |
4 | max_chunk_bytes | u32 | Bounded in (); default (). |
5 | chunks | Vec<ManifestChunkSpec> | Ordered array of chunk descriptors ( chunks). |
6 | expires_at_ms | u64 | Unix epoch milliseconds when the published attachment expires. |
extra_fields | BTreeMap<i128, CborValue> | Losslessly retained unknown future fields. |
3.2 ManifestChunkSpec Map Keys
| CBOR Key | Field Name | Rust Type | Normative Constraints |
|---|---|---|---|
1 | index | u32 | Strictly contiguous . |
2 | byte_len | u32 | Ciphertext byte length in . |
3 | sha256 | [u8; 32] | SHA-256 digest over the chunk's ciphertext bytes. |
3.3 Resource Limits Enforced Before Allocation
MAX_MANIFEST_BYTES:65_536()DEFAULT_CHUNK_BYTES:262_144()MAX_CHUNK_BYTES:1_048_576()MAX_CHUNK_COUNT:4_096MAX_ATTACHMENT_BYTES:268_435_456()
4. Stage Publish Reference / GC State Machine
4.1 Crash-Boundary Invariant Table
| Crash Boundary | Durable KV State | Chunk Store State | Reader Visibility | Recovery / GC Behavior |
|---|---|---|---|---|
Mid put_staged_chunk before B_stg_got write | B_stg_ses present, B_stg_got absent | Staged chunk present | Invisible (NotFound) | Client retry overwrites staged chunk idempotently; or gc_expired deletes staged chunk when session TTL expires. |
Mid publish_staged during chunk promotion (before KV commit) | B_stg_ses present, B_man absent | Partial published chunks written | Invisible (NotFound) | Retry of publish_staged completes promotion; if abandoned, gc_expired deletes both staged and unreferenced published chunks. |
Mid publish_staged after atomic KV commit, before staged chunk deletion | B_man, B_ref, and B_cln committed; B_stg_ses deleted | Published chunks intact; some staged chunks remain | Readable & verified | Next gc_expired sweeps B_cln and deletes leftover staged chunks without touching published chunks. |
Mid gc_expired after atomic unpublish transaction, before chunk deletion finishes | B_man and B_ref deleted; B_gc tombstone committed | Some published chunks still on disk/S3 | Invisible (NotFound) | Next gc_expired sweeps B_gc, deletes remaining published chunks, and removes B_gc. |
5. BlobStore Adapters & S3 Compatibility (#453)
RocksDbBlobStore: Persists manifests/references inRelayKvStoreand stores bounded chunks underB_stg:{session_id}:{idx}andB_chk:{attachment_id}:{idx}inRelayKvStore, avoiding multi-megabyte monolithic WriteBatches.LocalFsBlobStore: Persists manifests/references inRelayKvStoreand writes immutable chunk files underroot_dir/staging/{session_hex}/{idx}.chunkandroot_dir/chunks/{prefix}/{attachment_hex}/{idx}.chunkusing atomic temp-file write +fsync+rename.S3BlobStore: Persists authoritative manifests/references inRelayKvStoreand stores immutable chunk payloads in S3-compatible object storage using only the portable S3 REST subset (PUT,GET,HEAD,DELETEwith AWS SigV4Authorizationandx-amz-content-sha256payload verification). This subset works identically across AWS S3, MinIO, Cloudflare R2, and SeaweedFS without relying on provider-specific multipart-upload state or eventual-consistency bucket listing.
6. Threat Model Summary
| Actor / Layer | What It Can Observe | What It Cannot Learn or Alter |
|---|---|---|
Relay / RelayKvStore | Opaque AttachmentId, chunk count, per-chunk ciphertext sizes, expires_at_ms, and message owner_ref digests. | Plaintext bytes, , filename, MIME type, media dimensions, or whether two users uploaded the same file. |
| S3 / Object Storage Provider | Opaque object keys (staging/{session}/{idx}, chunks/{attachment_id}/{idx}), ciphertext byte lengths, and SHA-256 digests. | Cannot forge, reorder, truncate, or splice chunks undetected: BlobStore::get_chunk and BlobStore::read_range verify SHA-256 against the signed manifest, and clients verify per-chunk XChaCha20-Poly1305 AEAD tags bound to derive_chunk_nonce and derive_chunk_aad. |