Repository Public BSD-3-Clause
1# Map distribution API — `https://www.orixlab.dev/maps/v1/`23Status: **client implemented** (`CatalogClient`, `DownloadManager` in `Packages/ORIXMapPackage`), **files generated** by4`orix-package catalog` / `orix-package publish` (`Infrastructure/package-builder`), **server not implemented here**: this5document specifies what the Next.js route on the owner's node must do. The client was tested against an in-process6server and a real HTTP server on a loopback port that implement this specification; it was never run against7`www.orixlab.dev`.89Maps are downloaded from the ORIX Labs site the same way ORIX Astra downloads its local models: plain static files,10no account, no API key.1112## 1. Resources1314Everything is a static file under one versioned base. `v1` is the major version of the document schema.1516| Method and path | Content | `Cache-Control` |17|---|---|---|18| `GET /maps/v1/catalog.json` | every region with the summary of its current version | `public, max-age=300` |19| `GET /maps/v1/regions/<id>.json` | one region in detail (licences, components, zoom range) | `public, max-age=300` |20| `GET /maps/v1/regions/<id>/versions.json` | every published version of the region | `public, max-age=300` |21| `GET /maps/v1/files/<id>/<dataVersion>/<id>-<dataVersion>.orixmap` | the signed package (`docs/ORIXMAP_FORMAT.md`) | `public, max-age=31536000, immutable` |2223`<id>` is `[a-z0-9-]{1,64}`, `<dataVersion>` is a dotted decimal version (`2026.11.24`). Nothing else is served under24`/maps/v1/` (in particular not `pins.json`, a publisher-side file of the distribution directory).2526The distribution directory on the node has exactly this shape, so the route only maps URL paths to files:2728```29<distribution>/catalog.json30<distribution>/regions/ca-qc-montreal.json31<distribution>/regions/ca-qc-montreal/versions.json32<distribution>/files/ca-qc-montreal/2026.11.24/ca-qc-montreal-2026.11.24.orixmap33<distribution>/pins.json (publisher state, not served)34```3536## 2. Server requirements3738For every resource:3940- `ETag`: a **strong** entity tag equal to the lowercase hexadecimal SHA-256 of the file, in double quotes41 (`ETag: "70791b6b…9e8a"`). For artefacts it is the `sha256` of the catalog. Never a weak tag (`W/…`): the client42 refuses to resume without a strong one.43- `Content-Length` on 200 and 206 responses.44- `If-None-Match` → `304 Not Modified` when the tag matches.45- No `Set-Cookie`, no redirect to another host, no authentication.46- Rate limit: `429 Too Many Requests` with `Retry-After: <seconds>` (an HTTP date is also understood). The client never47 retries a 429 by itself: it reports the delay to the application.48- Unknown path: `404`.4950For artefacts (`files/…`):5152- `Accept-Ranges: bytes`; `Range: bytes=<first>-<last>` and `bytes=<first>-` → `206 Partial Content` with53 `Content-Range: bytes <first>-<last>/<total>`. Only single ranges are ever requested.54- `If-Range: "<etag>"`: when the tag does not match the current file, **ignore the range and answer `200` with the55 whole file** (RFC 9110 §13.1.5). This is how the client learns that the file changed under a partial download.56- A range starting at or after the end of the file → `416 Range Not Satisfiable`.57- `Content-Type: application/vnd.orix.map`; **no `Content-Encoding`** (the client sends `Accept-Encoding: identity`;58 byte ranges and digests are those of the stored file).59- A published artefact is **immutable**: its bytes never change under a given path. New data means a new60 `dataVersion`, hence a new path. (CryptoKit signatures are randomised, so re-running the builder on the same inputs61 produces different bytes: never overwrite a published file.)6263For JSON documents: `Content-Type: application/json`; transport compression is allowed.6465## 3. Documents6667Schema version: `{"major": 1, "minor": 0}` in every document. Clients ignore unknown members at every level and reject a68major they do not know with a typed error (`CatalogError.unsupportedSchema`) that the application presents as "update69the app". A minor bump only adds members. Timestamps are `YYYY-MM-DDTHH:MM:SSZ`. The three documents are generated by70`orix-package catalog`; the examples below are the real output for the development distribution built on 2026-11-25.7172### 3.1 `catalog.json`7374```json75{76 "schema": { "major": 1, "minor": 0 },77 "generatedAt": "2026-11-25T08:33:59Z",78 "regions": [79 {80 "id": "ca-qc-montreal",81 "names": { "en": "Greater Montréal", "fr": "Grand Montréal" },82 "bbox": { "minLat": 45.15, "minLon": -74.35, "maxLat": 45.95, "maxLon": -73.15 },83 "capabilities": ["map", "search", "routing"],84 "latest": {85 "dataVersion": "2026.11.24",86 "dataTimestamp": "2026-11-24T00:00:00Z",87 "buildDate": "2026-11-25T08:33:51Z",88 "downloadSize": 236150784,89 "installedSize": 236146599,90 "sha256": "70791b6b7f431328d3c14e29ad77b5f39a11545e2264a55bd60d1685cddf9e8a",91 "signingKeyId": "92853604e9033917",92 "path": "files/ca-qc-montreal/2026.11.24/ca-qc-montreal-2026.11.24.orixmap",93 "preambleSize": 152194 }95 }96 ]97}98```99100| Member | Meaning |101|---|---|102| `generatedAt` | when the publisher generated the document; a client never replaces a cached catalog by an older one |103| `regions[].id`, `names`, `bbox`, `capabilities` | copied from the manifest of the current package |104| `latest.dataVersion`, `dataTimestamp`, `buildDate` | version, OSM data date and build date of the current package |105| `latest.downloadSize` | size of the `.orixmap` file |106| `latest.installedSize` | size of the extracted components |107| `latest.sha256` | SHA-256 of the whole `.orixmap` file (= its ETag) |108| `latest.signingKeyId` | key that signed it; lets the application say "update the app" when it does not know the key |109| `latest.minAppVersion` | optional; oldest application version able to use the package |110| `latest.path` | artefact path **relative to the base URL** |111| `latest.preambleSize` | optional; bytes to request (`Range: bytes=0-<preambleSize-1>`) to get the signed manifest alone |112113Client-side validation: a region entry that is malformed, has an invalid `id`, or whose `path` is not a plain relative114path (segments of `[A-Za-z0-9._-]`, never `.` or `..`, no scheme, no query) is **dropped** and counted in115`Catalog.skippedRegions`; the other entries are kept. A path can therefore never leave the base URL.116117### 3.2 `regions/<id>.json`118119```json120{121 "schema": { "major": 1, "minor": 0 },122 "generatedAt": "2026-11-25T08:33:59Z",123 "region": { "id": "ca-qc-montreal", "names": { "…": "…" }, "bbox": { "…": 0 }, "capabilities": ["map", "search", "routing"],124 "latest": { "…same object as in catalog.json…": 0 } },125 "mapZoom": { "minZoom": 0, "maxZoom": 15 },126 "languages": ["en", "fr"],127 "licences": [128 { "source": "OpenStreetMap", "licence": "ODbL-1.0", "attribution": "© OpenStreetMap contributors",129 "url": "https://www.openstreetmap.org/copyright" },130 { "source": "Natural Earth", "licence": "Public domain", "attribution": "Made with Natural Earth",131 "url": "https://www.naturalearthdata.com/about/terms-of-use/" }132 ],133 "components": [134 { "id": "map", "length": 96370599, "mediaType": "application/vnd.pmtiles", "formatVersion": 3,135 "sha256": "2a9051192b6e6b12ebca351ba0f71c8d1ce5b57b7015a28ca9a8e2f7c87ea807" },136 { "id": "search", "length": 40460288, "mediaType": "application/vnd.sqlite3", "formatVersion": 1,137 "sha256": "ad542b9daacbdb9ad418ef518976a4e4c2c9335338015a58f37793a4e740bd01" },138 { "id": "routing", "length": 99315712, "mediaType": "application/vnd.orix.graph", "formatVersion": 1,139 "sha256": "aaa26d20a0f2f942f76a9b4a0566b4d873bea22872f371f6f33dd12267c30486" }140 ],141 "builder": { "orix-package": "1.0.0" }142}143```144145The client refuses a document whose `region.id` is not the one it asked for.146147### 3.3 `regions/<id>/versions.json`148149```json150{151 "schema": { "major": 1, "minor": 0 },152 "generatedAt": "2026-11-25T08:33:59Z",153 "id": "ca-qc-montreal",154 "latest": "2026.11.24",155 "versions": [156 { "dataVersion": "2026.11.24", "dataTimestamp": "2026-11-24T00:00:00Z", "buildDate": "2026-11-25T08:33:51Z",157 "downloadSize": 236150784, "installedSize": 236146599,158 "sha256": "70791b6b7f431328d3c14e29ad77b5f39a11545e2264a55bd60d1685cddf9e8a", "signingKeyId": "92853604e9033917",159 "path": "files/ca-qc-montreal/2026.11.24/ca-qc-montreal-2026.11.24.orixmap", "preambleSize": 1521 }160 ]161}162```163164`versions` is sorted newest first. `latest` is the version the catalog currently offers; after a publisher rollback it165is older than `versions[0]`.166167## 4. What the client sends168169One kind of request: `GET` of one of the four resources above. Headers sent by the application code:170171| Request | Headers |172|---|---|173| JSON documents | `Accept: application/json`, `If-None-Match: "<etag>"` when a cached copy exists |174| Artefact | `Accept-Encoding: identity`, and when resuming `Range: bytes=<n>-` + `If-Range: "<etag>"` |175| Preamble alone | `Accept-Encoding: identity`, `Range: bytes=0-<n>` |176177`URLSessionTransport` adds only `User-Agent: ORIXMaps/<version>` (fixed, generic), `Accept-Language: en` (fixed, so the178device language is not disclosed) and what HTTP itself needs (`Host`, `Connection`, and `Accept: */*` when the code set179none). Measured on the loopback server: the complete header set received is `host`, `user-agent`, `accept`,180`accept-language`, `accept-encoding`, `connection`.181182The session is `URLSessionConfiguration.ephemeral` with no cookie storage (`httpCookieStorage = nil`,183`httpShouldSetCookies = false`, accept policy `never`), no URL cache and no credential storage.184185**Never sent**: coordinates, search text, the list of installed regions, any identifier of the user, the device or the186installation, cookies, query strings. URLs are built from the base URL, a region identifier and a data version only.187188**What the server can still learn**, because HTTP makes it unavoidable: the IP address of the client, the time, and189which region package it downloads — hence a coarse indication of where the user is interested in. Someone watching the190network sees the host name (TLS SNI) and the transfer size, which can identify the region. The application should say so191in its privacy text; nothing else leaves the device.192193## 5. Client behaviour194195### 5.1 Catalog cache and offline use196197- Each document is cached on disk with its ETag, the date it was fetched and the date it was last confirmed by the198 server (`<cache>/catalog.json` + `catalog.meta.json`, `region-<id>…`, `versions-<id>…`). The cache is tied to the base199 URL.200- `catalog(refresh:)`: `.ifOlderThan(seconds: 300)` (default) answers from the cache while it is fresh, else201 revalidates with `If-None-Match`; `.always`; `.cacheOnly`.202- The result is a `CatalogSnapshot` with `origin`: `.network`, `.revalidated` (304), `.cache`, or203 `.staleCache(reason:)` — **any** failure (offline, 429, 5xx, undecodable or oversized document, unknown schema major,204 older document) falls back to the last good document, marked stale, with `fetchedAt` for the UI ("catalog from205 25 November"). Without a cached copy the error is thrown.206- Limits: a document larger than 8 MiB is refused; nothing invalid is ever written to the cache.207208### 5.2 Download, resume, verification2092101. **Space**: before any request, `downloadSize − alreadyDownloaded + installedSize + margin` (64 MiB by default) must211 be free → `DownloadError.notEnoughSpace(required:available:missing:)`.2122. **Transfer** to `<store>/staging/downloads/<id>-<version>.orixmap.part`, with a sidecar `.download.json` holding the213 request and the strong ETag of the first response.2143. **Resume** (after a broken connection, a pause, or an application relaunch): `Range: bytes=<size of the partial215 file>-` and `If-Range: "<etag>"`.216 - `206` with the expected `Content-Range` → the bytes are appended.217 - `200` with the same ETag → the server does not honour ranges: the transfer restarts from zero with that response.218 - `200` with another ETag, `206` with another total or ETag, or `416` → the file changed: the partial file is219 discarded and the error is `serverFileChanged` (refresh the catalog). Bytes of two files are never mixed.220 - No strong ETag was received → nothing is resumed, the transfer restarts from zero.2214. **Early check**: as soon as the partial file holds the preamble (a few kilobytes), its signature is verified and the222 manifest must name the requested region, version and size, and be installable (not a downgrade, application recent223 enough). A wrong or forged file is refused after one chunk, not after 300 MB.2245. **Broken transfers** are retried automatically from the partial file (exponential delay, 4 attempts without progress225 by default; any progress resets the count). `offline`, 429 and HTTP errors are reported immediately; the partial file226 is kept.2276. **End**: the size and the SHA-256 of the complete file are compared with the catalog (`sizeMismatch`,228 `checksumMismatch`), then `RegionStore.install` verifies the signature and every component again while extracting.2297. Never more than the announced size is written: a server that sends more is stopped (`sizeMismatch`).230231`DownloadManager.fetchManifest` implements "manifest alone": one Range request of `preambleSize` bytes (16 KiB when the232catalog gives no size, a second request if the preamble is longer), signature verified, nothing written to disk.233234## 6. Trust model235236**The catalog and the server are not trusted for integrity.** The only root of trust is the set of Ed25519 public keys237compiled into the application. The catalog's `sha256` and sizes are an early consistency check (they catch corruption238and a catalog/file mismatch cheaply); they are not a security boundary.239240What an attacker who controls the server, the DNS or the network path **cannot** do:241242| Attack | Why it fails | Test |243|---|---|---|244| Serve a modified package (and a catalog whose digest matches it) | component SHA-256 values are in the signed manifest | `serverControlledByAnAttackerCannotInstallAnything` (1) |245| Serve a package signed with its own key | key not in the trust store; refused when the preamble arrives | same (2) |246| Serve a genuine package of another region under this region's name | the signed `regionId` must equal the requested one | same (3) |247| Serve a genuine **older** package labelled as the new version | the signed `dataVersion` must equal the requested one | same (4) |248| Offer an older version of an installed region (rollback) | `RegionStore` refuses a downgrade unless the user forces it | `downgradeOfferedByTheCatalogIsRefusedEarly` |249| Replay an older `catalog.json` to a client that saw a newer one | `generatedAt` older than the cached one → cached copy kept, marked stale | `replayedOlderCatalogDoesNotReplaceANewerOne` |250| Make the client fetch from another site or path | `path` must be a plain relative path under the base URL | `forwardCompatibleDecoding`, `safeRelativePaths` |251| Write outside the store, overwrite application files | no name or path is taken from a package or from the catalog; region ids and versions are validated before they become directory names | fuzz tests, `hostileComponentIds` |252| Fill the disk or the memory | announced size checked against free space and never exceeded; manifest ≤ 1 MiB; catalog ≤ 8 MiB; components streamed | `notEnoughSpace`, `wrongChecksumAndWrongSize` |253| Mix components of two packages | one signature covers all component digests | `tamperedContentIsRejected` |254| Splice a changed file into a resumed download | `If-Range` + ETag, then whole-file SHA-256, then the signature chain | `serverFileChangedDuringResume` |255256What such an attacker **can** do, and how the client limits it:257258- **Denial of service**: refuse, slow down or truncate downloads. Installed maps keep working offline; partial files259 are resumed when the path works again.260- **Freeze**: keep serving a catalog that was current when the client first saw it, hiding newer versions. Nothing261 cryptographic prevents this without a trusted clock. The client exposes `generatedAt` and `fetchedAt` so that the262 application can display the age of the catalog and of each region's data (`dataTimestamp` is signed).263- **Rollback at first installation**: to a client that has neither a cached catalog nor the region installed, the264 attacker can present an old catalog and the matching old, genuine package. The user gets an authentic but outdated265 map; its signed data date is visible. Deleting a region also forgets the installed version (the store keeps no266 high-water mark after deletion).267- **Lie about what is available**: hide regions, announce wrong sizes or names. Wrong sizes are caught at the preamble268 (4 of 5.2) or at the end; names shown before download come from the catalog and are replaced by the signed ones once269 the manifest is fetched (`fetchManifest`).270- **Observe**: see section 4.271272Not done and worth considering later: signing `catalog.json` itself (same keys, detached signature) would turn "replay273of an old catalog" from detectable-if-seen-newer into forgeable-by-nobody, and give `generatedAt` a signer. It would not274solve freeze attacks without a freshness limit.275276## 7. Publishing, atomicity and rollback277278On the node, in the distribution directory:279280```sh281# one command: verify, copy to files/<id>/<version>/ (temporary file + rename), regenerate the three documents282orix-package publish ca-qc-montreal-2026.11.24.orixmap --dir /srv/orix-maps/v1 --trust production.trust.json283284# or, after copying files by hand: verify every package under files/ and regenerate285orix-package catalog --dir /srv/orix-maps/v1 --trust production.trust.json286```287288`catalog` fully verifies **every** package under `files/` (signature, layout, SHA-256 of each component) and checks that289each one sits at the canonical path for its signed region and version. One invalid, misplaced or unexpected file aborts290the command and leaves the published documents untouched.291292Order of writes, each one a temporary file followed by a rename (readers see the old or the new document, never a293partial one):2942951. the artefact, into `files/` (by `publish`);2962. `regions/<id>/versions.json`, then `regions/<id>.json`, for every region;2973. `catalog.json` — **last**, so that it never references an artefact or a document that is not in place;2984. documents of regions that have no package left are removed after the catalog stopped listing them.299300A crash between two steps leaves a catalog that is older than some region documents but always consistent with the301files on disk; re-running the command completes the publication.302303**Rollback** (a published version is bad):304305```sh306orix-package catalog --dir /srv/orix-maps/v1 --trust production.trust.json --latest ca-qc-montreal=2026.11.10307```308309`latest` points back to the previous version in `catalog.json`, `regions/<id>.json` and `versions.json`; the choice is310stored in `pins.json` and survives later regenerations until `--unpin ca-qc-montreal` (or until a newer version is311published and unpinned). The bad version stays listed in `versions.json` and on disk — delete its directory under312`files/` and run `catalog` again to withdraw it completely. Clients that already installed the bad version are **not**313downgraded automatically (downgrade refusal): the application sees an installed version newer than the catalog's and314can offer the user an explicit, forced reinstallation, or simply wait for the fixed version, which must carry a greater315`dataVersion` than the bad one.316317## 8. Not implemented / not verified318319- The server (Next.js route) is not part of this work; nothing here was tested against `www.orixlab.dev`.320- TLS, CDN behaviour, real rate limiting and HTTP/2-3 were not exercised (the loopback server is HTTP/1.1 over TCP).321- Background `URLSession` downloads are not implemented (see `Packages/ORIXMapPackage/README.md`).322- The catalog is not signed (section 6).323- No delta updates, no mirrors, no per-region statistics.324