Skip to content

C12 - Install and Downloads

Purpose: The 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.

Verifies: S17-install-and-upgradeS17-install-and-upgrade: Install, Downloads and UpgradesBuild, install, upgrade and remove a Wraith Box bundle, move its stored data to a new version, and download what an image build needs from the internet.

  • Self-check (S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet.). Confined, wb-download fails to open a file under the home directory, to connect to TCP port 80 and to UDP port 123, and to run /bin/echo. It can connect to port 443 and lists the host’s interfaces with getifaddrs (TestConfined in cmd/wb-download). It completes a TLS fetch of the channel file on port 443 against the system roots (TestLiveChannel, which needs the internet and runs only with WB_DOWNLOAD_LIVE_TEST=1). The child’s file size limit is the entry’s, soft and hard, and it can’t raise it (TestConfined).

  • Self-check, not yet covered. Confined, wb-download fails to reach the Keychain services. The profile allows no mach-lookup but trustd’s, so a Keychain call has no service to reach. No probe makes one yet: Go’s standard library calls the Security framework only to check a server’s certificate, through trustd, which TestLiveChannel covers. A probe needs a Keychain call such as SecItemCopyMatching through cgo.

  • Start. An argument, an unknown entry, a program outside a bundle, a file size limit it can’t set, and each descriptor set outside the start interface are refused with their rules (TestChildStartRefusals, TestChildDescriptors, TestChildLogRefused, TestCheckStart, TestBundlePath). So is a Claude Code output that isn’t empty (TestServeClaudeOutputNotEmpty). A peer of another build version doesn’t get an end record (TestChildVersionRefused, TestServeVersionMismatch). A child that set its limit can’t write past it or raise it (TestSetStopsWrites in internal/platform/filelimit).

  • Deny tests. Through a local test server and a fake resolver, feed it each of these, and see each refused with its rule and a refused 4002 record that names it:

    • a host outside its entry, and plain HTTP (download-host-refused);
    • a redirect (download-redirect-refused);
    • a name that resolves to a private address, and a failure to list the host’s interfaces (upstream-address-refused);
    • a server that doesn’t accept the connection (download-connect-timeout), one that stops sending (download-idle-timeout), and one that sends past the request’s deadline (download-deadline);
    • a closed request pipe (download-cancelled);
    • a 200 to a range request, and a 206 with another Content-Range (download-range-refused);
    • a short body (download-short);
    • a manifest of 1 MiB and one byte (download-too-large).

    The tests are the TestC12Download ones in internal/download.

  • Bounds. A body longer than the size is written only up to the size. A write past the entry’s file size limit fails.

  • Proxy. A run with HTTPS_PROXY set to a local proxy sees the proxy get no connection (TestC12DownloadProxyUnused).

  • Runs. A restore run from offset 0, from a partial file, and from a whole one, which sends no GET. An offset above the size or other than the partial file’s, a request out of order, and a second request are refused with download-request-invalid. A channel run and a release run each fill their files (TestServe in internal/download).

  • Remote input in a run. A catalog whose image URL names another host, an IP address, a port, a user, or plain HTTP ends the run with download-catalog-invalid, and no request reaches the image host (TestServeHostileFirmwareURL). A status of 600 and a response that isn’t HTTP end it with download-response-invalid, and failed lookups and connects with upstream-resolve-failed and upstream-connect-failed. Each request is still reported (TestServeRemoteFailures). A catalog error that quotes a megabyte of the catalog is logged bounded (TestServeCatalogErrorBounded), and each restore image left out is logged with its reason (TestParseLeavesOut).

  • Self-check (S04-05-helper-programsS04-05-helper-programs: Helper ProgramsThe programs that run once for an image build or a store operation: wb-guestadmin, wb-release-check, wb-download and wb-build-ssh., “wb-release-check”). Confined, wb-release-check reads its four descriptors and writes a pass record. Its probes then fail to open a file under the home directory or to connect to TCP port 443. Running /bin/echo fails too (TestConfined in cmd/wb-release-check). It reads each release file from offset 0, wherever the shared offset is (TestConfined, TestFromStart).

  • Start. An argument is refused before confinement (TestArguments). Each descriptor set outside the start interface is refused with release-check-descriptor-invalid after the deny probe, and the child exits without a record (TestDescriptorRefused, TestLogRefused). Those include an unconnected socket and one whose peer closed, for the channel. A peer of another build version doesn’t get a record (TestVersionRefused). A release key that doesn’t parse refuses the start with release-check-key-invalid and no record (TestKeyRefused). A host end closed after the request leaves the record unwritten, logged with release-check-record-failed (TestRecordFailed). Each exits 1. A failed check and a request outside the form write the fail record of their rule (TestFailRecords).

  • Deny tests (S14-01-installS14-01-install: InstallHow the image build downloads Claude Code on the host, checks it, and installs it in the guest image, and which version a guest runs., “Check”). With a test key, feed the check each of these, and see each refused with its rule:

    • a changed manifest byte, a signature by another key, another key naming the release key’s fingerprint, a v3 signature, a text signature, two signature packets, and a signature over 64 KiB (claude-release-signature-invalid);
    • an older version under a newer request, and the reverse (claude-release-version-mismatch);
    • versions 2.1.288 and 2.0.999 (claude-release-below-minimum);
    • no darwin-arm64 entry (claude-release-no-platform);
    • another binary name (claude-release-binary-name);
    • a short binary, a long one, and another checksum (claude-release-binary-mismatch);
    • a signed manifest that isn’t JSON, and one over 1 MiB (claude-release-manifest-invalid);
    • a request outside the version form (release-check-request-invalid).

    The test is TestC12ReleaseCheck in internal/releasecheck.

  • The real release. The signed manifest of Claude Code 2.1.311 and its signature, in internal/releasecheck/testdata, verify with the compiled-in key. A stand-in binary then fails the size check, a changed size fails the signature, and the test key refuses the signature (TestRealRelease).

  • Parsers. The manifest parser refuses duplicate keys at each level it reads, values of the wrong type, and checksums and sizes outside their form (TestParseManifest). The OpenPGP subset refuses each armor, packet, and subpacket outside its one form, including a bare CR in the armor’s body (TestDearmor, TestParseSignatureRefusals, TestParsePublicKey and TestVerifyRefusals in internal/releasecheck/pgpsig). The record and request readers refuse each line outside their form, and every record fits in MaxRecord (TestParseRecordRefusals, TestRecordBound, TestRequest in internal/releasecheck/record). The one version form refuses a leading zero and a number with too many digits (TestParseVersion), and wb-download’s request check uses it.

  • The agent. The compiled-in key’s fingerprint is 31DD DE24 DDFA B679 F42D 7BD2 BAA9 29FF 1A7E CACE (TestReleaseKeyFingerprint in internal/agent/claude). The guest instructions file is at /Library/Application Support/ClaudeCode/CLAUDE.md, and its text names xcodebuild, the missing GUI login session, and swift test (TestGuestInstructions).

  • Result records. Feed it records with each field outside its form, a URL with a port, a user, a query, a fragment, an empty segment and a .. segment, and a 17th request, and see each end the run with download-record-form. The checks themselves are TestC12DownloadRecordForm in internal/download/record, which wb-hostd and wb-download share.

  • Restore image. See each refused with its rule:

    • a catalog entry below the minimum, with and without --allow-older-macos (restore-image-below-minimum);
    • an entry older than the last sealed image, without --allow-older-macos (restore-image-rollback). With the flag, it is accepted;
    • less free space than the entry’s file size limit, less the partial file, plus the floor (download-no-space);
    • a file of the right size with another SHA-1 (restore-image-hash-mismatch).

    A partial file that is a symbolic link isn’t opened. A changed entry truncates the partial file.

  • Claude Code. A file left in <data>/downloads/ is deleted at the build’s start. A version from outside the build’s input is refused. A channel file over 64 bytes, empty, with two line feeds, or with anything but a version, is refused (claude-channel-invalid). A channel version older than the last sealed Claude Code layer’s is refused (claude-release-rollback), and a sealed parent doesn’t move that floor. The same version from --claude-version is accepted. With no record any version above the minimum is accepted, and an unreadable state.db refuses the build (claude-release-floor-unknown). wb-release-check starts only after wb-download has exited.

  • Audit. A download record that can’t be written cancels the run with download-audit-failed.

