Skip to content

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 unified BlobStore trait across RocksDbBlobStore, LocalFsBlobStore, and S3BlobStore.

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 (≤64 KiB\le 64\text{ KiB}), canonical Frank-CBOR attachment manifests (B_man:), staging session states (B_stg_ses:), and owner reference counts (B_ref:) are persisted in the transactional RelayKvStore (RocksDB or FoundationDB).
  • Data Plane (BlobStore): Bounded ciphertext chunks (≤1 MiB\le 1\text{ MiB}, default 256 KiB256\text{ KiB}) are stored in RocksDbBlobStore, LocalFsBlobStore, or S3BlobStore (AWS S3, MinIO, Cloudflare R2, SeaweedFS).
  • Zero Application Metadata in BlobStore: Neither EncryptedAttachmentManifest nor BlobStore contains 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 encrypted Type 8 (ApplicationItem) message payload alongside the 256-bit symmetric key KblobK_{\text{blob}} and 24-byte base_nonce.

2. Two-Level Opaque Identification & Per-Chunk Cryptography ​

2.1 Two-Level Identifiers (AttachmentId + ChunkDigest) ​

  1. AttachmentId([u8; 32]): A fresh 256-bit random capability-scoped identifier generated per upload. Addressing manifests and published chunk namespaces by random AttachmentId rather than a global plaintext or unkeyed ciphertext hash prevents cross-user confirmation-of-a-file attacks and deduplication side channels.
  2. ChunkDigest([u8; 32]): The SHA-256 digest 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's SHA-256 against 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 i∈[0,N)i \in [0, N) is encrypted with XChaCha20-Poly1305 under KblobK_{\text{blob}} using a domain-separated per-chunk nonce and AAD:

maski=HMAC-SHA256(Kblob, "frank-blob-chunk-v1"∥attachment_id∥u32_be(i))[0..24]\text{mask}_i = \text{HMAC-SHA256}\bigl(K_{\text{blob}},\ \texttt{"frank-blob-chunk-v1"} \parallel \text{attachment\_id} \parallel \text{u32\_be}(i)\bigr)[0..24]
noncei=base_nonce⊕maski\text{nonce}_i = \text{base\_nonce} \oplus \text{mask}_i
aadi="frank-blob-aad-v1"∥attachment_id∥u32_be(i)∥u8(is_final_chunk)\text{aad}_i = \texttt{"frank-blob-aad-v1"} \parallel \text{attachment\_id} \parallel \text{u32\_be}(i) \parallel \text{u8}(\text{is\_final\_chunk})

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 >6> 6 are retained in extra_fields: BTreeMap<i128, CborValue> for forward-compatible version negotiation.

3.1 Top-Level Manifest Map Keys ​

CBOR KeyField NameRust TypeNormative Constraints
1schema_versionu32Must equal 1 (MANIFEST_SCHEMA_VERSION).
2attachment_id[u8; 32]32-byte opaque capability-scoped attachment ID.
3total_ciphertext_bytesu64Exact sum of byte_len across all chunks (≤256 MiB\le 256\text{ MiB}).
4max_chunk_bytesu32Bounded in 1.. ⁣= ⁣1,048,5761..\!=\!1{,}048{,}576 (1 MiB1\text{ MiB}); default 262,144262{,}144 (256 KiB256\text{ KiB}).
5chunksVec<ManifestChunkSpec>Ordered array of chunk descriptors (≤4096\le 4096 chunks).
6expires_at_msu64Unix epoch milliseconds when the published attachment expires.
>6> 6extra_fieldsBTreeMap<i128, CborValue>Losslessly retained unknown future fields.

3.2 ManifestChunkSpec Map Keys ​

CBOR KeyField NameRust TypeNormative Constraints
1indexu32Strictly contiguous 0..chunks.len()0..\text{chunks.len()}.
2byte_lenu32Ciphertext byte length in 1.. ⁣= ⁣max_chunk_bytes1..\!=\!\text{max\_chunk\_bytes}.
3sha256[u8; 32]SHA-256 digest over the chunk's ciphertext bytes.

3.3 Resource Limits Enforced Before Allocation ​

  • MAX_MANIFEST_BYTES: 65_536 (64 KiB64\text{ KiB})
  • DEFAULT_CHUNK_BYTES: 262_144 (256 KiB256\text{ KiB})
  • MAX_CHUNK_BYTES: 1_048_576 (1 MiB1\text{ MiB})
  • MAX_CHUNK_COUNT: 4_096
  • MAX_ATTACHMENT_BYTES: 268_435_456 (256 MiB256\text{ MiB})

4. Stage →\rightarrow Publish →\rightarrow Reference / GC State Machine ​

4.1 Crash-Boundary Invariant Table ​

Crash BoundaryDurable KV StateChunk Store StateReader VisibilityRecovery / GC Behavior
Mid put_staged_chunk before B_stg_got writeB_stg_ses present, B_stg_got absentStaged chunk presentInvisible (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 absentPartial published chunks writtenInvisible (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 deletionB_man, B_ref, and B_cln committed; B_stg_ses deletedPublished chunks intact; some staged chunks remainReadable & verifiedNext gc_expired sweeps B_cln and deletes leftover staged chunks without touching published chunks.
Mid gc_expired after atomic unpublish transaction, before chunk deletion finishesB_man and B_ref deleted; B_gc tombstone committedSome published chunks still on disk/S3Invisible (NotFound)Next gc_expired sweeps B_gc, deletes remaining published chunks, and removes B_gc.

5. BlobStore Adapters & S3 Compatibility (#453) ​

  1. RocksDbBlobStore: Persists manifests/references in RelayKvStore and stores bounded chunks under B_stg:{session_id}:{idx} and B_chk:{attachment_id}:{idx} in RelayKvStore, avoiding multi-megabyte monolithic WriteBatches.
  2. LocalFsBlobStore: Persists manifests/references in RelayKvStore and writes immutable chunk files under root_dir/staging/{session_hex}/{idx}.chunk and root_dir/chunks/{prefix}/{attachment_hex}/{idx}.chunk using atomic temp-file write + fsync + rename.
  3. S3BlobStore: Persists authoritative manifests/references in RelayKvStore and stores immutable chunk payloads in S3-compatible object storage using only the portable S3 REST subset (PUT, GET, HEAD, DELETE with AWS SigV4 Authorization and x-amz-content-sha256 payload 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 / LayerWhat It Can ObserveWhat It Cannot Learn or Alter
Relay / RelayKvStoreOpaque AttachmentId, chunk count, per-chunk ciphertext sizes, expires_at_ms, and message owner_ref digests.Plaintext bytes, KblobK_{\text{blob}}, filename, MIME type, media dimensions, or whether two users uploaded the same file.
S3 / Object Storage ProviderOpaque 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.

Frank & Cashweb High-Assurance Protocol Documentation