beltsh 1.28.44 → 1.28.46
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.
- package/install.js +17 -6
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -242,6 +242,21 @@ function installFile(dest, data) {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
// Refuse an archive the manifest does not vouch for. A build entry without a
|
|
246
|
+
// sha256 used to install unverified; the check is not optional, so a manifest
|
|
247
|
+
// that lost the field (a bad release, a broken mirror) stops the install
|
|
248
|
+
// instead of running whatever the URL served.
|
|
249
|
+
function verifyChecksum(build, archive) {
|
|
250
|
+
const expected = typeof build.sha256 === "string" ? build.sha256.toLowerCase() : "";
|
|
251
|
+
if (!/^[0-9a-f]{64}$/.test(expected)) {
|
|
252
|
+
throw new Error("manifest has no sha256 for this build; refusing to install an unverified archive");
|
|
253
|
+
}
|
|
254
|
+
const actual = crypto.createHash("sha256").update(archive).digest("hex");
|
|
255
|
+
if (actual !== expected) {
|
|
256
|
+
throw new Error(`checksum mismatch\n expected: ${expected}\n got: ${actual}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
245
260
|
async function main() {
|
|
246
261
|
console.log(`Downloading belt for ${PLATFORM}/${ARCH}...`);
|
|
247
262
|
|
|
@@ -255,12 +270,7 @@ async function main() {
|
|
|
255
270
|
|
|
256
271
|
const archive = await fetch(build.url);
|
|
257
272
|
|
|
258
|
-
|
|
259
|
-
const actual = crypto.createHash("sha256").update(archive).digest("hex");
|
|
260
|
-
if (build.sha256 && actual !== build.sha256) {
|
|
261
|
-
console.error(`Checksum mismatch!\n expected: ${build.sha256}\n got: ${actual}`);
|
|
262
|
-
process.exit(1);
|
|
263
|
-
}
|
|
273
|
+
verifyChecksum(build, archive);
|
|
264
274
|
|
|
265
275
|
// Extract binary — pure Node, no shell commands, no MSYS path mangling
|
|
266
276
|
const entry = build.url.endsWith(".zip")
|
|
@@ -301,4 +311,5 @@ module.exports = {
|
|
|
301
311
|
noProxyMatches,
|
|
302
312
|
proxyFor,
|
|
303
313
|
selectBuild,
|
|
314
|
+
verifyChecksum,
|
|
304
315
|
};
|