@parhelia/capture 0.4.13062 → 0.4.13145

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +23 -4
  2. package/dist/cli.js +101 -19
  3. package/dist/cmsJob.d.ts +9 -0
  4. package/dist/cmsJob.d.ts.map +1 -1
  5. package/dist/cmsJob.js +81 -0
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/install/install.d.ts +4 -0
  10. package/dist/install/install.d.ts.map +1 -1
  11. package/dist/install/install.js +37 -10
  12. package/dist/install/layout.d.ts +9 -0
  13. package/dist/install/layout.d.ts.map +1 -1
  14. package/dist/install/layout.js +7 -1
  15. package/dist/install/manifestSignature.d.ts +30 -0
  16. package/dist/install/manifestSignature.d.ts.map +1 -0
  17. package/dist/install/manifestSignature.js +93 -0
  18. package/dist/install/releaseKeys.d.ts +2 -0
  19. package/dist/install/releaseKeys.d.ts.map +1 -0
  20. package/dist/install/releaseKeys.js +16 -0
  21. package/dist/install/services.d.ts +12 -0
  22. package/dist/install/services.d.ts.map +1 -1
  23. package/dist/install/services.js +45 -1
  24. package/dist/install/units.d.ts +8 -0
  25. package/dist/install/units.d.ts.map +1 -1
  26. package/dist/install/units.js +39 -3
  27. package/dist/install/updateLock.d.ts +14 -0
  28. package/dist/install/updateLock.d.ts.map +1 -0
  29. package/dist/install/updateLock.js +75 -0
  30. package/dist/install/updater.d.ts +28 -1
  31. package/dist/install/updater.d.ts.map +1 -1
  32. package/dist/install/updater.js +74 -2
  33. package/dist/install/versions.d.ts +11 -1
  34. package/dist/install/versions.d.ts.map +1 -1
  35. package/dist/install/versions.js +16 -2
  36. package/dist/isolation.d.ts +17 -1
  37. package/dist/isolation.d.ts.map +1 -1
  38. package/dist/isolation.js +21 -5
  39. package/dist/parheliaClient.d.ts +13 -0
  40. package/dist/parheliaClient.d.ts.map +1 -1
  41. package/dist/parheliaClient.js +7 -0
  42. package/dist/webIsolation.d.ts +2 -0
  43. package/dist/webIsolation.d.ts.map +1 -1
  44. package/dist/webIsolation.js +7 -5
  45. package/dist/worker.d.ts.map +1 -1
  46. package/dist/worker.js +3 -0
  47. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/install/layout.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,WAAW,qBAAqB,CAAC;AAC9C,eAAO,MAAM,YAAY,6BAA6B,CAAC;AACvD,yHAAyH;AACzH,eAAO,MAAM,SAAS,yBAAyB,CAAC;AAChD,kHAAkH;AAClH,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAErE,eAAO,MAAM,IAAI;aACf,MAAM,EAAE,iCAAiC;aACzC,WAAW,EAAE,uCAAuC;aACpD,OAAO,EAAE,kCAAkC;aAC3C,YAAY,EAAE,gCAAgC;CACtC,CAAC;AAEX,eAAO,MAAM,IAAI;aAAK,MAAM,EAAE,sBAAsB;aAAE,MAAM,EAAE,QAAQ;aAAE,WAAW,EAAE,cAAc;aAAE,OAAO,EAAE,SAAS;CAAW,CAAC;AAEnI,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,qHAAqH;IACrH,UAAU,EAAE,MAAM,CAAC;IACnB,2GAA2G;IAC3G,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,2HAA2H;IAC3H,QAAQ,EAAE,MAAM,CA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C;CAC9B,CAAC;AAEF,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,8GAA8G;IAC9G,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gHAAgH;IAChH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,aAAa,QAA4E,CAAC"}
@@ -21,8 +21,12 @@ export const UNIT = {
21
21
  browserHost: "parhelia-capture-browser-host.service",
22
22
  updater: "parhelia-capture-updater.service",
23
23
  updaterTimer: "parhelia-capture-updater.timer",
24
+ /** "Update now": the updater's long poll for an administrator's update request (privileged, like the updater). */
25
+ updateWatch: "parhelia-capture-update-watch.service",
26
+ };
27
+ export const TASK = {
28
+ folder: "\\Parhelia Capture\\", worker: "Worker", browserHost: "Browser host", updater: "Updater", updateWatch: "Update watch",
24
29
  };
