Repository Public License
1# Capsule format (`.orixcapsule`), version 123A capsule is one file holding a selection of a user's ORIX Navigator data, for backup or for moving it to another4device by any means (AirDrop, a USB key, a file share). Module: `SyncEngine` (`CapsuleExporter`, `CapsuleReader`,5`CapsuleImporter`). No third-party library: the container is implemented in the module, compression uses Apple's6`Compression` framework, cryptography uses CryptoKit and CommonCrypto.78## What a capsule can and cannot contain910Can, each only if the user selected it:1112| Kind | Content |13|---|---|14| `bookmarks` | bookmarks and folders of one profile (a selected folder brings its subtree) |15| `notes`, `canvases`, `workflows` | the items as stored |16| `spaces` | per space: name, symbol, tint and the list of open tabs as (URL, title, pinned) |17| `archives` + `archiveFile` | archive descriptions and their stored files |18| `canvasAttachment` | image/PDF files referenced by exported canvases |19| `history` | visits (URL, title, time, transition) — **only when the user explicitly ticks history** (`includeHistory`), and imported only when the importing user ticks it too (`importHistory`) |2021Cannot, by construction — the exporter has no code path that reads them and the format has no entry kind for them:22cookies and website storage (they live in WebKit, never in the app's database), secrets and API keys (Keychain),23settings, **permission decisions**, downloads, agent runs, WebKit session state of tabs, sync records and device24identifiers, the memory index, workflow run logs, profile names. A test fills a database with marker values in each25of these places and asserts that no marker appears in the file or in any decompressed entry.2627## Container layout2829All integers are big-endian.3031```32offset size field330 8 magic: ASCII "ORIXCAPS"348 2 container version = 13510 2 flags: bit 0 = encrypted; all other bits must be 03612 4 header length H (2 … 4096)3716 H header: UTF-8 JSON3816+H … body39```4041**Clear capsule** (flags = 0): header is exactly `{}`; body = `entries`, followed by a 32-byte SHA-256 digest of42every byte of the file before the digest.4344**Encrypted capsule** (flags = 1): header is4546```json47{"cipher":"AES-256-GCM","iterations":600000,"kdf":"PBKDF2-HMAC-SHA256","keyLength":32,"salt":"<base64, 16 bytes>"}48```4950and body = `nonce (12) ‖ ciphertext ‖ tag (16)`, the AES-256-GCM encryption of `entries`, with the first `16 + H`51bytes of the file (magic, version, flags, header length, header) as associated data.5253`entries`:5455```56repeat:57 u16 name length N (1 … 240); 0 ends the list58 N name, UTF-859 u8 compression: 0 = stored, 1 = raw DEFLATE (RFC 1951)60 u64 stored length S61 u64 original length L62 S bytes63u32 number of entries (must equal the number read)64```6566The first entry is `manifest.json`. Entries are sorted by name after it. A clear capsule is deterministic: the same67selection, the same data and the same `createdAt` give the same bytes.6869### Entry names7071Relative paths of at most 6 components made of `A–Z a–z 0–9 . - _`, no empty component, no `.` or `..`, no72component starting with `.` or `-`. Names used by version 1:7374```75manifest.json76data/bookmarks.json data/notes.json data/canvases.json data/workflows.json77data/spaces.json data/history.json data/archives.json78files/archives/<archive UUID>/<sanitised file name>79files/canvas/<canvas UUID>/<64 hex digits>.<png|jpg|gif|webp|heic|tiff|pdf>80```8182### Manifest8384```json85{86 "format": "orix.capsule",87 "formatVersion": 1,88 "createdAt": 1800000000,89 "appVersion": "1.0 (12)",90 "includesHistory": false,91 "items": [92 {"name": "data/bookmarks.json", "kind": "bookmarks", "count": 42, "byteSize": 9120, "sha256": "…64 hex…"}93 ]94}95```9697One item per entry other than the manifest. `byteSize` and `sha256` describe the uncompressed payload; `count` is98the number of records of a JSON entry (1 for a file). JSON payloads are arrays of the model types of NavigatorCore99(`Bookmark`, `Note`, `CanvasDocument`, `Workflow`, `Archive`) or of the two capsule-only shapes (space with tabs,100visit); dates are numbers of seconds since 1970; keys are sorted. Inside a capsule, `Archive.relativePath` is the101entry name of the archive's file.102103## Password protection104105- Key: PBKDF2-HMAC-SHA256 (CommonCrypto `CCKeyDerivationPBKDF`), 600 000 iterations, 16 random bytes of salt, 32-byte106 output. The password is normalised to Unicode NFC before derivation.107- Cipher: AES-256-GCM (CryptoKit), random 96-bit nonce, 128-bit tag, header authenticated as associated data.108- On reading, the iteration count must be between 100 000 and 10 000 000 and the cipher/KDF names must be exactly109 those above, so a crafted header can neither weaken the derivation nor stall the app.110111Limits, stated plainly:112113- **PBKDF2 is not memory-hard.** An attacker with the file can test passwords on GPUs or ASICs far faster than the114 app derives a key. 600 000 iterations slow each guess; they do not make a weak password safe. The protection is115 as strong as the password. (A memory-hard function such as Argon2id or scrypt is not available in CryptoKit or116 CommonCrypto, and the project takes no third-party dependency.)117- An encrypted capsule hides its content and its entry names and sizes; it does not hide its total size, nor that118 it is an ORIX capsule (magic and header are in clear).119- A wrong password and a modified file give the same error: they cannot be told apart.120- A **clear** capsule has an integrity digest, not a signature: it detects corruption, but anyone can produce a121 valid clear capsule. Nothing authenticates who made a capsule, encrypted or not (an encrypted one proves only122 knowledge of the password).123- The whole capsule is built and read in memory; the default limit is 1 GiB.124125## Reading: validation before anything else126127`CapsuleReader.open(data, password:)` returns a `CapsuleContents` or throws; it has no access to the database.128A capsule is rejected **as a whole** when any of these fails:1291301. Size ≤ the file limit; magic; container version (a higher version → `unsupportedVersion`); no unknown flag;131 header length and content.1322. Integrity: the SHA-256 digest (clear) or the GCM tag (encrypted). Any flipped byte of a clear capsule fails133 here or at step 1 — a test flips every byte, and truncates at every length.1343. Entry structure: every length is checked against the bytes that remain; no duplicate name; unknown compression135 refused; entry count matches; no trailing byte.1364. Sizes **before allocation**: declared original length ≤ 256 MiB per entry and ≤ 1 GiB in total; at most 20 000137 entries. A compressed entry is inflated into a buffer of exactly its declared size plus one byte, so an entry138 that inflates to more than it declares is detected without producing the excess ("zip bomb").1395. Names: the rules above; anything else → `unsafeName`.1406. Manifest: first entry, known format and version, and a one-to-one match with the entries (same names, same141 sizes, same SHA-256) — an unlisted entry, a missing one or a changed payload rejects the capsule.1427. Content: record counts equal to the manifest's; unique identifiers; URLs of bookmarks, notes, tabs, visits,143 archives and canvas page cards limited to `http`, `https`, `ftp`, `file`; text sizes bounded; canvas geometry144 finite and connections valid; canvas attachment references are content-hash names only; every file belongs to an145 item of the capsule; an archive's path is its own entry name; history present only if declared.146147## Importing: preview, then merge1481491. `CapsuleImporter.preview(contents, options:)` reads the destination and returns, per kind, how many items are150 new, identical or conflicting, plus remarks (history not ticked, archives without a folder…). It writes nothing.1512. `CapsuleImporter.apply(contents, options:)` merges with the chosen **conflict policy**, applied to items whose152 identifier already exists with different content:153154 | Policy | Effect |155 |---|---|156 | `keepBoth` | the incoming item is imported under a new identifier; the existing one is untouched |157 | `replace` | the existing item is overwritten |158 | `skip` | the existing item is kept, the incoming one ignored |159160 Identical items are never rewritten. Nothing is overwritten unless the policy is `replace`.161162Details:163164- Bookmarks, spaces, archives and history go to the profile given in the options (a stored profile is required).165 Parents are imported before children; a bookmark whose folder is neither in the capsule nor in the destination166 goes to the top level; under `keepBoth` children follow their (possibly renamed) parent.167- A space that already exists and differs is **never replaced**: under `replace` it is imported as a copy named168 "… (imported)". An imported space gets one window with dormant tabs (URL, title, pinned; nothing is loaded).169- Notes and canvases keep their space if it is imported with them or already exists; otherwise they are detached.170- Files are written only under the directories passed in the options, at paths the importer chooses171 (`capsule/<archive id>/<sanitised name>`, `<canvas id>/<hash name>`); a path found in the capsule is never used172 as a destination.173- History visits already present (same URL and time) are not duplicated.174- Importing the same capsule twice changes nothing the second time.175176The import is **not one transaction**: each item is written atomically through the public stores, in the order177spaces, bookmarks, notes, canvases, workflows, archives, history. A failure in the middle (disk full) leaves the178items already imported in place; running the import again completes it.179180## Compatibility181182- Readers reject container versions and manifest format versions they do not know.183- New optional manifest fields may be added without a version change; a new entry kind, a new compression method or184 a new cipher requires a new version.185186## Not verified187188- Capsules were only produced and read by this implementation, in tests, on macOS. No capsule has been moved189 between two real devices or read by an independent implementation (the tests do build containers by hand from190 this document to check the reader).191- Behaviour with very large capsules (hundreds of megabytes) was not measured; a 64 MiB decompression bomb is192 covered.193- No UI exists for the export sheet, the password prompt or the import preview.194- The export of archive files and canvas attachments depends on directories the app passes in; the app-side layout195 of those directories is not defined yet.196