π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Verify cached FFmpeg binaries and retain resource copying
Neeraj Gupta4860209f36c1
diff --git a/desktop/electron-builder.yml b/desktop/electron-builder.ymlindex 29c93231e2..8d18d49cb1 100644--- a/desktop/electron-builder.yml+++ b/desktop/electron-builder.yml@@ -3,9 +3,9 @@ artifactName: ${productName}-${version}-${arch}.${ext}files:- app/**/*- out-extraResources:+extraFiles:- from: build- to: .+ to: resourcesfilter: ["**/*", "!ffmpeg/{ffprobe,ffprobe.exe,.archive-sha256}"]beforeBuild: scripts/beforeBuild.jsbeforePack: scripts/beforePack.jsdiff --git a/desktop/scripts/ffmpeg.js b/desktop/scripts/ffmpeg.jsindex 12c352cea2..74582913df 100644--- a/desktop/scripts/ffmpeg.js+++ b/desktop/scripts/ffmpeg.js@@ -1,4 +1,5 @@const crypto = require("node:crypto");+const { createReadStream } = require("node:fs");const fs = require("node:fs/promises");const path = require("node:path");const { execFileSync } = require("node:child_process");@@ -6,16 +7,47 @@ const StreamZip = require("node-stream-zip");const release = "9.0.2";const checksums = {- "darwin-universal":- "ba2f10d5433ae4b22f482ea2cee85d50819455e1e63b5aa1ecf6201ad2f2b7c9",- "linux-x64":- "7cf14c99d674d5f2ad2897f83f2b00307f66dba6c2f4fa854601a0521bc47886",- "linux-arm64":- "00dd72f0f0ac4805d90b3c01a667909f04d6f821f90189791e1dea59cf8507ba",- "windows-x64":- "0d772b1676871c480a8f140c45507c68e3077013d42792088c8db55f1611aba2",- "windows-arm64":- "4f6df97fcd471adeac97079e271617e0fee322610faeca89f6590c323a5af654",+ "darwin-universal": {+ archive:+ "ba2f10d5433ae4b22f482ea2cee85d50819455e1e63b5aa1ecf6201ad2f2b7c9",+ ffmpeg: "1fc24088a740634a52d7a74bc90fa8178778ba38451f156f32fb3540af6eb70b",+ ffprobe:+ "ce7c0146fbd67abe36a24ed7bb52f1cc581bff5421714f81ad88328c49650cd6",+ },+ "linux-x64": {+ archive:+ "7cf14c99d674d5f2ad2897f83f2b00307f66dba6c2f4fa854601a0521bc47886",+ ffmpeg: "b45af6ffd68a62e4265bc71aeef4f5aa2708682dc4d540c9d3ef9a2308745c70",+ ffprobe:+ "38b4b2a0839930c7ebfdcf11327b1e2b359e70135389134f160aed41352547ef",+ },+ "linux-arm64": {+ archive:+ "00dd72f0f0ac4805d90b3c01a667909f04d6f821f90189791e1dea59cf8507ba",+ ffmpeg: "332e0978b77b74cac50d7243458b4f894b04404f845c5104a40dc9bfb7040c69",+ ffprobe:+ "57d187e0937c5aad150da819d50adcba057fbdd30532e6d3bf447eb9c9edeacc",+ },+ "windows-x64": {+ archive:+ "0d772b1676871c480a8f140c45507c68e3077013d42792088c8db55f1611aba2",+ ffmpeg: "1576d072c63730c353b96bc47f4436ecbf64b4cad05cde9e97926ffd2f7a6c6d",+ ffprobe:+ "a90b435381118dd1c1232608ee76fe995ffc3c53179ac2acb89869f50e79b15b",+ },+ "windows-arm64": {+ archive:+ "4f6df97fcd471adeac97079e271617e0fee322610faeca89f6590c323a5af654",+ ffmpeg: "82c270d2119c68b6f6f409ce1b0a5200cdcc9bef4c5fa4f6f4b0ee60c605e8ca",+ ffprobe:+ "13108f929ff858a7e06530338a9eeecc0b9226b908a1c5631ce14b417fb2fdca",+ },+};++const fileSHA256 = async (file) => {+ const hash = crypto.createHash("sha256");+ for await (const chunk of createReadStream(file)) hash.update(chunk);+ return hash.digest("hex");};const ensureFFmpeg = async (platform, arch, appDir) => {@@ -28,15 +60,29 @@ const ensureFFmpeg = async (platform, arch, appDir) => {const out = path.join(appDir, "build", "ffmpeg");const stamp = path.join(out, ".archive-sha256");- const binaries = ["ffmpeg", "ffprobe"].map((name) =>- platform == "win32" ? `${name}.exe` : name,- );+ const binaries = ["ffmpeg", "ffprobe"].map((name) => ({+ name: platform == "win32" ? `${name}.exe` : name,+ sha256: expected[name],+ }));try {- if ((await fs.readFile(stamp, "utf8")) == expected) {- await Promise.all(- binaries.map((name) => fs.access(path.join(out, name))),+ if ((await fs.readFile(stamp, "utf8")) == expected.archive) {+ const valid = await Promise.all(+ binaries.map(async ({ name, sha256 }) => {+ const file = path.join(out, name);+ return (+ (await fs.lstat(file)).isFile() &&+ (await fileSHA256(file)) == sha256+ );+ }),);- return;+ if (valid.every(Boolean)) {+ await Promise.all(+ binaries.map(({ name }) =>+ fs.chmod(path.join(out, name), 0o755),+ ),+ );+ return;+ }}} catch (e) {if (e.code != "ENOENT") throw e;@@ -51,7 +97,7 @@ const ensureFFmpeg = async (platform, arch, appDir) => {throw new Error(`Failed to download ${asset}: HTTP ${response.status}`);const archive = Buffer.from(await response.arrayBuffer());const actual = crypto.createHash("sha256").update(archive).digest("hex");- if (actual != expected)+ if (actual != expected.archive)throw new Error(`SHA-256 mismatch for ${asset}: ${actual}`);await fs.mkdir(path.dirname(out), { recursive: true });@@ -70,9 +116,12 @@ const ensureFFmpeg = async (platform, arch, appDir) => {execFileSync("tar", ["-xf", archivePath, "-C", stage]);}await fs.unlink(archivePath);- for (const name of binaries)+ for (const { name } of binaries)await fs.chmod(path.join(stage, name), 0o755);- await fs.writeFile(path.join(stage, ".archive-sha256"), expected);+ await fs.writeFile(+ path.join(stage, ".archive-sha256"),+ expected.archive,+ );await fs.rm(out, { recursive: true, force: true });await fs.rename(stage, out);} finally {