Skip to content

S17-06 - Command Line Tools

Purpose: The steps by which wb-download and wb-hostd fetch and check Apple’s Command Line Tools for the base layer (S06-16-base-layerS06-16-base-layer: The Base LayerWhat the base layer holds, how the image build installs Apple's Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as.).

Requirements: SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter. (every egress decision recorded), SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped. (what the host spends is capped), NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it. (each refusal names its rule and the fix)

Tests: C12-install-and-downloadsC12-install-and-downloads: Install and DownloadsThe test cases for installing and upgrading Wraith Box: wb-download, wb-release-check, the checks wb-hostd makes on what it fetches, wb setup, and the migrations of state.db and configuration.

Brief: B150-named-imagesB150-named-images: Which VM runs a recipe, and how does a recipe build get through the proxy?A new recipe VM, `wb-vmd-recipe`, with a network of its own and the build CA installed at runtime and removed before sealing.

Each step runs under the rules of S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet., from the entry wb-download-clt. The guest gets the packages over the host-guest socket and has no network for them (S06-16-base-layerS06-16-base-layer: The Base LayerWhat the base layer holds, how the image build installs Apple's Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as., “No guest network in the base build”).

A build runs the entry twice: a catalog run that picks the product, then a package run that fetches its packages.

  1. wb-hostd sends the macOS version of the restore image the build installed.
  2. wb-download fetches Apple’s software update catalog for that major version from swscan.apple.com. The catalog path of each major version is compiled in. A version with no path fails with download-clt-catalog-unknown.
  3. The catalog is a gzip-compressed XML property list. wb-download reads at most 2 MiB compressed and 16 MiB decompressed.
  4. The candidates are the products that list a package named CLTools_Executables.pkg, newest PostDate first, at most 8.
  5. For each candidate in turn, it fetches the English distribution file from swdist.apple.com, at most 1 MiB, and takes the first that fits the guest:
    • its os-version range holds the guest’s macOS version;
    • its hostArchitectures holds arm64;
    • it has one choice, whose package references each name a package the catalog lists for the product.
  6. It reports the product ID, the version from the distribution file’s SU_VERS, and for each package in the choice’s order its name, URL, size and digest.

A catalog or distribution file that can’t be parsed, or lacks those keys, fails with download-catalog-invalid. A catalog without a candidate that fits fails with download-no-clt. The catalog and the distribution file parsers each have a fuzz target.

Before the package run, wb-hostd checks the version the catalog run reported, from the distribution file’s SU_VERS:

The flag accepts older tools as well as an older restore image. The text of each refusal it overrides says both.

The distribution file isn’t signed. After the install, step 5 of S06-16-base-layerS06-16-base-layer: The Base LayerWhat the base layer holds, how the image build installs Apple's Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as., “The Command Line Tools”, checks that the signed package’s receipt starts with that version. The package then matches what the floor checked. state.db records the receipt’s version, as wb-guestd reports it, cut to 64 bytes.

wb-hostd creates one output for each package in <data>/downloads/clt/, with O_CREAT | O_EXCL | O_NOFOLLOW and mode 600, and sends the reported list back as the request. wb-download refuses a list that isn’t the one it reported, or a count of outputs that doesn’t fit it, with download-request-invalid.

For each package, it sends a GET to its URL on swcdn.apple.com. It requires a 200 with a Content-Length equal to the size, writes the body, and stops reading at the size. A shorter body fails with download-short. A package run doesn’t resume: a failed run deletes the outputs, and the next build fetches them again.

After wb-launcher reports the exit, wb-hostd checks each package from its own descriptor:

  1. the size, with fstat;
  2. the XAR header: the magic xar!, a header size of at least 28, and the compressed table of contents’ length, within the file;
  3. the SHA-1 of those table of contents bytes, which must equal the catalog’s digest;
  4. the SHA-256 of the whole file, which wb-hostd keeps for the stream to the guest (S06-16-base-layerS06-16-base-layer: The Base LayerWhat the base layer holds, how the image build installs Apple's Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as., “The Command Line Tools”).

A mismatch deletes every package and fails the build with clt-package-hash-mismatch. The header parser has a fuzz target.

The catalog’s Digest is the SHA-1 of the table of contents, not of the whole file (B150-named-imagesB150-named-images: Which VM runs a recipe, and how does a recipe build get through the proxy?A new recipe VM, `wb-vmd-recipe`, with a network of its own and the build CA installed at runtime and removed before sealing., “Evidence”).

The catalog isn’t signed, and comes over TLS checked against the system trust store. wb-guestd checks Apple’s signature over the table of contents against a compiled-in Apple root before it installs anything (S06-16-base-layerS06-16-base-layer: The Base LayerWhat the base layer holds, how the image build installs Apple's Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as., “Apple’s signature”).

One property is still to be verified (I868I868 (open): Probe whether installer refuses a CLT package with changed files under a kept signatureS17-06-command-line-tools, "The trust base" (from #150): wb-guestd checks Apple's signature over a Command Line Tools package's table of contents with pkgutil --check-signature, then installs it with installer.): a package whose files were changed, with its table of contents and signature kept, fails installer. The table of contents holds the checksum of every file in the package. If installer checks them, a compromised wb-download or catalog can pick an older Apple package, which the floor bounds, but can’t change one. If it doesn’t, wb-guestd checks each file against the table of contents before the install.

A catalog run makes at most 9 requests, and a package run one for each package. Each stays within the 16 requests of S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet., “The result record”. A product with more than 15 packages fails with download-no-clt.

wb-hostd takes the newest product Apple’s catalog offers for the guest’s macOS, and doesn’t pin one.

Status: Draft