25
- export const TASK = { folder: "\\Parhelia Capture\\", worker: "Worker", browserHost: "Browser host", updater: "Updater" };
26
30
  export function linuxLayout() {
27
31
  const join = path.posix.join;
28
32
  return {
@@ -36,6 +40,7 @@ export function linuxLayout() {
36
40
  stateDir: "/var/lib/parhelia-capture",
37
41
  statusFile: "/var/lib/parhelia-capture/status.json",
38
42
  updaterStatusFile: "/var/lib/parhelia-capture/updater.json",
43
+ updateLockFile: "/opt/parhelia-capture/update.lock",
39
44
  browserStateDir: "/var/lib/parhelia-capture-browser",
40
45
  socketDir: "/run/parhelia-capture/browser-host",
41
46
  unitDir: "/etc/systemd/system",
@@ -60,6 +65,7 @@ export function windowsLayout(env = process.env) {
60
65
  stateDir: join(data, "state"),
61
66
  statusFile: join(data, "state", "status.json"),
62
67
  updaterStatusFile: join(data, "state", "updater.json"),
68
+ updateLockFile: join(prefix, "update.lock"),
63
69
  browserStateDir: join(data, "browser"),
64
70
  socketDir: "\\\\.\\pipe\\parhelia-capture",
65
71
  unitDir: join(data, "tasks"),
@@ -0,0 +1,30 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ import type { SidecarManifest } from "./versions.js";
3
+ export type ManifestSignature = {
4
+ keyId: string;
5
+ signature: string;
6
+ };
7
+ /** The text a release key signs: every field that decides what is installed or served, one per line, in a fixed order. */
8
+ export declare function manifestSigningPayload(manifest: SidecarManifest): string;
9
+ /** A release key's id: the first 16 hex digits of the SHA-256 of its public key (SPKI, DER). */
10
+ export declare function keyIdOf(spkiBase64: string): string;
11
+ /** The public half of a private key, as the trusted list spells it (SPKI, DER, base64). */
12
+ export declare function publicKeyBase64(privateKey: KeyObject): string;
13
+ /** The release pipeline's half: signs the manifest's canonical text. */
14
+ export declare function signManifest(manifest: SidecarManifest, privateKey: KeyObject): ManifestSignature;
15
+ export type ManifestCheck =
16
+ /** `signed` false: this build trusts no key, so nothing was checked. */
17
+ {
18
+ ok: true;
19
+ signed: boolean;
20
+ keyId?: string;
21
+ } | {
22
+ ok: false;
23
+ reason: string;
24
+ };
25
+ /**
26
+ * Whether a trusted release key signed this manifest. With no trusted key nothing is checked (a build from before signing);
27
+ * with one, a manifest without a valid signature of a trusted key is refused, by name.
28
+ */
29
+ export declare function checkManifestSignature(manifest: SidecarManifest, trustedKeys?: readonly string[]): ManifestCheck;
30
+ //# sourceMappingURL=manifestSignature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifestSignature.d.ts","sourceRoot":"","sources":["../../src/install/manifestSignature.ts"],"names":[],"mappings":"AAOA,OAAO,EAA6C,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAExF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,MAAM,iBAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAUrE,0HAA0H;AAC1H,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAmBxE;AAMD,gGAAgG;AAChG,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,CAE7D;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,GAAG,iBAAiB,CAKhG;AAED,MAAM,MAAM,aAAa;AACvB,wEAAwE;AACtE;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,eAAe,EAAE,WAAW,GAAE,SAAS,MAAM,EAAiB,GAAG,aAAa,CA4B9H"}
@@ -0,0 +1,93 @@
1
+ /*
2
+ * Signed release manifests. The Parhelia host names the sidecar version to install and its hashes; this proves that the
3
+ * release pipeline wrote that manifest, not whoever answers at the host's address. The signature is Ed25519 over a canonical
4
+ * text of the manifest's fields, not over its JSON: the host reads the pin and writes it again (its own field order and date
5
+ * spelling), so the bytes on the wire are not the bytes that were signed. The release script signs with this same module
6
+ * (from the staged package's dist), so there is one spelling of the text.
7
+ */
8
+ import { createHash, createPublicKey, sign, verify } from "node:crypto";
9
+ import { RELEASE_KEYS } from "./releaseKeys.js";
10
+ const HEADER = "parhelia-capture-manifest/1";
11
+ function field(name, value) {
12
+ const text = value === undefined || value === null ? "" : String(value);
13
+ if (/[\r\n]/.test(text))
14
+ throw new Error(`The manifest's ${name} holds a line break; it cannot be signed or checked.`);
15
+ return `${name}:${text}`;
16
+ }
17
+ /** The text a release key signs: every field that decides what is installed or served, one per line, in a fixed order. */
18
+ export function manifestSigningPayload(manifest) {
19
+ const browser = manifest.browser ?? undefined;
20
+ const released = browser?.releasedUtc ? Date.parse(browser.releasedUtc) : NaN;
21
+ const platforms = browser?.platforms ?? {};
22
+ return [
23
+ HEADER,
24
+ field("version", manifest.version),
25
+ field("integrity", manifest.integrity),
26
+ field("tarball", manifest.tarball),
27
+ field("securityMinimum", manifest.securityMinimum),
28
+ field("browserMaxAgeDays", manifest.browserMaxAgeDays),
29
+ field("browser.revision", browser?.revision),
30
+ // The instant, not its spelling: the host writes the date its own way.
31
+ field("browser.releasedUtc", Number.isFinite(released) ? released : ""),
32
+ ...Object.keys(platforms).sort().map((key) => {
33
+ const archive = platforms[key];
34
+ return field(`browser.platform.${key}`, [archive.url, archive.sha256.toLowerCase(), archive.executable].join("|"));
35
+ }),
36
+ ].join("\n");
37
+ }
38
+ function publicKeyOf(spkiBase64) {
39
+ return createPublicKey({ key: Buffer.from(spkiBase64, "base64"), format: "der", type: "spki" });
40
+ }
41
+ /** A release key's id: the first 16 hex digits of the SHA-256 of its public key (SPKI, DER). */
42
+ export function keyIdOf(spkiBase64) {
43
+ return createHash("sha256").update(Buffer.from(spkiBase64, "base64")).digest("hex").slice(0, 16);
44
+ }
45
+ /** The public half of a private key, as the trusted list spells it (SPKI, DER, base64). */
46
+ export function publicKeyBase64(privateKey) {
47
+ return createPublicKey(privateKey).export({ format: "der", type: "spki" }).toString("base64");
48
+ }
49
+ /** The release pipeline's half: signs the manifest's canonical text. */
50
+ export function signManifest(manifest, privateKey) {
51
+ return {
52
+ keyId: keyIdOf(publicKeyBase64(privateKey)),
53
+ signature: sign(null, Buffer.from(manifestSigningPayload(manifest), "utf8"), privateKey).toString("base64"),
54
+ };
55
+ }
56
+ /**
57
+ * Whether a trusted release key signed this manifest. With no trusted key nothing is checked (a build from before signing);
58
+ * with one, a manifest without a valid signature of a trusted key is refused, by name.
59
+ */
60
+ export function checkManifestSignature(manifest, trustedKeys = RELEASE_KEYS) {
61
+ if (trustedKeys.length === 0)
62
+ return { ok: true, signed: false };
63
+ const signatures = Array.isArray(manifest.signatures) ? manifest.signatures : [];
64
+ if (signatures.length === 0)
65
+ return { ok: false, reason: `Parhelia names version ${manifest.version} without a release signature; this sidecar installs signed releases only.` };
66
+ let payload;
67
+ try {
68
+ payload = Buffer.from(manifestSigningPayload(manifest), "utf8");
69
+ }
70
+ catch (error) {
71
+ return { ok: false, reason: error instanceof Error ? error.message : String(error) };
72
+ }
73
+ const byId = new Map(trustedKeys.map((key) => [keyIdOf(key), key]));
74
+ for (const candidate of signatures) {
75
+ const key = typeof candidate?.keyId === "string" ? byId.get(candidate.keyId) : undefined;
76
+ if (!key || typeof candidate.signature !== "string")
77
+ continue;
78
+ try {
79
+ if (verify(null, payload, publicKeyOf(key), Buffer.from(candidate.signature, "base64")))
80
+ return { ok: true, signed: true, keyId: candidate.keyId };
81
+ }
82
+ catch {
83
+ // A malformed signature is not a valid one.
84
+ }
85
+ }
86
+ const known = signatures.some((candidate) => typeof candidate?.keyId === "string" && byId.has(candidate.keyId));
87
+ return {
88
+ ok: false,
89
+ reason: known
90
+ ? `The release signature of version ${manifest.version} does not match what Parhelia names (the manifest was changed after it was signed); nothing is installed.`
91
+ : `Version ${manifest.version} is signed by no release key this sidecar trusts; nothing is installed.`,
92
+ };
93
+ }
@@ -0,0 +1,2 @@
1
+ export declare const RELEASE_KEYS: readonly string[];
2
+ //# sourceMappingURL=releaseKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"releaseKeys.d.ts","sourceRoot":"","sources":["../../src/install/releaseKeys.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAGzC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /*
2
+ * The release keys this sidecar trusts: Ed25519 public keys (SPKI, DER, base64), one per line of the array. The release
3
+ * pipeline signs every manifest it writes with the matching private key (its secret variable CaptureSigningKey;
4
+ * frontend/scripts/write-capture-manifest.mjs), and an updater built with at least one key here installs nothing whose
5
+ * manifest carries no valid signature of one of them: a Parhelia host that is compromised, or impersonated on the way, can then
6
+ * name only releases we signed (docs/capture-service.md § Signed releases).
7
+ *
8
+ * While the list is empty this build checks no signature (it says so in `parhelia-capture status`). Make a key pair with
9
+ * `node frontend/scripts/capture-signing-key.mjs --out <private key file>`; add the public key it prints here, and the
10
+ * private key to the pipeline. To rotate: add the new key here first, release (signed by the old key), then sign with the new
11
+ * one, and remove the old key a release later.
12
+ */
13
+ export const RELEASE_KEYS = [
14
+ // Key id 7b6f24bdecffaf08, made 2026-11-12: the first release key.
15
+ "MCowBQYDK2VwAyEAtSdyDgO7Ncjyy4R6QgDco8AaZCm7HyqqXMJWNSP1Pi8=",
16
+ ];
@@ -7,6 +7,18 @@ export declare function services(sys: Sys, layout: Layout, web: boolean): {
7
7
  stop(): void;
8
8
  start(): void;
9
9
  };
10
+ /**
11
+ * "Update now": the update watch as a service of its own (`install` writes and starts it with the others). The updater calls
12
+ * this on every run, so an install from before the watch gets it at the first check its new version makes. It acts only when
13
+ * the definition is missing or differs: an administrator who stopped or disabled the watch keeps it that way. True when it
14
+ * was (re)written and started.
15
+ */
16
+ export declare function ensureUpdateWatch(sys: Sys, layout: Layout, config: InstalledConfig): boolean;
17
+ /**
18
+ * After an update by the timer or by hand, the update watch still runs the previous version: restart it, so the update it
19
+ * starts next is the current version's. A watch that is not running stays that way (Linux: `try-restart`).
20
+ */
21
+ export declare function restartUpdateWatch(sys: Sys, layout: Layout): void;
10
22
  export declare function windowsFirewall(sys: Sys): Firewall;
11
23
  /** The staged version's self-test (plan CS-D14): run as the worker would, against a trial browser host when public-web is on. */
12
24
  export declare function selfTest(sys: Sys, layout: Layout, config: InstalledConfig): (versionDir: string, _version: string) => Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/install/services.ts"],"names":[],"mappings":"AAQA,OAAO,EAAmE,KAAK,eA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G;IAAE,IAAI,IAAI,IAAI,CAAC;IAAC,KAAK,IAAI,IAAI,CAAA;CAAE,CAahG;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAsB5F;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAOjE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAUlD;AAED,iIAAiI;AACjI,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,gBAC9C,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA0C9F"}
@@ -7,7 +7,7 @@
7
7
  import path from "node:path";
8
8
  import { browserHostUnitProperties } from "../isolation.js";
9
9
  import { BROWSER_USER, IPC_GROUP, PACKAGE_ENTRY, TASK, UNIT, WORKER_USER } from "./layout.js";
10
- import { firewallRemoveScript, firewallRuleHolds, firewallRuleScript, firewallVerifyScript, nodeReadOnlyPaths } from "./units.js";
10
+ import { firewallRemoveScript, firewallRuleHolds, firewallRuleScript, firewallVerifyScript, nodeReadOnlyPaths, updateWatchTask, updateWatchUnit, } from "./units.js";
11
11
  export const TRIAL_UNIT = "parhelia-capture-trial-browser-host";
12
12
  export function entryOf(layout, versionDir) {
13
13
  return layout.join(versionDir, ...PACKAGE_ENTRY.split("/"));
@@ -31,6 +31,50 @@ export function services(sys, layout, web) {
31
31
  start: () => tasks.forEach((task) => check(sys.exec("schtasks", ["/Run", "/TN", task]), `Starting ${task}`)),
32
32
  };
33
33
  }
34
+ /**
35
+ * "Update now": the update watch as a service of its own (`install` writes and starts it with the others). The updater calls
36
+ * this on every run, so an install from before the watch gets it at the first check its new version makes. It acts only when
37
+ * the definition is missing or differs: an administrator who stopped or disabled the watch keeps it that way. True when it
38
+ * was (re)written and started.
39
+ */
40
+ export function ensureUpdateWatch(sys, layout, config) {
41
+ const input = { layout, nodePath: sys.nodePath, inaccessiblePaths: config.inaccessiblePaths ?? [], web: config.web };
42
+ if (layout.platform === "linux") {
43
+ const file = layout.join(layout.unitDir, UNIT.updateWatch);
44
+ const text = updateWatchUnit(input);
45
+ if (sys.exists(file) && sys.readFile(file) === text)
46
+ return false;
47
+ sys.writeFile(file, text, { mode: 0o644 });
48
+ check(sys.exec("systemctl", ["daemon-reload"]), "Reloading systemd");
49
+ check(sys.exec("systemctl", ["enable", UNIT.updateWatch]), "Enabling the update watch");
50
+ check(sys.exec("systemctl", ["restart", UNIT.updateWatch]), "Starting the update watch");
51
+ return true;
52
+ }
53
+ const file = layout.join(layout.unitDir, `${TASK.updateWatch}.xml`);
54
+ const text = updateWatchTask(input);
55
+ if (sys.exists(file) && sys.readFile(file) === text)
56
+ return false;
57
+ const task = TASK.folder + TASK.updateWatch;
58
+ sys.mkdir(layout.unitDir);
59
+ sys.writeFile(file, text);
60
+ sys.exec("schtasks", ["/End", "/TN", task]);
61
+ check(sys.exec("schtasks", ["/Create", "/TN", task, "/XML", file, "/F"]), "Registering the update watch");
62
+ check(sys.exec("schtasks", ["/Run", "/TN", task]), "Starting the update watch");
63
+ return true;
64
+ }
65
+ /**
66
+ * After an update by the timer or by hand, the update watch still runs the previous version: restart it, so the update it
67
+ * starts next is the current version's. A watch that is not running stays that way (Linux: `try-restart`).
68
+ */
69
+ export function restartUpdateWatch(sys, layout) {
70
+ if (layout.platform === "linux") {
71
+ sys.exec("systemctl", ["try-restart", UNIT.updateWatch]);
72
+ return;
73
+ }
74
+ const task = TASK.folder + TASK.updateWatch;
75
+ if (sys.exec("schtasks", ["/End", "/TN", task]).status === 0)
76
+ sys.exec("schtasks", ["/Run", "/TN", task]);
77
+ }
34
78
  export function windowsFirewall(sys) {
35
79
  const powershell = (script) => sys.exec("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script]);
36
80
  return {
@@ -15,6 +15,12 @@ export declare function workerUnit(input: UnitInput): string;
15
15
  export declare function browserHostUnit(input: UnitInput): string;
16
16
  export declare function updaterUnit(input: UnitInput): string;
17
17
  export declare function updaterTimer(): string;
18
+ /**
19
+ * "Update now": the updater's long poll. It asks Parhelia (with the worker key, never through the worker) whether an
20
+ * administrator asked for this worker's update, and then runs the same update as the timer, at once. It ends after an update
21
+ * that switched versions, so systemd starts the new version's own.
22
+ */
23
+ export declare function updateWatchUnit(input: UnitInput): string;
18
24
  export declare function linuxUnits(input: UnitInput): Record<string, string>;
19
25
  export declare const SID: {
20
26
  readonly localService: "S-1-5-19";
@@ -30,6 +36,8 @@ export declare function windowsTask(input: {
30
36
  daily?: boolean;
31
37
  }): string;
32
38
  export declare function windowsTasks(input: UnitInput): Record<string, string>;
39
+ /** "Update now" on Windows: the updater's long poll as a task of SYSTEM, started at boot and restarted when it ends. */
40
+ export declare function updateWatchTask(input: UnitInput): string;
33
41
  /** Every remote address but loopback, as ranges: one block rule, no allow rule, so block-over-allow precedence cannot bite. */
34
42
  export declare const WINDOWS_BLOCKED_REMOTE: readonly ["0.0.0.0-126.255.255.255", "128.0.0.0-255.255.255.255", "::", "::2-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
35
43
  export declare const firewallRuleName: (version: string) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/install/units.ts"],"names":[],"mappings":"AAOA,OAAO,EAA6D,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAErG,+GAA+G;AAC/G,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,iBAAiB,EAAE,SAAS,MAAM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O,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAarG;AAED,oHAAoH;AACpH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAExD;AAED,+HAA+H;AAC/H,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAExD;AAED,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAcpG;AAED,mHAAmH;AACnH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIvE"}
@@ -1,11 +1,11 @@
1
1
  /*
2
- * Capture sidecar CS6 (plan §5, §8): the service definitions `install` writes. Linux: three systemd units and a timer (the worker,
3
- * the isolated browser host, the privileged updater). Windows: three scheduled tasks (restart on failure, start at boot) and the
2
+ * Capture sidecar CS6 (plan §5, §8): the service definitions `install` writes. Linux: four systemd units and a timer (the worker,
3
+ * the isolated browser host, the privileged updater and its "Update now" long poll). Windows: four scheduled tasks and the
4
4
  * outbound block rule bound to one browser executable. Pure text; `install` writes it, the tests read it.
5
5
  */
6
6
  import path from "node:path";
7
7
  import { browserHostUnitProperties } from "../isolation.js";
8
- import { BROWSER_USER, IPC_GROUP, PACKAGE_ENTRY, UNIT, WORKER_USER } from "./layout.js";
8
+ import { BROWSER_USER, IPC_GROUP, PACKAGE_ENTRY, TASK, UNIT, WORKER_USER } from "./layout.js";
9
9
  /** A stop waits this long for the running jobs (each job's budget is 60 s) before systemd kills the worker. */
10
10
  export const WORKER_STOP_TIMEOUT_S = 150;
11
11
  const entry = (layout) => path.posix.join(layout.currentLink, PACKAGE_ENTRY);
@@ -114,12 +114,40 @@ Persistent=true
114
114
  WantedBy=timers.target
115
115
  `;
116
116
  }
117
+ /**
118
+ * "Update now": the updater's long poll. It asks Parhelia (with the worker key, never through the worker) whether an
119
+ * administrator asked for this worker's update, and then runs the same update as the timer, at once. It ends after an update
120
+ * that switched versions, so systemd starts the new version's own.
121
+ */
122
+ export function updateWatchUnit(input) {
123
+ const { layout } = input;
124
+ return `# Written by parhelia-capture. The updater's long poll for "Update now" (Settings › Capture service): it holds an outbound
125
+ # request to Parhelia and runs the updater the moment an administrator asks. What it installs is what the timer's run would.
126
+ [Unit]
127
+ Description=Parhelia capture service (update requests)
128
+ Wants=network-online.target
129
+ After=network-online.target
130
+
131
+ [Service]
132
+ Type=exec
133
+ ExecStart=${input.nodePath} ${entry(layout)} update-watch --config ${layout.configFile}
134
+ Restart=always
135
+ RestartSec=10
136
+ UMask=0022
137
+ NoNewPrivileges=yes
138
+ PrivateTmp=yes
139
+
140
+ [Install]
141
+ WantedBy=multi-user.target
142
+ `;
143
+ }
117
144
  export function linuxUnits(input) {
118
145
  return {
119
146
  [UNIT.worker]: workerUnit(input),
120
147
  ...(input.web ? { [UNIT.browserHost]: browserHostUnit(input) } : {}),
121
148
  [UNIT.updater]: updaterUnit(input),
122
149
  [UNIT.updaterTimer]: updaterTimer(),
150
+ [UNIT.updateWatch]: updateWatchUnit(input),
123
151
  };
124
152
  }
125
153
  // --- Windows -----------------------------------------------------------------------------------------------------------------
@@ -161,8 +189,16 @@ export function windowsTasks(input) {
161
189
  } : {}),
162
190
  Updater: windowsTask({ description: "Parhelia capture service (updater)", sid: SID.system, command: input.nodePath,
163
191
  args: `${cli} update --auto --config ${quoted(layout.configFile)}`, daily: true }),
192
+ [TASK.updateWatch]: updateWatchTask(input),
164
193
  };
165
194
  }
195
+ /** "Update now" on Windows: the updater's long poll as a task of SYSTEM, started at boot and restarted when it ends. */
196
+ export function updateWatchTask(input) {
197
+ const { layout } = input;
198
+ const cli = quoted(path.win32.join(layout.currentLink, ...PACKAGE_ENTRY.split("/")));
199
+ return windowsTask({ description: "Parhelia capture service (update requests)", sid: SID.system, command: input.nodePath,
200
+ args: `${cli} update-watch --config ${quoted(layout.configFile)}` });
201
+ }
166
202
  /** Every remote address but loopback, as ranges: one block rule, no allow rule, so block-over-allow precedence cannot bite. */
167
203
  export const WINDOWS_BLOCKED_REMOTE = [
168
204
  "0.0.0.0-126.255.255.255", "128.0.0.0-255.255.255.255", "::", "::2-ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
@@ -0,0 +1,14 @@
1
+ /** An update's longest run is its unit's start timeout (30 min); a lock older than this belongs to nothing that still runs. */
2
+ export declare const UPDATE_LOCK_STALE_MS: number;
3
+ export type UpdateLockOptions = {
4
+ now?: () => number;
5
+ pid?: number;
6
+ /** Whether a process with this id runs (default: signal 0). */
7
+ alive?: (pid: number) => boolean;
8
+ };
9
+ /**
10
+ * Takes the update lock: the function that releases it, or undefined while another update holds it. A lock whose holder no
11
+ * longer runs (a killed updater, a reboot) or that is older than UPDATE_LOCK_STALE_MS is taken over.
12
+ */
13
+ export declare function acquireUpdateLock(file: string, options?: UpdateLockOptions): (() => void) | undefined;
14
+ //# sourceMappingURL=updateLock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateLock.d.ts","sourceRoot":"","sources":["../../src/install/updateLock.ts"],"names":[],"mappings":"AAQA,+HAA+H;AAC/H,eAAO,MAAM,oBAAoB,QAAkB,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CAClC,CAAC;AAYF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CA2BzG"}
@@ -0,0 +1,75 @@
1
+ /*
2
+ * "Update now": one update at a time on a machine. The timer's check and an update an administrator asked for (the update
3
+ * watch, or `parhelia-capture update` by hand) are separate privileged processes; both stage into the same directories and
4
+ * stop and start the same services, so the second one waits or skips instead of running beside the first. The lock is a file
5
+ * beside the code (root's on Linux, Administrators' and SYSTEM's on Windows): the service users cannot hold it.
6
+ */
7
+ import fs from "node:fs";
8
+ /** An update's longest run is its unit's start timeout (30 min); a lock older than this belongs to nothing that still runs. */
9
+ export const UPDATE_LOCK_STALE_MS = 2 * 60 * 60_000;
10
+ function processRuns(pid) {
11
+ try {
12
+ process.kill(pid, 0);
13
+ return true;
14
+ }
15
+ catch (error) {
16
+ // EPERM: it runs, as someone else.
17
+ return error.code === "EPERM";
18
+ }
19
+ }
20
+ /**
21
+ * Takes the update lock: the function that releases it, or undefined while another update holds it. A lock whose holder no
22
+ * longer runs (a killed updater, a reboot) or that is older than UPDATE_LOCK_STALE_MS is taken over.
23
+ */
24
+ export function acquireUpdateLock(file, options = {}) {
25
+ const now = options.now ?? Date.now;
26
+ const pid = options.pid ?? process.pid;
27
+ const alive = options.alive ?? processRuns;
28
+ for (let attempt = 0; attempt < 2; attempt++) {
29
+ try {
30
+ const handle = fs.openSync(file, "wx", 0o600);
31
+ try {
32
+ fs.writeSync(handle, JSON.stringify({ pid, at: now() }));
33
+ }
34
+ finally {
35
+ fs.closeSync(handle);
36
+ }
37
+ return () => {
38
+ try {
39
+ const held = JSON.parse(fs.readFileSync(file, "utf8"));
40
+ if (held.pid === pid)
41
+ fs.rmSync(file, { force: true });
42
+ }
43
+ catch {
44
+ // Already gone, or taken over as stale: nothing of ours to remove.
45
+ }
46
+ };
47
+ }
48
+ catch (error) {
49
+ if (error.code !== "EEXIST")
50
+ throw error;
51
+ if (!isStale(file, now(), alive))
52
+ return undefined;
53
+ fs.rmSync(file, { force: true });
54
+ }
55
+ }
56
+ return undefined;
57
+ }
58
+ function isStale(file, now, alive) {
59
+ let held;
60
+ try {
61
+ held = JSON.parse(fs.readFileSync(file, "utf8"));
62
+ }
63
+ catch {
64
+ // Being written this instant by its holder, or damaged: only an old one is taken over.
65
+ try {
66
+ return now - fs.statSync(file).mtimeMs > 60_000;
67
+ }
68
+ catch {
69
+ return true;
70
+ }
71
+ }
72
+ if (typeof held.pid !== "number" || typeof held.at !== "number")
73
+ return true;
74
+ return now - held.at > UPDATE_LOCK_STALE_MS || !alive(held.pid);
75
+ }
@@ -28,7 +28,8 @@ export type UpdaterStatus = {
28
28
  policy?: string;
29
29
  problems: string[];
30
30
  };
31
- export type UpdateResult = "no-release" | "up-to-date" | "available" | "updated" | "refused" | "rolled-back" | "unreachable";
31
+ /** "ahead": this machine runs a newer version than the host names for it (a worker moved back from canary); nothing is installed. */
32
+ export type UpdateResult = "no-release" | "up-to-date" | "ahead" | "available" | "updated" | "refused" | "rolled-back" | "unreachable";
32
33
  export type Firewall = {
33
34
  install(version: string, executable: string): void;
34
35
  verify(version: string, executable: string): {
@@ -55,12 +56,38 @@ export type UpdaterDeps = {
55
56
  /** Windows: the browser's outbound rule (plan §8: installed and verified before the first launch of a new path). */
56
57
  firewall?: Firewall;
57
58
  healthTimeoutMs?: number;
59
+ /** The release keys a manifest must be signed by (default: the ones this build ships; none: nothing is checked). */
60
+ trustedKeys?: readonly string[];
58
61
  log?: (line: string) => void;
59
62
  };
63
+ /** `allowDowngrade`: by hand only ('parhelia-capture update --allow-downgrade'); no run the host can start installs an older version. */
60
64
  export type UpdateOptions = {
61
65
  auto: boolean;
62
66
  fromTarball?: string;
67
+ allowDowngrade?: boolean;
63
68
  };
64
69
  export declare function runUpdate(deps: UpdaterDeps, options: UpdateOptions): Promise<UpdaterStatus>;
70
+ /** How long one update wait is held open (the host caps it at its own poll limit; proxies cut longer requests). */
71
+ export declare const UPDATE_WAIT_MS = 25000;
72
+ export type UpdateWatchDeps = {
73
+ /** The host's update wait: true when an administrator asked for this worker's update, false when the wait passed. */
74
+ wait(waitMs: number): Promise<boolean>;
75
+ /** The update that was asked for: the timer's, but not held back by a "notify" policy. */
76
+ update(): Promise<UpdaterStatus>;
77
+ sleep(ms: number): Promise<void>;
78
+ now(): number;
79
+ /** True once the service is being stopped. */
80
+ stopping?: () => boolean;
81
+ log?: (line: string) => void;
82
+ };
83
+ /**
84
+ * "Update now" (Settings › Capture service): the updater's long poll. It holds an outbound request to Parhelia, with the worker
85
+ * key and never through the worker, and runs the update the moment the host answers that one was asked for. Returns "updated"
86
+ * after an update that switched versions (the caller ends, and the service manager starts the new version's watch), "stopped"
87
+ * when the service is stopped. A host that cannot be asked is asked again later; nothing here ends the watch.
88
+ */
89
+ export declare function watchForUpdateRequests(deps: UpdateWatchDeps): Promise<"updated" | "stopped">;
90
+ /** How long the watch pauses after a wait that failed: a host without the route or a refused key rarely, anything else soon. */
91
+ export declare function updateWaitPause(error: unknown, failures: number): number;
65
92
  export declare function readJson<T>(sys: Sys, file: string): T | undefined;
66
93
  //# sourceMappingURL=updater.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../src/install/updater.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EACwF,KAAK,eAAe,EAClH,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,eAAe,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE5H,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU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