@that-company/dat 0.1.43 → 0.1.44

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 (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/install.js +18 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@that-company/dat",
3
- "version": "0.1.43",
3
+ "version": "0.1.44",
4
4
  "description": "Installer for the D.A.T. CLI",
5
5
  "bin": {
6
6
  "dat": "bin/dat.js"
@@ -2,6 +2,7 @@
2
2
  "use strict";
3
3
 
4
4
  const { createHash } = require("node:crypto");
5
+ const { spawnSync } = require("node:child_process");
5
6
  const { createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, rmSync, chmodSync } = require("node:fs");
6
7
  const { get } = require("node:https");
7
8
  const { tmpdir } = require("node:os");
@@ -46,8 +47,9 @@ async function main() {
46
47
  await download(sumsUrl, tempSums);
47
48
  verifyChecksum(tempBin, tempSums, asset);
48
49
 
50
+ chmodSync(tempBin, 0o755);
51
+ ensureDarwinSignature(tempBin);
49
52
  renameSync(tempBin, BIN_PATH);
50
- chmodSync(BIN_PATH, 0o755);
51
53
  console.error(`installed dat ${pkg.version} -> ${BIN_PATH}`);
52
54
  } finally {
53
55
  rmSync(tempDir, { recursive: true, force: true });
@@ -135,3 +137,18 @@ function verifyChecksum(filePath, sumsPath, asset) {
135
137
  }
136
138
  console.error("checksum ok");
137
139
  }
140
+
141
+ function ensureDarwinSignature(filePath) {
142
+ if (process.platform !== "darwin" || !isMachO(filePath)) return;
143
+ const verified = spawnSync("codesign", ["--verify", "--strict", filePath], { stdio: "ignore" });
144
+ if (verified.status === 0) return;
145
+ const signed = spawnSync("codesign", ["-f", "-s", "-", filePath], { stdio: "ignore" });
146
+ if (signed.status !== 0) throw new Error("downloaded macOS binary has an invalid code signature and local codesign failed");
147
+ const reverified = spawnSync("codesign", ["--verify", "--strict", filePath], { stdio: "ignore" });
148
+ if (reverified.status !== 0) throw new Error("downloaded macOS binary still has an invalid code signature");
149
+ }
150
+
151
+ function isMachO(filePath) {
152
+ const magic = readFileSync(filePath).subarray(0, 4).toString("hex");
153
+ return ["feedface", "feedfacf", "cefaedfe", "cffaedfe", "cafebabe", "bebafeca"].includes(magic);
154
+ }