Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Pin SHA-256 checksums of the ONNX Runtime archives

laurenspriemd238d1fc02ed
diff --git a/desktop/scripts/ort.js b/desktop/scripts/ort.js
index 129d6b56ca..99d9979fe2 100644
--- a/desktop/scripts/ort.js
+++ b/desktop/scripts/ort.js
@@ -7,10 +7,10 @@
* https://github.com/laurens-pilot/ort-packaging/releases
*
* This script downloads the archive for the relevant OS/arch combination,
- * verifies it against the release's SHA-256 sidecar, and extracts it into
- * `build/onnxruntime/<arch>`. From there it gets used during development, and
- * copied into the packaged app's resources by the "extraFiles" clause in
- * `electron-builder.yml`.
+ * verifies it against the SHA-256 checksums pinned below, and extracts it
+ * into `build/onnxruntime/<arch>`. From there it gets used during
+ * development, and copied into the packaged app's resources by the
+ * "extraFiles" clause in `electron-builder.yml`.
*
* On macOS both architectures are downloaded since the packaged app is a
* universal binary. Like `vips.js`, this script runs during "npm install"
@@ -28,6 +28,28 @@ const version = "1.27.0-r2";
const releaseURL = `https://github.com/laurens-pilot/ort-packaging/releases/download/ort-${version}`;
+/**
+ * SHA-256 checksums of the release assets, pinned here so that the library we
+ * package cannot change without a corresponding (reviewed) change to this
+ * file. When bumping {@link version}, update these with the values from the
+ * release's `.sha256` sidecar files after verifying them against the built
+ * archives.
+ */
+const assetSHA256s = {
+ "darwin-arm64":
+ "3249212d99a22b5c3a7fecf5d7269938475f6cc2dbb5ca98f43f1b5887d5b80f",
+ "darwin-x64":
+ "11264a993b1dd9c25c9fc52c777052aa90cc1e2fe2e6145bba9d397ec86ae3cd",
+ "linux-arm64":
+ "f83f463d37c9a7bce0482202cb5c75b519c0e41dd5c194ad629f9f2b920bfc18",
+ "linux-x64":
+ "bfd679770f0a5a2c186980e565cd7d1eaee1491ff1f038d079d73f382eb81b76",
+ "win32-arm64":
+ "1fd74f7dadd9d9c58d0573cdeb789d6deaa7d744333c2dd5285f9c88e4f957b6",
+ "win32-x64":
+ "d20661b8af1cce1a6d5577e32da22edba940d547b8247ffc143f9735a8afe87b",
+};
+
const assetName = (platform, arch) => {
switch (platform) {
case "darwin":
@@ -54,20 +76,15 @@ const downloadONNXRuntimeIfNeeded = async (platform, arch, appDir) => {
if ((await fsp.readFile(stampPath, "utf8")) == asset) return;
} catch {}
+ const expected = assetSHA256s[`${platform}-${arch}`];
+ if (!expected) throw new Error(`No pinned SHA-256 for ${platform}-${arch}`);
+
console.log(`Downloading ${asset}`);
- const download = async (name) => {
- const res = await fetch(`${releaseURL}/${name}`);
- if (!res.ok)
- throw new Error(`Failed to download ${name}: HTTP ${res.status}`);
- return Buffer.from(await res.arrayBuffer());
- };
-
- const [archive, sidecar] = await Promise.all([
- download(asset),
- download(`${asset}.sha256`),
- ]);
-
- const expected = sidecar.toString("utf8").trim().split(/\s+/)[0];
+ const res = await fetch(`${releaseURL}/${asset}`);
+ if (!res.ok)
+ throw new Error(`Failed to download ${asset}: HTTP ${res.status}`);
+ const archive = Buffer.from(await res.arrayBuffer());
+
const actual = crypto.createHash("sha256").update(archive).digest("hex");
if (actual != expected)
throw new Error(