Spec: S17-01-bundleS17-01-bundle: The BundleWhat a Wraith Box bundle holds, and how mise run build builds and signs it..

See each refused with its rule, and nothing written:

  • a bundle outside both Applications folders (setup-bundle-location);
  • a bare wb, an unstamped one, and one whose WBBuildVersion differs (setup-not-in-bundle);
  • a regular file, and a link into another directory, at ~/.local/bin/wb (setup-link-exists);
  • a changed plist with a VM running, with a same-version wb-hostd that can’t list its VMs, and with a wb-hostd of another build version, whose message names both versions (setup-vms-running);
  • a Mac without Apple Silicon or with an older macOS (setup-host-unsupported), and a Linux or Windows host (setup-host-later).

With an unchanged plist and a loaded agent, it leaves the agent running and asks wb-hostd nothing. With no wb-hostd listening, it goes on. It runs /bin/launchctl with only PATH in its environment. The plist is mode 644, written by rename. An old Wraith Box link is replaced, and a ~/.local/bin that isn’t on PATH gets the line to add. The projects root and the probe file are made when missing and left alone when present. The tests are the TestC12Setup ones in internal/setup and internal/platform/service, and the reader of WBBuildVersion is TestReadBuildVersion in internal/appbundle.

A failed backup, a failed migration, a newer database, and a renamed and an unknown configuration key each put wb-hostd in refusing mode with their rule, and it starts no daemon. An existing .bak name is kept. A backup file is mode 600. The tests are the TestC12 ones in internal/hostd/state, internal/config and internal/hostd/startup.

Bytes from the internet: Apple’s restore image catalog (FuzzParse), the Content-Range header (FuzzContentRange), and the result records wb-hostd reads from wb-download (FuzzResults). The requests wb-download reads from wb-hostd have FuzzRequests.

A Claude Code release’s signature and manifest: the armor (FuzzDearmor) and the signature packet (FuzzParseSignature) in internal/releasecheck/pgpsig, and the manifest parser (FuzzParseManifest) in internal/releasecheck. The result record wb-hostd reads from wb-release-check has FuzzParseRecord, and the request wb-release-check reads from wb-hostd has FuzzReadRequest, both in internal/releasecheck/record.

Status: Draft