diff --git a/SECURITY.md b/SECURITY.md index a74580bb..1c99ead3 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -140,6 +140,32 @@ with `--confirm-bypass`, which a program can pass, so the flag records a choice, `permissions allow`. `--by` records who the caller says asked; it is not authentication (PC-125). +## What `anchor install` touches + +`passioncode anchor install` (not in the help yet; a step of a guided install) checks a service package as the person +who runs it and then hands it to macOS's own Installer: Gatekeeper assessments must be on (`spctl --status`), the +package's SHA-256 must equal its line in the release's `SHA256SUMS` (and a deployment manifest's pin when one is given), +its GitHub build attestation must verify (`gh attestation verify`) as made by the anchor workflow on a pushed +`brain-anchor-v` tag (a build from any other ref is refused), and `pkgutil --check-signature` must read a +notarised Developer ID Installer signature of team `KJ35UYYL22` that chains to the Apple Root CA by its fingerprint. +`spctl -a -t install` is a further check only: it accepted a signed package with one byte changed, which `pkgutil` +refused (2026-11-25). The launcher refuses to run as root, never runs `sudo` and never reads or passes a password: +the password goes only into Installer's own prompt. It writes `~/.passioncode/brain-anchor.json` (the role, the +organisation for an organisation space, and the roster row the install step enrols; nothing else) and opens Installer +with `open -a Installer`. A failed check writes nothing and opens nothing. The limit of a check made as the person: +the package and the request sit where that user (and so any agent session of that user) can write, between the checks +and the moment Installer reads them. Gatekeeper's notarisation check applies to a package that carries the +download quarantine (a browser download does; a package taken with `gh run download` or copied by hand does not), and the package's own first elevated step compares its payload with the pin shipped inside the same package before +anything changes, which catches a modified payload of a genuine package but checks no signature and no team. So a +same-user swap, between the checks and Installer's read, of the package (for another team's notarised package, or a +package that Installer opens without a notarisation check) or of the request is not caught by the launcher; what still +holds is that the store paths come from the package, never from the request. This is a known limit (PC-250). +`spctl`, `pkgutil` and `open` run by their absolute paths under `/usr` (System Integrity Protection keeps them), never +through the person's `PATH`, so a shim a process of the same user puts on the `PATH` cannot report a check as passed; +`gh` is not a system tool and is found on the `PATH`, so a shimmed `gh` could fake the attestation check alone, while +the signature check still runs through `/usr/sbin/pkgutil`. The role is never defaulted: `--role` is required, and +without it nothing is checked or written. + ## What anonymous counts send Each command sends, when it ends, the events listed in [docs/analytics-events.md](docs/analytics-events.md) to diff --git a/bin/passioncode.js b/bin/passioncode.js index 9e75a453..e89bf62a 100755 --- a/bin/passioncode.js +++ b/bin/passioncode.js @@ -252,7 +252,7 @@ function analyticsCommand(rest) { async function main(argv) { const [cmd = 'help', ...rest] = argv; if (cmd === 'permissions') return await permissionsCommand(rest); - if (cmd === 'analytics') return analyticsCommand(rest); + if (cmd === 'analytics') return analyticsCommand(rest); if (cmd === 'anchor') return await anchorCommand(rest); // W7 T28a: anchorCommand at the end if (cmd === 'setup' || cmd === 'onboard' || cmd === 'doctor') { try { return await setupOrDoctor(cmd === 'onboard' ? 'setup' : cmd, rest); } catch (error) { threw = true; @@ -359,3 +359,25 @@ main(argv).then(async (code) => { const errorCode = cmd === 'doctor' && !argv.includes('--fix') && !threw ? 'check-failed' : 'other'; await require('../lib/analytics').after({ command: cmd, code, errorCode, json: argv.includes('--json'), quiet: argv.includes('--quiet'), existing, startedAt, version: VERSION, state: L.paths().state }); }); + +// W7 T28a: `anchor install`, the service package hand-off (lib/anchor.js). Checks as the person, then macOS Installer asks +// for the password in its own prompt. Not in the help yet: it is a step of the owner's sitting, run with its runbook. +async function anchorCommand(rest) { + const A = require('../lib/anchor'); + const json = rest.includes('--json'); + const [verb, ...args] = rest.filter((a) => a !== '--json'); + const o = { dryRun: false }; + const names = { '--pkg': 'pkg', '--url': 'url', '--sums': 'sumsFile', '--deploy': 'deployFile', '--role': 'role', '--org': 'org', '--row': 'row' }; + for (let i = 0; i < args.length; i++) { + if (args[i] === '--dry-run') { o.dryRun = true; continue; } + const key = names[args[i]]; + if (!key || args[i + 1] === undefined || o[key] !== undefined) return usage('anchor install takes --pkg PATH --sums PATH | --url URL, [--deploy FILE] --role person|owner|org-space [--org ORG] [--row ROW] [--dry-run] [--json]'); + o[key] = args[++i]; + } + if (verb !== 'install') return usage('anchor takes install'); + let r; + try { r = await A.anchor(o); } catch (error) { process.stderr.write(`passioncode: ${error.message}\n`); return 1; } + const lines = (r.checks || []).map((c) => `${c.ok ? 'ok ' : 'FAILED'} ${c.check.padEnd(16)} ${c.detail}`); + process.stdout.write(json ? JSON.stringify(r, null, 2) + '\n' : [...lines, r.message].join('\n') + '\n'); + return r.code; +} diff --git a/docs/analytics-events.md b/docs/analytics-events.md index 6463c7cc..11010bf9 100644 --- a/docs/analytics-events.md +++ b/docs/analytics-events.md @@ -33,7 +33,7 @@ for any other (`-rc.N`, `-beta.N`, a build tag). | `app_installed` | live | lib/analytics.js:164 | the first command on this machine that tries to send (a send that fails is not repeated, so an offline first run never reports it) | `existing`: `"true"` when the launcher was installed here before the counts existed (its `~/.passioncode/state.json` was there when the first run of a counting version started, whatever its flags; that answer is kept in `analytics.json`; so a machine an agent sets up with `setup --json` counts as a new install), `"false"` for a new install (a string, as every property: growth filters only string properties) | 2026-11-04 | | `app_updated` | live | lib/analytics.js:165 | the first command after the launcher's version changed (an update the SessionStart hook ran is counted at the next command, so it can arrive a session late) | `from`: the previous version | 2026-11-04 | | `app_active` | live | lib/analytics.js:168 | the first command of a UTC day on this machine (counts daily active machines; two commands that end at the same moment on a new day may both send it) | none | 2026-11-04 | -| `command_run` | live | lib/analytics.js:171 | every command, when it ends | `command`: `setup`, `doctor`, `update`, `status`, `restore`, `config`, `uninstall`, `permissions`, `analytics` or `help` (any other word is sent as `other`, never as typed; a new command gets a new value here in the same change, a removed one is marked retired and its value is never reused); `outcome`: `ok` (exit 0), `failed` (exit 1: a check or a step failed) or `usage` (exit 2: the words given were not a command the launcher takes); `duration`: `under-1s`, `1-10s`, `10-60s` or `over-60s` (the bounds are part of the series: other bounds would be a new property, never new meanings of these); `json`: `"true"` or `"false"` (strings) | 2026-11-04 | +| `command_run` | live | lib/analytics.js:171 | every command, when it ends | `command`: `setup`, `doctor`, `update`, `status`, `restore`, `config`, `uninstall`, `permissions`, `analytics`, `help` or `anchor` (`anchor` added 2026-11-25 with `anchor install`, W7 T28a; any other word is sent as `other`, never as typed; a new command gets a new value here in the same change, a removed one is marked retired and its value is never reused); `outcome`: `ok` (exit 0), `failed` (exit 1: a check or a step failed) or `usage` (exit 2: the words given were not a command the launcher takes); `duration`: `under-1s`, `1-10s`, `10-60s` or `over-60s` (the bounds are part of the series: other bounds would be a new property, never new meanings of these); `json`: `"true"` or `"false"` (strings) | 2026-11-04 | | `app_error` | live | lib/analytics.js:172 | a command that ends with exit 1 | `where`: the command, as above; `code`: `check-failed` for a plain `doctor` whose checks found a problem on the machine (not a fault in the launcher; not `doctor --fix`, whose exit 1 can be a failed repair, and not a run that ended on a thrown error; added 2026-11-04 before the first release) or `other` (fixed codes per failure come later, each added here first) | 2026-11-04 | Never sent: a path, a file or folder name, a user name, a rule, an argument, an app id the person typed, a token, an diff --git a/docs/backlog.md b/docs/backlog.md index b7ae9e88..47d6f94e 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -254,3 +254,5 @@ derives its common backlog from [backlog-sources.json](backlog-sources.json). | PC-246 | `PC-163: the server end of this account's own connection reads \`own\` from the real socket table` (`test/listener.test.js`) fails on a build machine whose `netstat` prints no row for the server end of the test's own loopback connection (`table-restricted … netstat printed no table`); it fails the same on unchanged `origin/main` `df80ead` there, 2026-11-24. Make the test skip with its reason where the table is restricted, or read the table the way that machine allows | open 2026-11-24: P3 | W2 session 06, full `npm test` on `agent/w2-s06-base1-owner-mac` (681 of 687 pass, 2 fail: this one and a strings.md drift fixed in the same branch) | | PC-247 | Pin Fabric Agent Adapter `v0.103.3` (`f9b87061`, npm `latest` 0.103.3 with the same `gitHead`, release run 45555348309 green) and release the launcher: check `git diff --name-status v0.102.0 v0.103.3 -- plugins/fabric-agent-adapter`, vendor with `--release`, run the full gate, release 0.2.84 | done 2026-11-25: released in 0.2.84: PR #367 merged as `9b408de` (merge commit), annotated tag `v0.2.84` on it, release run 45566649147 success (validate gate, node, macos, windows; release; publish), npm `latest` 0.2.84 published 2026-11-25T07:36:45Z, `gitHead` `9b408de`, SLSA provenance; the published tarball carries adapter plugin 0.103.3. Gate on `5cc0fd0`: full `npm test` 689 tests, 685 pass, 0 fail, 4 skipped (Windows only); `vendor:release` exit 0; `claude plugin validate ./payload --strict` passed; check-docs 0 errors. The diff `v0.102.0..v0.103.3` adds three scripts, modifies 28 files, removes none. Open: this Mac's install waits on free disk (the disk sentry refuses installs below 14 GB; 12 GB on 2026-11-25). The Fabric Base 1 line stays on 0.2.83 until fabric-workspace moves the base manifest. Handoff `docs/handoffs/2026-11-25-release-0.2.84.md` | board request `645b9e02` from fabric-agent-adapter (thread `2b08b15f`), deadline 2026-11-28 | | PC-248 | R5 of the harness-loss audit (H-06): the session-start course line (`plugin/passioncode/hooks/repo-rules.js`), `working-in-passioncode` §0 and `AGENTS.md` named the unified plan of 2026-11-11 after the system design of 2026-11-21 became the plan of record (fabric-workspace `AGENTS.md:10`, `knowledge/rules.md:32`). Read the plan from the knowledge base, not as a string: point at rules §0, which names it | done 2026-11-25: released in 0.2.84: PR #367 merged as `9b408de` (merge commit), annotated tag `v0.2.84` on it, release run 45566649147 success (validate gate, node, macos, windows; release; publish), npm `latest` 0.2.84 published 2026-11-25T07:36:45Z, `gitHead` `9b408de`, SLSA provenance; the published tarball carries the new course line (no `2026-11-11-unified` in `hooks/repo-rules.js`). Test `PC-248: …` in `test/repo-rules.test.js` failed before the fix and passes with it. R8 (H-10, Codex plugin versions and hooks) belongs to the adapter and Switchboard | board request `ca9354fa` from fabric-workspace (thread `5552be73`), deadline 2026-11-26 | +| PC-249 | W7 T28a, the service package hand-off: `passioncode anchor install` (`lib/anchor.js`, `test/anchor.test.js`, SECURITY.md "What `anchor install` touches") checks a package as the person (Gatekeeper on, SHA256SUMS and a manifest pin, the build attestation, `pkgutil` signature of team `KJ35UYYL22` to the Apple Root CA, `spctl`, the embedded pin) and hands it to macOS Installer; never sudo. Left: a help line and strings.md rows when it ships, and a launcher release after the owner's sitting (T28d) proves it on the live package | open 2026-11-25: built on branch `w7-anchor-launcher-2026-11-25`, not merged, not released | Studio session 45 (W7 trust-anchor lane, thread `bb204715`); fabric-workspace `w7-anchor-2026-11-25` `tools/brain/anchor/` | +| PC-250 | The anchor hand-off's same-user window (W7 T28a, review round 1 of Studio session 59): `passioncode anchor install` checks the package and writes `~/.passioncode/brain-anchor.json` as the person, so any process of that user (an agent session included) can swap the package (for another team's notarised package, or a self-built package Installer opens without a notarisation check, whose own pin matches its own payload) or rewrite the request, between the checks and the moment macOS Installer reads them; the package's first step compares only its payload with its own pin, and Installer checks no team. SECURITY.md "What `anchor install` touches" names the limit. The same user can also shim `gh` on the `PATH` (it is found there; `spctl`, `pkgutil` and `open` run by absolute path since review round 8), which fakes the attestation check alone. A fix needs a hand-off the user cannot write between check and read (for example the package's own first elevated step checking the team of its own signature, or Installer reading a copy the user cannot change) | open 2026-11-25 | Studio session 59, review finding 9 of round 1 (W7 trust-anchor lane, thread `bb204715`); nothing in T28a's done line depends on it (the payload still aborts off its pin) | diff --git a/docs/handoffs/2026-11-25-w7-anchor-launcher.md b/docs/handoffs/2026-11-25-w7-anchor-launcher.md new file mode 100644 index 00000000..d7d66866 --- /dev/null +++ b/docs/handoffs/2026-11-25-w7-anchor-launcher.md @@ -0,0 +1,56 @@ +# Handoff: the service package hand-off on the launcher (W7 trust-anchor lane, Studio session 45), 2026-11-25 + +Objective: task T28a's launcher part: fetch the trust anchor's installer package, check it as the person and hand it +to macOS Installer, which alone asks for the administrator password. Program thread `bb204715`. Backlog row: PC-249 in +[docs/backlog.md](../backlog.md) (with PC-250, the same-user window; numbered PC-247 and PC-248 on this branch +until `main` took those ids for release 0.2.84). The package, its workflow and its machine proof live in fabric-workspace, branch +`w7-anchor-2026-11-25`, `tools/brain/anchor/` (handoff `docs/handoffs/2026-11-25-w7-anchor-lane.md` there). + +## Done + +- `lib/anchor.js` and `passioncode anchor install --pkg PATH --sums PATH | --url URL [--deploy FILE] --role + person|owner|org-space [--org ORG] [--row ROW] [--dry-run] [--json]` (dispatched from `bin/passioncode.js`, the function at the + file's end so no line a strings.md row cites moves). Checks in order: Gatekeeper on, SHA-256 against SHA256SUMS and + a deployment manifest's pin, `gh attestation verify` for `passioncode-ai/fabric-workspace`'s `brain-anchor.yml`, made on a pushed `brain-anchor-v` tag (any other source ref refused), + `pkgutil --check-signature` (notarised, Developer ID Installer of `KJ35UYYL22`, Developer ID CA, Apple Root CA by + fingerprint, the manifest's certificate pin), `spctl -a -t install`, the embedded pin (shown with its commit; equal to the manifest's + tool tree hash when given; a manifest that pins no package sha256 is refused). Then it writes + `~/.passioncode/brain-anchor.json` (role, organisation, roster row) and runs `open -a Installer`. +- SECURITY.md: "What `anchor install` touches", with the same-user window between the checks and Installer's read, + and the system tools run by absolute path (`TOOL` in `lib/anchor.js`; `gh` from the `PATH`), the role required + (review round 8 of Studio session 59) + (PC-250). +- Studio session 59 (integration and blind review rounds): the attestation's source ref, `--row`, the manifest's + package pin, PC-250; `origin/main` merged in. + +## Checks actually run + +- Session 59, after merging `origin/main` `7421947` (0.2.84) at `6340353`: `node --test test/anchor.test.js` 22 of 22; + full `npm test` 711 tests, 706 pass, 4 skipped, 1 fail (the known PC-246: the PC-163 socket-table test fails the same + on unchanged `origin/main` `7421947` on this machine, run again 2026-11-25); IP gate (public) on the merge's changes + and the PR text: pass. +- Session 59: `node --test test/anchor.test.js` 22 of 22 (at `cb27ada`, review round 8: the role required, the system + tools by absolute path); full `npm test` (on `8270c92`) 703 tests, 698 pass, 4 skipped, 1 fail (the + known PC-246); IP gate (`public:npm-passioncode`) on the changed `lib/anchor.js`, `bin/passioncode.js`, SECURITY.md, + the PC-250 row and the commit messages: pass. + +- Session 45: `node scripts/test.mjs test/anchor.test.js`: 15 of 15 (fixtures are real `pkgutil` outputs, `test/fixtures/anchor`; + one test builds an unsigned package with the real `pkgbuild` and sees the real `pkgutil` refuse it). +- Full `npm test` on this machine: 678 tests, 672 pass, 4 skipped, 1 fail: PC-163's socket-table test, the known PC-246 + failure of this build machine (fails the same on unchanged `origin/main`). `test/setup.test.js` was cut by the run's + time cap and ran again on its own with help, strings, no-em-dash, repo-rules and docs: 195 of 195, exit 0. +- IP gate (`ip_gate.py scan --destination public:npm-passioncode`) on `lib/anchor.js`, the CLI lines and the SECURITY + section: pass. +- The same refusals by the Python twin of this check on a real machine (fabric-workspace `assert_identity.py`, the same + `pkgutil` reading; the VM never ran `lib/anchor.js`): `tools/brain/anchor/evidence/` there (the unsigned, tampered, + flipped-byte and other-team packages refused by the agents' user before any elevation). + +## Open + +- Not merged and not released (W7 runs on branches; a launcher release follows the owner's sitting, T28d). +- A help line and strings.md rows when the command ships to people. + +## The next task + +After T28d's first signed package exists: download the workflow's artifact (`gh run download -R passioncode-ai/fabric-workspace -n brain-anchor-signed`: nothing is published as a release) and run `passioncode anchor install --pkg --sums --role owner --dry-run` on the +MacBook as the owner, then merge this branch through a PR and release the launcher. diff --git a/lib/analytics.js b/lib/analytics.js index 34a6194a..28417637 100644 --- a/lib/analytics.js +++ b/lib/analytics.js @@ -24,7 +24,7 @@ const APP_KEY = /^A-[A-Z]{2,4}-\d{10}$/; const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; // an app may write it upper case: sent as written const SEND_MS = 2000; // The words a property may carry; anything else is dropped (a free string could hold a name or a path). -const COMMANDS = new Set(['setup', 'doctor', 'update', 'status', 'restore', 'config', 'uninstall', 'permissions', 'analytics', 'help']); +const COMMANDS = new Set(['setup', 'doctor', 'update', 'status', 'restore', 'config', 'uninstall', 'permissions', 'analytics', 'help', 'anchor']); const OUTCOMES = new Set(['ok', 'failed', 'usage']); // check-failed: a plain doctor whose checks found a problem on the machine (not --fix, not a thrown error); other: the rest. const ERROR_CODES = new Set(['check-failed', 'other']); diff --git a/lib/anchor.js b/lib/anchor.js new file mode 100644 index 00000000..dee991a5 --- /dev/null +++ b/lib/anchor.js @@ -0,0 +1,246 @@ +'use strict'; +/** + * The service package hand-off (`passioncode anchor`): fetch an installer package, check it as the person (never as + * root), and hand it to macOS's own Installer, which shows the administrator password prompt. The launcher never runs + * sudo, never reads or passes a password, and stops before the hand-off on the first failed check: + * 1. the machine: Gatekeeper assessments enabled (`spctl --status`); + * 2. the bytes: the package's SHA-256 equals its line in the release's SHA256SUMS, and the pinned value when a + * deployment manifest is given; + * 3. the build: the GitHub attestation of the package verifies for the expected repository and workflow; + * 4. the signature: `pkgutil --check-signature` reads signed by Apple for distribution, notarised, a Developer ID + * Installer certificate of the PassionCode.ai team, the Developer ID CA and the Apple Root CA by its fingerprint. + * `pkgutil` is required: `spctl -a -t install` alone accepted a signed package with a flipped byte (measured + * 2026-11-25), so it is a further check, never the only one; + * 5. the contents: the package's embedded pin is shown (its tree hash), and must equal the manifest's when given. + */ +const crypto = require('crypto'); +const fs = require('fs'); +const os = require('os'); +const path = require('path'); +const catalog = require('./catalog'); + +const ROOT_CA_SHA256 = 'B0B1730ECBC7FF4505142C49F1295E6EDA6BCAED7E2C68C5BE91B5A11001F024'; // Apple Root CA +const STATUS_OK = 'signed by a developer certificate issued by Apple for distribution'; +const NOTARY_OK = 'trusted by the Apple notary service'; +const REPO = 'passioncode-ai/fabric-workspace'; +const WORKFLOW = `${REPO}/.github/workflows/brain-anchor.yml`; +const ROLES = ['person', 'owner', 'org-space']; +// The system tools run by absolute path (SIP-protected), never through the person's PATH, where a process of the same +// user could put a shim that reports ok. `gh` is not a system tool and is found on the PATH: a shimmed `gh` can only +// fake the attestation check; the signature check still runs through /usr/sbin/pkgutil (SECURITY.md, PC-250). +const TOOL = { spctl: '/usr/sbin/spctl', pkgutil: '/usr/sbin/pkgutil', open: '/usr/bin/open' }; + +function defaultRun(cmd, args, opts) { return require('./releases').run(cmd, args, opts); } + +/** `pkgutil --check-signature` output: status, notarisation, and the certificate chain with SHA-256 fingerprints. */ +function parsePkgutil(text) { + const status = /^\s*Status:\s*(.+)$/m.exec(text); + const notary = /^\s*Notarization:\s*(.+)$/m.exec(text); + const chain = []; + const lines = text.split('\n'); + for (let i = 0; i < lines.length; i++) { + const m = /^\s*(\d+)\.\s+(.+?)\s*$/.exec(lines[i]); + if (!m) continue; + let j = i + 1; + while (j < lines.length && !/SHA256 Fingerprint:/.test(lines[j]) && !/^\s*\d+\.\s/.test(lines[j])) j++; + if (j >= lines.length || !/SHA256 Fingerprint:/.test(lines[j])) continue; + let hex = ''; + for (let k = j + 1; k < lines.length && /^\s+([0-9A-F]{2}\s?)+\s*$/.test(lines[k]); k++) hex += lines[k].replace(/\s+/g, ''); + chain.push({ n: Number(m[1]), name: m[2], sha256: hex }); + } + return { status: status ? status[1].trim() : null, notarization: notary ? notary[1].trim() : null, chain }; +} + +/** Null when the signature is the PassionCode.ai team's Developer ID Installer chain, else the reason. */ +function signatureProblem(text, { team = catalog.TEAM_ID, certSha256 = null } = {}) { + const p = parsePkgutil(text); + if (p.status !== STATUS_OK) return `signature: ${p.status || 'none'}`; + if (p.notarization !== NOTARY_OK) return `notarisation: ${p.notarization || 'none'}`; + if (p.chain.length !== 3) return `certificate chain of ${p.chain.length}, not leaf, Developer ID CA and Apple Root CA`; + const [leaf, mid, root] = p.chain; + if (!leaf.name.startsWith('Developer ID Installer:') || !leaf.name.endsWith(`(${team})`)) return `signed by ${leaf.name}, not a Developer ID Installer of team ${team}`; + if (mid.name !== 'Developer ID Certification Authority') return `intermediate ${mid.name}`; + if (root.name !== 'Apple Root CA' || root.sha256 !== ROOT_CA_SHA256) return 'the chain does not end at the Apple Root CA'; + if (certSha256 && leaf.sha256.toUpperCase() !== certSha256.toUpperCase()) return `installer certificate ${leaf.sha256} is not the pinned one`; + return null; +} + +function sha256File(file) { + const h = crypto.createHash('sha256'); + const fd = fs.openSync(file, 'r'); + try { + const buf = Buffer.alloc(1 << 20); + let n; + while ((n = fs.readSync(fd, buf, 0, buf.length, null)) > 0) h.update(buf.subarray(0, n)); + } finally { fs.closeSync(fd); } + return h.digest('hex'); +} + +/** The SHA-256 a SHA256SUMS text gives for a file name, or null. */ +function sumFor(sumsText, name) { + for (const line of String(sumsText).split('\n')) { + const m = /^([0-9a-f]{64})\s+\*?(.+)$/.exec(line.trim()); + if (m && m[2] === name) return m[1]; + } + return null; +} + +/** The pin embedded in the package's scripts (read with pkgutil, nothing executed). */ +function readPin(pkg, { run = defaultRun, tmp = os.tmpdir() } = {}) { + const dir = fs.mkdtempSync(path.join(tmp, 'pc-anchor-')); + const out = path.join(dir, 'x'); + try { + const r = run(TOOL.pkgutil, ['--expand-full', pkg, out], { timeout: 300000 }); + if (r.code !== 0) return { error: `pkgutil --expand-full: ${(r.err || r.out).trim().split('\n')[0]}` }; + const candidates = [path.join(out, 'component.pkg', 'Scripts', 'pin.json'), path.join(out, 'Scripts', 'pin.json')]; + const file = candidates.find((f) => fs.existsSync(f)); + if (!file) return { error: 'the package carries no pin' }; + const pin = JSON.parse(fs.readFileSync(file, 'utf8')); + if (!/^[0-9a-f]{64}$/.test(pin.tree_hash || '')) return { error: 'the pin holds no tree hash' }; + return { pin }; + } catch (error) { + return { error: `the pin is unreadable: ${error.message}` }; + } finally { fs.rmSync(dir, { recursive: true, force: true }); } +} + +/** The workflow signs only on a pushed tag (fabric-workspace brain-anchor.yml); a build from any other ref is refused. */ +const TAG_PREFIX = 'brain-anchor-v'; +const ROW = /^[a-z0-9][a-z0-9._:-]{2,80}$/; + +/** Null when every verified attestation was made on a brain-anchor-v tag, else the reason. */ +function attestedRefProblem(out) { + let list; + try { list = JSON.parse(out); } catch { return 'the attestation answer is not JSON'; } + if (!Array.isArray(list) || list.length === 0) return 'no verified attestation in the answer'; + for (const item of list) { + const ref = item && item.verificationResult && item.verificationResult.signature && item.verificationResult.signature.certificate + ? item.verificationResult.signature.certificate.sourceRepositoryRef : null; + if (typeof ref !== 'string' || !new RegExp(`^refs/tags/${TAG_PREFIX}\\d+\\.\\d+\\.\\d+$`).test(ref)) { + return `attested from ${ref || 'an unnamed ref'}, not a ${TAG_PREFIX} tag`; + } + } + return null; +} + +/** + * Every check before the hand-off. Returns { ok, checks, pin }. `deploy` is a parsed deployment manifest (optional): + * its tool.package.sha256, tool.package.signer_certificate_sha256 and tool.tree_hash are then pinned too. + */ +function verify(pkg, { sums, deploy = null, run = defaultRun, team = catalog.TEAM_ID, requireAttestation = true } = {}) { + const checks = []; + const add = (check, ok, detail) => { checks.push({ check, ok, detail }); return ok; }; + const done = (pin = null) => ({ ok: checks.every((c) => c.ok), checks, pin }); + + const status = run(TOOL.spctl, ['--status'], { timeout: 20000 }); + const st = `${status.out}${status.err}`.trim(); + if (!add('gatekeeper', st === 'assessments enabled', st || 'no answer')) return done(); + + const sha = sha256File(pkg); + const listed = sumFor(sums, path.basename(pkg)); + if (!add('sha256', listed === sha, listed ? (listed === sha ? sha : `${sha} differs from SHA256SUMS ${listed}`) : `${path.basename(pkg)} is not in SHA256SUMS`)) return done(); + const pinned = deploy && deploy.tool && deploy.tool.package ? deploy.tool.package : null; + // A manifest pins the package bytes (brain-deploy/0.1 tool.package.sha256): without them it would pin only the tool + // tree hash, which a package with the same tool and another anchor runtime also carries. + if (deploy && !(pinned && /^[0-9a-f]{64}$/.test(pinned.sha256 || ''))) { + add('manifest-sha256', false, 'the deployment manifest pins no package sha256'); + return done(); + } + if (pinned && !add('manifest-sha256', pinned.sha256 === sha, pinned.sha256 === sha ? 'equals the deployment manifest' : `the deployment manifest pins ${pinned.sha256}`)) return done(); + + if (requireAttestation) { + const a = run('gh', ['attestation', 'verify', pkg, '--repo', REPO, '--signer-workflow', WORKFLOW, '--format', 'json'], { timeout: 120000 }); + const refProblem = a.code === 0 ? attestedRefProblem(a.out) : null; + const detail = a.code === 127 ? 'gh is not installed; the build attestation cannot be checked' + : a.code !== 0 ? (a.err || a.out).trim().split('\n').pop() + : refProblem || `attested by ${WORKFLOW} on a ${TAG_PREFIX} tag`; + if (!add('attestation', a.code === 0 && !refProblem, detail)) return done(); + } + + const sig = run(TOOL.pkgutil, ['--check-signature', pkg], { timeout: 60000 }); + const problem = signatureProblem(sig.out, { team, certSha256: pinned ? pinned.signer_certificate_sha256 : null }); + if (!add('signature', !problem, problem || `Developer ID Installer of ${team}, notarised`)) return done(); + + const gk = run(TOOL.spctl, ['-a', '-vv', '-t', 'install', pkg], { timeout: 120000 }); + const src = /source=([^\n]+)/.exec(`${gk.err}\n${gk.out}`); + if (!add('assessment', gk.code === 0 && !!src && src[1].trim() === 'Notarized Developer ID', src ? `source=${src[1].trim()}` : `spctl exit ${gk.code}`)) return done(); + + const { pin, error } = readPin(pkg, { run }); + if (!add('pin', !!pin, pin ? `payload tree hash ${pin.tree_hash}, tool tree hash ${pin.tool_tree_hash}, built at commit ${pin.tool_commit || 'unnamed'}` : error)) return done(); + // A fixture package is a test vector, never signed by the workflow; one that reached here is refused all the same. + if (pin.fixture === true && !add('pin-mode', false, 'a fixture package (test only)')) return done(); + if (deploy && deploy.tool && deploy.tool.tree_hash) { + add('manifest-tool', pin.tool_tree_hash === deploy.tool.tree_hash, pin.tool_tree_hash === deploy.tool.tree_hash ? 'tool tree hash equals the deployment manifest' : `tool tree hash ${pin.tool_tree_hash} is not the manifest's ${deploy.tool.tree_hash}`); + } + return done(pin); +} + +/** + * The request the package reads from the person's home: the role, the organisation of an organisation space, and the + * roster row the install step enrols (the Studio made the row; the code then shows in the installer's own window). + */ +function requestProblem({ role, org = null, row = null }) { + if (role === null || role === undefined) return `name the role with --role ${ROLES.join('|')}: it is never defaulted`; + if (!ROLES.includes(role)) return `role must be one of ${ROLES.join(', ')}`; + if (role === 'org-space' && !/^[a-z][a-z0-9-]{1,20}$/.test(org || '')) return 'an organisation space needs --org'; + if (role !== 'org-space' && org) return '--org belongs to an organisation space only'; + if (row !== null && !ROW.test(row)) return '--row must be a roster row id'; + return null; +} + +function writeRequest(home, { role, org, row = null }) { + const problem = requestProblem({ role, org, row }); + if (problem) throw new Error(problem); + const dir = path.join(home, '.passioncode'); + fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); + const file = path.join(dir, 'brain-anchor.json'); + const tmp = `${file}.tmp`; + const body = { role, ...(role === 'org-space' ? { org } : {}), ...(row ? { row } : {}) }; + fs.writeFileSync(tmp, JSON.stringify(body) + '\n', { mode: 0o600 }); + fs.renameSync(tmp, file); + return file; +} + +/** Hand the checked package to macOS's Installer, which asks for the administrator password itself. */ +function handOff(pkg, { run = defaultRun } = {}) { + const r = run(TOOL.open, ['-a', 'Installer', pkg], { timeout: 30000 }); + return { ok: r.code === 0, detail: r.code === 0 ? 'handed to macOS Installer; type the password only into its own prompt' : (r.err || r.out).trim() }; +} + +async function fetchRelease(url, dir) { + const { download } = require('./releases'); + const name = decodeURIComponent(url.split('/').pop()); + if (!/^[A-Za-z0-9._+-]+\.pkg$/.test(name)) throw new Error(`not a package URL: ${url}`); + const pkg = path.join(dir, name); + await download(url, pkg); + const sumsUrl = url.replace(/[^/]+$/, 'SHA256SUMS'); + const res = await fetch(sumsUrl, { headers: { 'User-Agent': 'passioncode-launcher' }, signal: AbortSignal.timeout(60000) }); + if (!res.ok) throw new Error(`${sumsUrl}: HTTP ${res.status}`); + return { pkg, sums: await res.text() }; +} + +/** The whole command. Exit codes: 0 handed off (or checked, with dryRun), 1 a check failed, 2 usage. */ +async function anchor({ pkg, url, sumsFile, deployFile, role = null, org = null, row = null, dryRun = false, uid = process.getuid ? process.getuid() : null, home = os.homedir(), run = defaultRun, platform = process.platform }) { + if (platform !== 'darwin') return { code: 2, message: 'the service package installs on macOS only' }; + if (uid === 0) return { code: 2, message: 'run it as yourself, without sudo: macOS Installer asks for the administrator password in its own prompt' }; + if (!pkg === !url) return { code: 2, message: 'name the package with --pkg PATH (and --sums PATH) or --url URL' }; + // The request is checked before any download or check, so a dry run proves the words the real run will take. + const problem = requestProblem({ role, org, row }); + if (problem) return { code: 2, message: problem }; + let sums; + if (url) { + // The download stays in the temp folder: Installer reads the package after `open` returns. + ({ pkg, sums } = await fetchRelease(url, fs.mkdtempSync(path.join(os.tmpdir(), 'pc-anchor-dl-')))); + } else { + if (!sumsFile) return { code: 2, message: '--pkg needs --sums, the release SHA256SUMS' }; + sums = fs.readFileSync(sumsFile, 'utf8'); + } + const deploy = deployFile ? JSON.parse(fs.readFileSync(deployFile, 'utf8')) : null; + const v = verify(pkg, { sums, deploy, run }); + if (!v.ok) return { code: 1, message: 'refused before elevation; nothing was installed', ...v }; + if (dryRun) return { code: 0, message: 'every check passed; dry run: not handed to the Installer', ...v }; + const request = writeRequest(home, { role, org, row }); + const h = handOff(pkg, { run }); + return { code: h.ok ? 0 : 1, message: h.detail, request, ...v }; +} + +module.exports = { TOOL, anchor, verify, signatureProblem, parsePkgutil, sumFor, readPin, writeRequest, handOff, ROOT_CA_SHA256, WORKFLOW }; diff --git a/test/anchor.test.js b/test/anchor.test.js new file mode 100644 index 00000000..3dcca5f4 --- /dev/null +++ b/test/anchor.test.js @@ -0,0 +1,193 @@ +'use strict'; +delete process.env.CLAUDE_CONFIG_DIR; +delete process.env.SWITCHBOARD_CLAUDE_SOURCE_DIR; +// W7 T28a: the service package hand-off. Every check runs as the person before macOS Installer is opened; a modified or +// unsigned package, a package of another team, a Gatekeeper that is off, a missing SHA256SUMS line or attestation all +// stop before the hand-off, and the launcher never runs sudo. Fixtures: real pkgutil output (test/fixtures/anchor). +const assert = require('node:assert/strict'); +const { spawnSync } = require('node:child_process'); +const crypto = require('node:crypto'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const test = require('node:test'); + +const A = require('../lib/anchor'); + +const FX = path.join(__dirname, 'fixtures', 'anchor'); +const vendor = fs.readFileSync(path.join(FX, 'pkgutil-vendor-signed.txt'), 'utf8'); +const ours = vendor.replace('AMZN Mobile LLC (94KV3E626L)', 'Fixture Owner (KJ35UYYL22)'); + +const attested = (ref) => JSON.stringify([{ verificationResult: { signature: { certificate: { sourceRepositoryRef: ref } } } }]); + +function world({ signature = ours, gatekeeper = 'assessments enabled', assess = 'source=Notarized Developer ID', attest = 0, attestOut = attested('refs/tags/brain-anchor-v0.1.0'), pin = { tree_hash: 'a'.repeat(64), tool_tree_hash: 'b'.repeat(64), tool_commit: 'c'.repeat(40) } } = {}) { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'anchor-test-')); + const pkg = path.join(dir, 'passioncode-brain-anchor-0.1.0.pkg'); + fs.writeFileSync(pkg, 'package bytes'); + const sha = crypto.createHash('sha256').update('package bytes').digest('hex'); + const calls = []; + const paths = []; + const run = (full, args) => { + paths.push(full); + const cmd = path.basename(full); + calls.push([cmd, ...args].join(' ')); + if (cmd === 'spctl' && args[0] === '--status') return { code: 0, out: `${gatekeeper}\n`, err: '' }; + if (cmd === 'spctl') return { code: assess.includes('Notarized') ? 0 : 3, out: '', err: `${pkg}: x\n${assess}\n` }; + if (cmd === 'gh') return attest === 127 ? { code: 127, out: '', err: 'gh not found' } : { code: attest, out: attest ? '' : attestOut, err: attest ? 'no matching attestation' : '' }; + if (cmd === 'pkgutil' && args[0] === '--check-signature') return { code: 0, out: signature, err: '' }; + if (cmd === 'pkgutil' && args[0] === '--expand-full') { + const scripts = path.join(args[2], 'component.pkg', 'Scripts'); + fs.mkdirSync(scripts, { recursive: true }); + if (pin) fs.writeFileSync(path.join(scripts, 'pin.json'), JSON.stringify(pin)); + return { code: 0, out: '', err: '' }; + } + if (cmd === 'open') return { code: 0, out: '', err: '' }; + return { code: 127, out: '', err: `${cmd} not expected` }; + }; + return { dir, pkg, sha, sums: `${sha} passioncode-brain-anchor-0.1.0.pkg\n`, run, calls, paths }; +} + +test('T28a: a package of the team, notarised, listed and attested passes every check and is handed to Installer', async () => { + const w = world(); + const r = await A.anchor({ pkg: w.pkg, sumsFile: (fs.writeFileSync(path.join(w.dir, 'S'), w.sums), path.join(w.dir, 'S')), run: w.run, uid: 501, home: w.dir, platform: 'darwin', role: 'person' }); + assert.equal(r.code, 0, JSON.stringify(r)); + assert.deepEqual(r.checks.map((c) => c.check), ['gatekeeper', 'sha256', 'attestation', 'signature', 'assessment', 'pin']); + assert.ok(w.calls.includes(`open -a Installer ${w.pkg}`)); + assert.ok(!w.calls.some((c) => /sudo|installer -pkg/.test(c)), 'never sudo, never the installer CLI'); + assert.deepEqual(JSON.parse(fs.readFileSync(path.join(w.dir, '.passioncode', 'brain-anchor.json'), 'utf8')), { role: 'person' }); +}); + +const refusals = [ + ['an unsigned package', { signature: fs.readFileSync(path.join(FX, 'pkgutil-unsigned.txt'), 'utf8') }, 'signature'], + ['a modified package', { signature: fs.readFileSync(path.join(FX, 'pkgutil-modified.txt'), 'utf8') }, 'signature'], + ['a package signed by another team', { signature: vendor }, 'signature'], + ['a package that is not notarised', { signature: ours.replace(/^\s*Notarization:.*\n/m, '') }, 'signature'], + ['a chain that does not end at the Apple Root CA', { signature: ours.replace('B0 B1 73 0E', 'B0 B1 73 0F') }, 'signature'], + ['a machine with Gatekeeper assessments off', { gatekeeper: 'assessments disabled' }, 'gatekeeper'], + ['a package without a build attestation', { attest: 1 }, 'attestation'], + ['a machine without gh to read the attestation', { attest: 127 }, 'attestation'], + ['a build attested from a branch, not a brain-anchor tag', { attestOut: attested('refs/heads/feature') }, 'attestation'], + ['a fixture package', { pin: { tree_hash: 'a'.repeat(64), tool_tree_hash: 'b'.repeat(64), fixture: true } }, 'pin-mode'], + ['an attestation answer that cannot be read', { attestOut: 'not json' }, 'attestation'], + ['a package Gatekeeper does not accept', { assess: 'source=no usable signature' }, 'assessment'], + ['a package without a pin', { pin: null }, 'pin'], +]; +for (const [name, opts, failed] of refusals) { + test(`T28a: ${name} is refused before elevation`, async () => { + const w = world(opts); + fs.writeFileSync(path.join(w.dir, 'S'), w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', role: 'person' }); + assert.equal(r.code, 1); + assert.equal(r.checks.at(-1).check, failed); + assert.equal(r.checks.at(-1).ok, false); + assert.ok(!w.calls.some((c) => c.startsWith('open ')), 'not handed off'); + assert.ok(!fs.existsSync(path.join(w.dir, '.passioncode')), 'no request written'); + }); +} + +test('T28a: bytes that differ from SHA256SUMS, or a file it does not list, are refused', async () => { + const w = world(); + for (const sums of [`${'0'.repeat(64)} passioncode-brain-anchor-0.1.0.pkg\n`, `${w.sha} other.pkg\n`]) { + fs.writeFileSync(path.join(w.dir, 'S'), sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', role: 'person' }); + assert.equal(r.code, 1); + assert.equal(r.checks.at(-1).check, 'sha256'); + } +}); + +test('T28a: a deployment manifest pins the package bytes, the installer certificate and the tool tree hash', async () => { + const w = world(); + fs.writeFileSync(path.join(w.dir, 'S'), w.sums); + const leaf = A.parsePkgutil(ours).chain[0].sha256; + const deploy = (o) => { const f = path.join(w.dir, 'D'); fs.writeFileSync(f, JSON.stringify({ tool: { tree_hash: 'b'.repeat(64), package: { sha256: w.sha, signer_certificate_sha256: leaf, ...o } } })); return f; }; + const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, uid: 501, home: w.dir, platform: 'darwin', dryRun: true, role: 'person' }; + assert.equal((await A.anchor({ ...base, deployFile: deploy({}) })).code, 0); + let r = await A.anchor({ ...base, deployFile: deploy({ sha256: '1'.repeat(64) }) }); + assert.equal(r.checks.at(-1).check, 'manifest-sha256'); + r = await A.anchor({ ...base, deployFile: deploy({ signer_certificate_sha256: '1'.repeat(64) }) }); + assert.equal(r.checks.at(-1).check, 'signature'); + // A manifest that pins no package bytes pins nothing a same-tool, different-runtime package would fail. + fs.writeFileSync(path.join(w.dir, 'D2'), JSON.stringify({ tool: { tree_hash: 'b'.repeat(64) } })); + r = await A.anchor({ ...base, deployFile: path.join(w.dir, 'D2') }); + assert.equal(r.code, 1); + assert.equal(r.checks.at(-1).check, 'manifest-sha256'); +}); + +test('T28a: never as root, macOS only, a dry run does not hand off, and the request is validated', async () => { + const w = world(); + fs.writeFileSync(path.join(w.dir, 'S'), w.sums); + const base = { pkg: w.pkg, sumsFile: path.join(w.dir, 'S'), run: w.run, home: w.dir, platform: 'darwin', role: 'person' }; + assert.equal((await A.anchor({ ...base, uid: 0 })).code, 2); + assert.equal((await A.anchor({ ...base, uid: 501, platform: 'linux' })).code, 2); + const d = await A.anchor({ ...base, uid: 501, dryRun: true }); + assert.equal(d.code, 0); + assert.ok(!w.calls.some((c) => c.startsWith('open '))); + assert.throws(() => A.writeRequest(w.dir, { role: 'org-space' }), /needs --org/); + assert.throws(() => A.writeRequest(w.dir, { role: 'root' }), /role must be/); + assert.throws(() => A.writeRequest(w.dir, { role: 'person', org: 'x' }), /organisation space only/); +}); + +const darwin = process.platform === 'darwin' && !spawnSync('pkgbuild', ['--help']).error; +test('T28a: with the real pkgutil, an unsigned package built here is refused at the signature', { skip: !darwin && 'needs macOS pkgbuild' }, () => { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'anchor-real-')); + const scripts = path.join(dir, 'scripts'); + fs.mkdirSync(scripts); + fs.writeFileSync(path.join(scripts, 'postinstall'), '#!/bin/sh\nexit 0\n', { mode: 0o755 }); + const pkg = path.join(dir, 'unsigned.pkg'); + assert.equal(spawnSync('pkgbuild', ['--nopayload', '--scripts', scripts, '--identifier', 'ai.passioncode.test', '--version', '1', pkg]).status, 0); + const sha = crypto.createHash('sha256').update(fs.readFileSync(pkg)).digest('hex'); + const gatekeeperOn = { code: 0, out: 'assessments enabled\n', err: '' }; + const real = require('../lib/releases').run; + const run = (cmd, args, o) => (path.basename(cmd) === 'spctl' && args[0] === '--status' ? gatekeeperOn : real(cmd, args, o)); + const r = A.verify(pkg, { sums: `${sha} unsigned.pkg\n`, run, requireAttestation: false }); + assert.equal(r.ok, false); + assert.equal(r.checks.at(-1).check, 'signature'); + assert.match(r.checks.at(-1).detail, /no signature/); + fs.rmSync(dir, { recursive: true, force: true }); +}); + +test('T28b: the request may carry the roster row the install step enrols; a bad row is refused before the hand-off', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, role: 'org-space', org: 'passioncode', row: 'machine:studio-passioncode', run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 0, JSON.stringify(r)); + assert.deepEqual(JSON.parse(fs.readFileSync(path.join(w.dir, '.passioncode', 'brain-anchor.json'), 'utf8')), { role: 'org-space', org: 'passioncode', row: 'machine:studio-passioncode' }); + assert.throws(() => A.writeRequest(w.dir, { role: 'person', row: '../x' }), /row/); + const calls = w.calls.filter((c) => c.startsWith('gh ')); + assert.ok(calls.every((c) => c.includes('--format json')), calls.join('\n')); + assert.ok(r.checks.find((c) => c.check === 'pin').detail.includes('c'.repeat(40)), 'the pinned commit is shown'); +}); + +test('T28a: a request that cannot be written is a usage error before any check runs, dry run included', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + for (const bad of [{ role: 'org-space' }, { role: 'person', org: 'passioncode' }, { role: 'nobody' }, { role: 'person', row: '../x' }]) { + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, ...bad, dryRun: true, run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 2, JSON.stringify(bad)); + } + assert.ok(!w.calls.some((c) => c.startsWith('gh ') || c.startsWith('pkgutil')), 'no check ran for a bad request'); + assert.ok(!fs.existsSync(path.join(w.dir, '.passioncode', 'brain-anchor.json'))); +}); + +test('T28a: the role is named on the command line, never defaulted; no check runs without it', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, dryRun: true, run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 2); + assert.match(r.message, /--role/); + assert.deepEqual(w.calls, [], 'no check ran'); +}); + +test('T28a: the system checking tools run by absolute path, never through the person\'s PATH', async () => { + const w = world(); + const sums = path.join(w.dir, 'S'); + fs.writeFileSync(sums, w.sums); + const r = await A.anchor({ pkg: w.pkg, sumsFile: sums, role: 'person', run: w.run, uid: 501, home: w.dir, platform: 'darwin' }); + assert.equal(r.code, 0, JSON.stringify(r)); + const system = w.paths.filter((p) => path.basename(p) !== 'gh'); + assert.ok(system.length >= 5, system.join(' ')); + for (const p of system) assert.ok(['/usr/sbin/spctl', '/usr/sbin/pkgutil', '/usr/bin/open'].includes(p), p); +}); diff --git a/test/fixtures/anchor/pkgutil-modified.txt b/test/fixtures/anchor/pkgutil-modified.txt new file mode 100644 index 00000000..9fce8ce6 --- /dev/null +++ b/test/fixtures/anchor/pkgutil-modified.txt @@ -0,0 +1,2 @@ +Package "sample-modified.pkg": + Status: package is invalid (checksum did not verify) diff --git a/test/fixtures/anchor/pkgutil-unsigned.txt b/test/fixtures/anchor/pkgutil-unsigned.txt new file mode 100644 index 00000000..b308d2c3 --- /dev/null +++ b/test/fixtures/anchor/pkgutil-unsigned.txt @@ -0,0 +1,2 @@ +Package "sample-unsigned.pkg": + Status: no signature diff --git a/test/fixtures/anchor/pkgutil-vendor-signed.txt b/test/fixtures/anchor/pkgutil-vendor-signed.txt new file mode 100644 index 00000000..68fcb327 --- /dev/null +++ b/test/fixtures/anchor/pkgutil-vendor-signed.txt @@ -0,0 +1,23 @@ +Package "sample-signed.pkg": + Status: signed by a developer certificate issued by Apple for distribution + Notarization: trusted by the Apple notary service + Signed with a trusted timestamp on: 2026-11-24 19:14:05 +0000 + Certificate Chain: + 1. Developer ID Installer: AMZN Mobile LLC (94KV3E626L) + Expires: 2030-09-26 00:18:06 +0000 + SHA256 Fingerprint: + 5C 45 BE 63 FD 52 10 07 2D 66 56 77 5C A9 FF 25 91 6D 3F 01 F7 0E + 9A 8A 05 F6 2D 62 B2 88 8D A9 + ------------------------------------------------------------------------ + 2. Developer ID Certification Authority + Expires: 2031-09-17 00:00:00 +0000 + SHA256 Fingerprint: + F1 6C D3 C5 4C 7F 83 CE A4 BF 1A 3E 6A 08 19 C8 AA A8 E4 A1 52 8F + D1 44 71 5F 35 06 43 D2 DF 3A + ------------------------------------------------------------------------ + 3. Apple Root CA + Expires: 2035-02-09 21:40:36 +0000 + SHA256 Fingerprint: + B0 B1 73 0E CB C7 FF 45 05 14 2C 49 F1 29 5E 6E DA 6B CA ED 7E 2C + 68 C5 BE 91 B5 A1 10 01 F0 24 +