app-builder-lib 27.0.0-alpha.12 → 27.0.0-alpha.13

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 (220) hide show
  1. package/dist/asar/asarUtil.js +1 -1
  2. package/dist/asar/asarUtil.js.map +1 -1
  3. package/dist/codeSign/certInfo.d.ts +4 -1
  4. package/dist/codeSign/certInfo.d.ts.map +1 -1
  5. package/dist/codeSign/certInfo.js +5 -3
  6. package/dist/codeSign/certInfo.js.map +1 -1
  7. package/dist/codeSign/forceCodeSigning.d.ts +22 -0
  8. package/dist/codeSign/forceCodeSigning.d.ts.map +1 -0
  9. package/dist/codeSign/forceCodeSigning.js +18 -0
  10. package/dist/codeSign/forceCodeSigning.js.map +1 -0
  11. package/dist/codeSign/mac/macCodeSign.d.ts +13 -1
  12. package/dist/codeSign/mac/macCodeSign.d.ts.map +1 -1
  13. package/dist/codeSign/mac/macCodeSign.js +29 -2
  14. package/dist/codeSign/mac/macCodeSign.js.map +1 -1
  15. package/dist/codeSign/mac/macSignatureVerifier.d.ts +23 -0
  16. package/dist/codeSign/mac/macSignatureVerifier.d.ts.map +1 -0
  17. package/dist/codeSign/mac/macSignatureVerifier.js +96 -0
  18. package/dist/codeSign/mac/macSignatureVerifier.js.map +1 -0
  19. package/dist/codeSign/win/authenticodeSignature.d.ts +14 -2
  20. package/dist/codeSign/win/authenticodeSignature.d.ts.map +1 -1
  21. package/dist/codeSign/win/authenticodeSignature.js +78 -30
  22. package/dist/codeSign/win/authenticodeSignature.js.map +1 -1
  23. package/dist/codeSign/win/pkcs11SignManager.d.ts.map +1 -1
  24. package/dist/codeSign/win/pkcs11SignManager.js +4 -3
  25. package/dist/codeSign/win/pkcs11SignManager.js.map +1 -1
  26. package/dist/codeSign/win/publisherName.d.ts +31 -0
  27. package/dist/codeSign/win/publisherName.d.ts.map +1 -0
  28. package/dist/codeSign/win/publisherName.js +78 -0
  29. package/dist/codeSign/win/publisherName.js.map +1 -0
  30. package/dist/codeSign/win/signtoolBaseSignManager.d.ts +16 -9
  31. package/dist/codeSign/win/signtoolBaseSignManager.d.ts.map +1 -1
  32. package/dist/codeSign/win/signtoolBaseSignManager.js +46 -35
  33. package/dist/codeSign/win/signtoolBaseSignManager.js.map +1 -1
  34. package/dist/codeSign/win/verifyUpdatePublisher.d.ts.map +1 -1
  35. package/dist/codeSign/win/verifyUpdatePublisher.js +7 -4
  36. package/dist/codeSign/win/verifyUpdatePublisher.js.map +1 -1
  37. package/dist/codeSign/win/windowsSignAzureManager.d.ts +1 -1
  38. package/dist/codeSign/win/windowsSignAzureManager.d.ts.map +1 -1
  39. package/dist/codeSign/win/windowsSignAzureManager.js +24 -6
  40. package/dist/codeSign/win/windowsSignAzureManager.js.map +1 -1
  41. package/dist/configuration.d.ts +46 -3
  42. package/dist/configuration.d.ts.map +1 -1
  43. package/dist/configuration.js.map +1 -1
  44. package/dist/electron/mac/asarIntegrityDigest.js +2 -2
  45. package/dist/electron/mac/asarIntegrityDigest.js.map +1 -1
  46. package/dist/electron/mac/electronMacUtils.d.ts +3 -2
  47. package/dist/electron/mac/electronMacUtils.d.ts.map +1 -1
  48. package/dist/electron/mac/electronMacUtils.js +3 -2
  49. package/dist/electron/mac/electronMacUtils.js.map +1 -1
  50. package/dist/fileMatcher.d.ts.map +1 -1
  51. package/dist/fileMatcher.js +4 -2
  52. package/dist/fileMatcher.js.map +1 -1
  53. package/dist/index.d.ts +1 -1
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +4 -3
  56. package/dist/index.js.map +1 -1
  57. package/dist/indexInternal.d.ts +7 -2
  58. package/dist/indexInternal.d.ts.map +1 -1
  59. package/dist/indexInternal.js +6 -2
  60. package/dist/indexInternal.js.map +1 -1
  61. package/dist/linuxPackager.js +1 -1
  62. package/dist/linuxPackager.js.map +1 -1
  63. package/dist/macPackager.d.ts +26 -0
  64. package/dist/macPackager.d.ts.map +1 -1
  65. package/dist/macPackager.js +168 -12
  66. package/dist/macPackager.js.map +1 -1
  67. package/dist/options/PlatformSpecificBuildOptions.d.ts +15 -12
  68. package/dist/options/PlatformSpecificBuildOptions.d.ts.map +1 -1
  69. package/dist/options/PlatformSpecificBuildOptions.js.map +1 -1
  70. package/dist/options/SquirrelWindowsOptions.d.ts +3 -0
  71. package/dist/options/SquirrelWindowsOptions.d.ts.map +1 -1
  72. package/dist/options/SquirrelWindowsOptions.js.map +1 -1
  73. package/dist/options/macOptions.d.ts +7 -2
  74. package/dist/options/macOptions.d.ts.map +1 -1
  75. package/dist/options/macOptions.js.map +1 -1
  76. package/dist/options/winOptions.d.ts +61 -15
  77. package/dist/options/winOptions.d.ts.map +1 -1
  78. package/dist/options/winOptions.js +20 -0
  79. package/dist/options/winOptions.js.map +1 -1
  80. package/dist/packager.d.ts +1 -0
  81. package/dist/packager.d.ts.map +1 -1
  82. package/dist/packager.js +7 -2
  83. package/dist/packager.js.map +1 -1
  84. package/dist/platformPackager.d.ts +14 -5
  85. package/dist/platformPackager.d.ts.map +1 -1
  86. package/dist/platformPackager.js +44 -13
  87. package/dist/platformPackager.js.map +1 -1
  88. package/dist/publish/PublishManager.d.ts +3 -0
  89. package/dist/publish/PublishManager.d.ts.map +1 -1
  90. package/dist/publish/PublishManager.js +50 -16
  91. package/dist/publish/PublishManager.js.map +1 -1
  92. package/dist/publish/manifestUploadCheck.d.ts +10 -0
  93. package/dist/publish/manifestUploadCheck.d.ts.map +1 -0
  94. package/dist/publish/manifestUploadCheck.js +75 -0
  95. package/dist/publish/manifestUploadCheck.js.map +1 -0
  96. package/dist/publish/updateInfoBuilder.d.ts.map +1 -1
  97. package/dist/publish/updateInfoBuilder.js +51 -17
  98. package/dist/publish/updateInfoBuilder.js.map +1 -1
  99. package/dist/publish/updateManifestVerifier.d.ts +22 -0
  100. package/dist/publish/updateManifestVerifier.d.ts.map +1 -0
  101. package/dist/publish/updateManifestVerifier.js +65 -0
  102. package/dist/publish/updateManifestVerifier.js.map +1 -0
  103. package/dist/targets/ArchiveTarget.d.ts.map +1 -1
  104. package/dist/targets/ArchiveTarget.js +6 -2
  105. package/dist/targets/ArchiveTarget.js.map +1 -1
  106. package/dist/targets/archive.d.ts.map +1 -1
  107. package/dist/targets/archive.js +3 -3
  108. package/dist/targets/archive.js.map +1 -1
  109. package/dist/targets/linux/FlatpakTarget.js +5 -5
  110. package/dist/targets/linux/FlatpakTarget.js.map +1 -1
  111. package/dist/targets/linux/FpmTarget.d.ts.map +1 -1
  112. package/dist/targets/linux/FpmTarget.js +10 -7
  113. package/dist/targets/linux/FpmTarget.js.map +1 -1
  114. package/dist/targets/linux/LinuxTargetHelper.js +1 -1
  115. package/dist/targets/linux/LinuxTargetHelper.js.map +1 -1
  116. package/dist/targets/linux/appimage/AppImageTarget.d.ts.map +1 -1
  117. package/dist/targets/linux/appimage/AppImageTarget.js +6 -1
  118. package/dist/targets/linux/appimage/AppImageTarget.js.map +1 -1
  119. package/dist/targets/linux/appimage/appImageUtil.js +9 -9
  120. package/dist/targets/linux/appimage/appImageUtil.js.map +1 -1
  121. package/dist/targets/linux/flatpakBundle.d.ts.map +1 -1
  122. package/dist/targets/linux/flatpakBundle.js +25 -20
  123. package/dist/targets/linux/flatpakBundle.js.map +1 -1
  124. package/dist/targets/linux/snap/coreLegacy.d.ts.map +1 -1
  125. package/dist/targets/linux/snap/coreLegacy.js +22 -6
  126. package/dist/targets/linux/snap/coreLegacy.js.map +1 -1
  127. package/dist/targets/linux/snap/snapPlugs.d.ts +2 -2
  128. package/dist/targets/linux/snap/snapPlugs.d.ts.map +1 -1
  129. package/dist/targets/linux/snap/snapPlugs.js +1 -1
  130. package/dist/targets/linux/snap/snapPlugs.js.map +1 -1
  131. package/dist/targets/linux/snap/snapcraftBuilder.d.ts.map +1 -1
  132. package/dist/targets/linux/snap/snapcraftBuilder.js +19 -17
  133. package/dist/targets/linux/snap/snapcraftBuilder.js.map +1 -1
  134. package/dist/targets/mac/MacTargetHelper.d.ts +15 -3
  135. package/dist/targets/mac/MacTargetHelper.d.ts.map +1 -1
  136. package/dist/targets/mac/MacTargetHelper.js +96 -13
  137. package/dist/targets/mac/MacTargetHelper.js.map +1 -1
  138. package/dist/targets/mac/pkg.d.ts.map +1 -1
  139. package/dist/targets/mac/pkg.js +7 -5
  140. package/dist/targets/mac/pkg.js.map +1 -1
  141. package/dist/targets/win/nsis/NsisTarget.d.ts.map +1 -1
  142. package/dist/targets/win/nsis/NsisTarget.js +8 -2
  143. package/dist/targets/win/nsis/NsisTarget.js.map +1 -1
  144. package/dist/targets/win/nsis/nsisOptions.d.ts +1 -1
  145. package/dist/targets/win/nsis/nsisOptions.js.map +1 -1
  146. package/dist/toolsets/nsis.js +1 -1
  147. package/dist/toolsets/nsis.js.map +1 -1
  148. package/dist/toolsets/wine.d.ts +3 -0
  149. package/dist/toolsets/wine.d.ts.map +1 -1
  150. package/dist/toolsets/wine.js +14 -5
  151. package/dist/toolsets/wine.js.map +1 -1
  152. package/dist/util/appFileCopier.d.ts.map +1 -1
  153. package/dist/util/appFileCopier.js +9 -3
  154. package/dist/util/appFileCopier.js.map +1 -1
  155. package/dist/util/buildOutputVerifier.d.ts +40 -0
  156. package/dist/util/buildOutputVerifier.d.ts.map +1 -0
  157. package/dist/util/buildOutputVerifier.js +420 -0
  158. package/dist/util/buildOutputVerifier.js.map +1 -0
  159. package/dist/util/config/fileOptions.js +2 -2
  160. package/dist/util/config/fileOptions.js.map +1 -1
  161. package/dist/util/config/legacyConfigGuard.d.ts.map +1 -1
  162. package/dist/util/config/legacyConfigGuard.js +2 -2
  163. package/dist/util/config/legacyConfigGuard.js.map +1 -1
  164. package/dist/util/config/legacyOptions.d.ts +9 -2
  165. package/dist/util/config/legacyOptions.d.ts.map +1 -1
  166. package/dist/util/config/legacyOptions.js +8 -2
  167. package/dist/util/config/legacyOptions.js.map +1 -1
  168. package/dist/util/electronGet.d.ts.map +1 -1
  169. package/dist/util/electronGet.js +3 -1
  170. package/dist/util/electronGet.js.map +1 -1
  171. package/dist/util/flags.d.ts.map +1 -1
  172. package/dist/util/flags.js +3 -9
  173. package/dist/util/flags.js.map +1 -1
  174. package/dist/util/mac/macosIconComposer.d.ts.map +1 -1
  175. package/dist/util/mac/macosIconComposer.js +6 -5
  176. package/dist/util/mac/macosIconComposer.js.map +1 -1
  177. package/dist/util/macroExpander.js +1 -1
  178. package/dist/util/macroExpander.js.map +1 -1
  179. package/dist/util/nativeBinaryVerifier.d.ts.map +1 -1
  180. package/dist/util/nativeBinaryVerifier.js +3 -1
  181. package/dist/util/nativeBinaryVerifier.js.map +1 -1
  182. package/dist/util/packageMetadata.js +1 -1
  183. package/dist/util/packageMetadata.js.map +1 -1
  184. package/dist/util/removedEnvVars.d.ts +2 -0
  185. package/dist/util/removedEnvVars.d.ts.map +1 -1
  186. package/dist/util/removedEnvVars.js +15 -1
  187. package/dist/util/removedEnvVars.js.map +1 -1
  188. package/dist/util/streamSpawnToFile.d.ts +3 -1
  189. package/dist/util/streamSpawnToFile.d.ts.map +1 -1
  190. package/dist/util/streamSpawnToFile.js +6 -2
  191. package/dist/util/streamSpawnToFile.js.map +1 -1
  192. package/dist/version.d.ts +1 -1
  193. package/dist/version.js +1 -1
  194. package/dist/version.js.map +1 -1
  195. package/dist/vm/ParallelsVm.d.ts +10 -0
  196. package/dist/vm/ParallelsVm.d.ts.map +1 -1
  197. package/dist/vm/ParallelsVm.js +22 -8
  198. package/dist/vm/ParallelsVm.js.map +1 -1
  199. package/dist/vm/PwshVm.d.ts +0 -1
  200. package/dist/vm/PwshVm.d.ts.map +1 -1
  201. package/dist/vm/PwshVm.js +10 -15
  202. package/dist/vm/PwshVm.js.map +1 -1
  203. package/dist/vm/WineVm.d.ts.map +1 -1
  204. package/dist/vm/WineVm.js +4 -4
  205. package/dist/vm/WineVm.js.map +1 -1
  206. package/dist/vm/vm.d.ts +9 -3
  207. package/dist/vm/vm.d.ts.map +1 -1
  208. package/dist/vm/vm.js +40 -32
  209. package/dist/vm/vm.js.map +1 -1
  210. package/dist/winPackager.d.ts +16 -1
  211. package/dist/winPackager.d.ts.map +1 -1
  212. package/dist/winPackager.js +77 -19
  213. package/dist/winPackager.js.map +1 -1
  214. package/package.json +9 -9
  215. package/scheme.json +497 -23
  216. package/templates/nsis/include/allowOnlyOneInstallerInstance.nsh +14 -9
  217. package/dist/vm/MonoVm.d.ts +0 -9
  218. package/dist/vm/MonoVm.d.ts.map +0 -1
  219. package/dist/vm/MonoVm.js +0 -16
  220. package/dist/vm/MonoVm.js.map +0 -1
@@ -0,0 +1,420 @@
1
+ import { isPathWithin } from "builder-util";
2
+ import { asArray, matchPublisherName, normalizePublicKeyList } from "builder-util-runtime";
3
+ import { readdir, readFile, realpath, stat } from "fs/promises";
4
+ import { load } from "js-yaml";
5
+ import * as path from "path";
6
+ import { checkInstallerPackageSignature, validateStapledTicket, verifyMacCodeSignature } from "../codeSign/mac/macSignatureVerifier.js";
7
+ import { AuthenticodeSignatureStatus, authenticodeSignatureStatusName, isAuthenticodeFileType, readAuthenticodeSigner, } from "../codeSign/win/authenticodeSignature.js";
8
+ import { shouldSignWindowsFile } from "../options/winOptions.js";
9
+ import { updateManifestPlatform, verifyUpdateManifestContent } from "../publish/updateManifestVerifier.js";
10
+ import { hashFile } from "./hash.js";
11
+ // The app output directories of the targets: `<platform><-arch, unless it is the default arch>`, with `-unpacked` for Windows and
12
+ // Linux (PlatformPackager.computeAppOutDir) and the MAS target name for MAS (MacPackager.packMasTargets)
13
+ const ARCH_SUFFIX = "(?:-(?:ia32|x64|armv7l|arm64|universal))?";
14
+ const MAC_APP_DIR = new RegExp(`^(mac|mas|mas-dev)${ARCH_SUFFIX}$`);
15
+ const UNPACKED_APP_DIR = new RegExp(`^(win|linux)${ARCH_SUFFIX}-unpacked$`);
16
+ const MAC_CONFIG_KEYS = { mac: ["mac"], mas: ["mac", "mas"], "mas-dev": ["mac", "mas", "masDev"] };
17
+ const NOT_MANIFESTS = new Set(["app-update.yml", "builder-debug.yml", "builder-effective-config.yaml"]);
18
+ /**
19
+ * Verifies the built artifacts in an output directory, the checks `forceCodeSigning` makes during a build plus what can
20
+ * only be seen afterwards:
21
+ * - every update manifest (`latest*.yml`, found by its shape) is signed by a key in the trust list (`updateManifestPublicKey`)
22
+ * of every packaged app of its platform, and each file it lists matches an artifact (sha512 and size);
23
+ * - macOS (on macOS only): every `.app` has a valid code signature and, outside the Mac App Store, a stapled notarization
24
+ * ticket; a `.pkg` is signed (and notarized); a DMG with `dmg.sign: true` is signed;
25
+ * - Windows: every installer, package and app executable carries a valid Authenticode signature (whose hash only Windows
26
+ * can validate), and the update installers match the `publisherName` electron-updater verifies them against.
27
+ *
28
+ * Opt-outs in `config` (`updateManifest: false`, `mac.notarize: false`, `win.sign: false`, `signExts` exclusions, ...)
29
+ * turn the affected checks into `skipped` results, whatever the host.
30
+ */
31
+ export async function verifyBuildOutput(options) {
32
+ // absolute, so that every path handed to codesign, stapler or pkgutil starts with "/": a file name of the output (which is not
33
+ // trusted) such as "-v.pkg" never reaches them as an option
34
+ const outDir = path.resolve(options.outDir);
35
+ const { config } = options;
36
+ const { apps, files } = await discover(outDir);
37
+ const results = [];
38
+ for (const app of apps) {
39
+ if (app.updateConfigProblem != null) {
40
+ results.push({ status: "failed", check: "app update configuration", file: app.updateConfigFile, message: app.updateConfigProblem });
41
+ }
42
+ }
43
+ const manifests = [];
44
+ for (const file of files.filter(it => /\.ya?ml$/.test(it) && !NOT_MANIFESTS.has(path.basename(it)))) {
45
+ const manifest = await readManifest(file);
46
+ if (manifest != null) {
47
+ manifests.push(manifest);
48
+ }
49
+ }
50
+ const hashes = new Map();
51
+ const sha512Of = (file) => {
52
+ let hash = hashes.get(file);
53
+ if (hash == null) {
54
+ hash = hashFile(file);
55
+ hashes.set(file, hash);
56
+ }
57
+ return hash;
58
+ };
59
+ // the local files the Windows manifests point electron-updater at: their signer must match the embedded publisherName
60
+ const windowsUpdateInstallers = new Set();
61
+ for (const manifest of manifests) {
62
+ results.push(...verifyManifestSignature(manifest, apps, options));
63
+ for (const { result, artifact } of await verifyManifestFiles(manifest, files, outDir, sha512Of)) {
64
+ results.push(result);
65
+ if (artifact != null && manifest.platform === "win") {
66
+ windowsUpdateInstallers.add(artifact);
67
+ }
68
+ }
69
+ }
70
+ results.push(...(await verifyMacArtifacts(apps, files, outDir, config)));
71
+ results.push(...(await verifyWindowsArtifacts(apps, files, config, options.readSigner ?? readAuthenticodeSigner, windowsUpdateInstallers)));
72
+ return results;
73
+ }
74
+ // ─── discovery ────────────────────────────────────────────────────────────────
75
+ // How deep below a target folder files are collected: a further publish provider's manifest of a target with its own folder is
76
+ // one level down (<outDir>/nsis-web/<provider>/latest.yml, see createUpdateInfoTasks)
77
+ const MAX_TARGET_DIR_DEPTH = 2;
78
+ /**
79
+ * Collects the regular files of a target folder and of its subfolders, up to {@link MAX_TARGET_DIR_DEPTH} levels down. The output is not
80
+ * trusted: a symlink is never followed, and a folder whose real path is not inside the output folder is not read.
81
+ */
82
+ async function collectTargetFiles(dir, realOutDir, depth, files) {
83
+ if (!isPathWithin(realOutDir, await realpath(dir))) {
84
+ return;
85
+ }
86
+ for (const child of await readdir(dir, { withFileTypes: true })) {
87
+ if (child.name.startsWith(".")) {
88
+ continue;
89
+ }
90
+ const childPath = path.join(dir, child.name);
91
+ // Dirent types come from lstat: a symlink is neither a file nor a directory here
92
+ if (child.isFile()) {
93
+ files.push(childPath);
94
+ }
95
+ else if (child.isDirectory() && depth < MAX_TARGET_DIR_DEPTH) {
96
+ await collectTargetFiles(childPath, realOutDir, depth + 1, files);
97
+ }
98
+ }
99
+ }
100
+ async function discover(outDir) {
101
+ const apps = [];
102
+ const files = [];
103
+ const realOutDir = await realpath(outDir);
104
+ for (const entry of await readdir(outDir, { withFileTypes: true })) {
105
+ const entryPath = path.join(outDir, entry.name);
106
+ if (entry.name.startsWith(".")) {
107
+ continue;
108
+ }
109
+ if (entry.isFile()) {
110
+ files.push(entryPath);
111
+ continue;
112
+ }
113
+ // universal builds pack each arch into a temporary `*-temp` dir first
114
+ if (!entry.isDirectory() || entry.name.endsWith("-temp")) {
115
+ continue;
116
+ }
117
+ const macDir = MAC_APP_DIR.exec(entry.name);
118
+ const unpackedDir = UNPACKED_APP_DIR.exec(entry.name);
119
+ if (macDir != null) {
120
+ const macConfigKeys = MAC_CONFIG_KEYS[macDir[1]] ?? ["mac"];
121
+ const isMas = macDir[1] !== "mac";
122
+ for (const child of await readdir(entryPath, { withFileTypes: true })) {
123
+ const childPath = path.join(entryPath, child.name);
124
+ if (child.isDirectory() && child.name.endsWith(".app")) {
125
+ apps.push(await readApp("mac", childPath, isMas, macConfigKeys, path.join(childPath, "Contents", "Resources", "app-update.yml")));
126
+ }
127
+ else if (child.isFile() && child.name.endsWith(".pkg")) {
128
+ // the MAS installer is written next to the app
129
+ files.push(childPath);
130
+ }
131
+ }
132
+ }
133
+ else if (unpackedDir != null) {
134
+ const platform = unpackedDir[1] === "win" ? "win" : "linux";
135
+ apps.push(await readApp(platform, entryPath, false, [], path.join(entryPath, "resources", "app-update.yml")));
136
+ }
137
+ else {
138
+ // nsis-web/, squirrel-windows*/, and the manifests of a further publish provider (<outDir>/<provider>/, <outDir>/nsis-web/<provider>/)
139
+ await collectTargetFiles(entryPath, realOutDir, 0, files);
140
+ }
141
+ }
142
+ return { apps, files };
143
+ }
144
+ async function readApp(platform, appPath, isMas, macConfigKeys, updateConfigFile) {
145
+ const app = { platform, path: appPath, isMas, macConfigKeys, updateConfigFile };
146
+ const problem = (updateConfigProblem) => ({ ...app, updateConfig: null, updateConfigProblem });
147
+ let content;
148
+ try {
149
+ // The output can be downloaded artifacts, which are not trusted: app-update.yml is read only as a regular file inside the app,
150
+ // never through a symlink to another file on this machine (whose content a YAML error would print)
151
+ const [appRealPath, configRealPath] = await Promise.all([realpath(appPath), realpath(updateConfigFile)]);
152
+ if (!isPathWithin(appRealPath, configRealPath)) {
153
+ return problem("app-update.yml is a symlink that leads out of the app");
154
+ }
155
+ if (!(await stat(configRealPath)).isFile()) {
156
+ return problem("app-update.yml is not a file");
157
+ }
158
+ content = await readFile(configRealPath, "utf8");
159
+ }
160
+ catch (e) {
161
+ // ENOTDIR: a "resources" (or "Resources") that is a file, so there is no app-update.yml either
162
+ if (e.code === "ENOENT" || e.code === "ENOTDIR") {
163
+ return { ...app, updateConfig: null, updateConfigProblem: null };
164
+ }
165
+ throw e;
166
+ }
167
+ let parsed;
168
+ try {
169
+ parsed = load(content);
170
+ }
171
+ catch (e) {
172
+ // the reason only: the message of a YAML error quotes the content
173
+ return problem(`app-update.yml is not valid YAML (${e.reason ?? "cannot be parsed"})`);
174
+ }
175
+ if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
176
+ return problem("app-update.yml is not a YAML mapping");
177
+ }
178
+ const updateConfig = parsed;
179
+ const publisherNames = updateConfig.verifyUpdateCodeSignature === false || updateConfig.publisherName == null
180
+ ? null
181
+ : asArray(updateConfig.publisherName).filter((it) => typeof it === "string");
182
+ return {
183
+ ...app,
184
+ updateConfig: { trustedKeys: normalizePublicKeyList(updateConfig.updateManifestPublicKey), publisherNames },
185
+ updateConfigProblem: null,
186
+ };
187
+ }
188
+ async function readManifest(file) {
189
+ const content = await readFile(file, "utf8");
190
+ let info;
191
+ try {
192
+ info = load(content);
193
+ }
194
+ catch {
195
+ return null;
196
+ }
197
+ if (info == null || typeof info !== "object" || typeof info.version !== "string" || !Array.isArray(info.files)) {
198
+ return null;
199
+ }
200
+ return { file, platform: updateManifestPlatform(file), content, info };
201
+ }
202
+ /** A platform-level value wins over the root one, as in the build (`PlatformPackager.updateManifestOptions`). */
203
+ function platformOption(config, platform, key) {
204
+ return config[platform]?.[key] ?? config[key];
205
+ }
206
+ // ─── update manifests ─────────────────────────────────────────────────────────
207
+ function verifyManifestSignature(manifest, apps, options) {
208
+ const check = "update manifest signature";
209
+ const result = (status, message) => ({ status, check, file: manifest.file, message });
210
+ const updateManifest = platformOption(options.config, manifest.platform, "updateManifest");
211
+ if (updateManifest === false) {
212
+ return [result("skipped", "updateManifest is false in the configuration, so the manifest is not signed")];
213
+ }
214
+ // Only public keys are used: verify never loads a signing (private) key, from the configuration or the environment.
215
+ // A deliberate cutover release is signed with a key outside the trust list it embeds (updateManifest.allowSigningKeyOutsideTrustList),
216
+ // whose public key verify does not have.
217
+ const cutover = (reason) => result("skipped", `${reason}, which updateManifest.allowSigningKeyOutsideTrustList allows for a cutover release signed with a key outside the trust list`);
218
+ const trustingApps = [];
219
+ for (const app of apps) {
220
+ if (app.platform === manifest.platform && !app.isMas && app.updateConfig != null) {
221
+ trustingApps.push({ app, trustedKeys: app.updateConfig.trustedKeys });
222
+ }
223
+ }
224
+ if (trustingApps.length === 0) {
225
+ const keys = updateManifest?.publicKey == null ? [] : normalizePublicKeyList(updateManifest.publicKey);
226
+ if (keys.length === 0) {
227
+ return [
228
+ result("unverifiable", "no packaged app embeds a trust list (app-update.yml), and updateManifest.publicKey is not set in the configuration: set it to the public keys to verify the manifest with"),
229
+ ];
230
+ }
231
+ const verification = verifyUpdateManifestContent(manifest.content, keys);
232
+ if (verification.ok) {
233
+ return [result("verified", `signed by ${verification.keyId}, a key in the configuration (no packaged app was found to read the trust list from)`)];
234
+ }
235
+ return [
236
+ updateManifest?.allowSigningKeyOutsideTrustList === true
237
+ ? cutover(`not signed by a key of updateManifest.publicKey (${verification.reason})`)
238
+ : result("failed", verification.reason),
239
+ ];
240
+ }
241
+ return trustingApps.map(({ app, trustedKeys }) => {
242
+ if (trustedKeys.length === 0) {
243
+ return result("failed", `${path.relative(options.outDir, app.updateConfigFile)} embeds no updateManifestPublicKey, so installs of this build accept any update manifest`);
244
+ }
245
+ const verification = verifyUpdateManifestContent(manifest.content, trustedKeys);
246
+ if (verification.ok) {
247
+ return result("verified", `signed by ${verification.keyId}, which ${path.relative(options.outDir, app.updateConfigFile)} trusts`);
248
+ }
249
+ const reason = `not accepted by the trust list of ${path.relative(options.outDir, app.updateConfigFile)} (${verification.reason})`;
250
+ return updateManifest?.allowSigningKeyOutsideTrustList === true ? cutover(reason) : result("failed", reason);
251
+ });
252
+ }
253
+ async function verifyManifestFiles(manifest, files, outDir, sha512Of) {
254
+ const check = "update manifest file";
255
+ // the artifacts of a target with its own folder (nsis-web/) are there, also for the manifest of a further provider (nsis-web/<provider>/)
256
+ const parts = path.relative(outDir, manifest.file).split(path.sep);
257
+ const targetDir = parts.length > 1 ? path.join(outDir, parts[0]) : outDir;
258
+ const dirs = new Set([path.dirname(manifest.file), targetDir, outDir]);
259
+ const candidates = files.filter(it => dirs.has(path.dirname(it)) && !/\.(ya?ml|blockmap)$/.test(it));
260
+ const verified = [];
261
+ for (const entry of manifest.info.files) {
262
+ const name = typeof entry?.url === "string" ? entry.url : "(no url)";
263
+ if (typeof entry?.sha512 !== "string") {
264
+ verified.push({ result: { status: "failed", check, file: manifest.file, message: `files entry ${name} has no sha512` }, artifact: null });
265
+ continue;
266
+ }
267
+ // matched by hash, not by name: a GitHub manifest lists the safe artifact name, which can differ from the local file name
268
+ let artifact = null;
269
+ for (const candidate of candidates) {
270
+ if (typeof entry.size === "number" && (await stat(candidate)).size !== entry.size) {
271
+ continue;
272
+ }
273
+ if ((await sha512Of(candidate)) === entry.sha512) {
274
+ artifact = candidate;
275
+ break;
276
+ }
277
+ }
278
+ verified.push({
279
+ result: artifact == null
280
+ ? {
281
+ status: "failed",
282
+ check,
283
+ file: manifest.file,
284
+ message: `no artifact matches the sha512${typeof entry.size === "number" ? " and size" : ""} of ${name}: it is missing, or it was changed after the manifest was written`,
285
+ }
286
+ : { status: "verified", check, file: manifest.file, message: `${name} matches ${path.relative(outDir, artifact)}` },
287
+ artifact,
288
+ });
289
+ }
290
+ return verified;
291
+ }
292
+ // ─── macOS ────────────────────────────────────────────────────────────────────
293
+ /**
294
+ * The `sign` option of a macOS app, cascaded over its configuration blocks as the build does (a later block wins, and sign objects
295
+ * are merged): whether it opts out of signing (`sign: null` or `sign.identity: null`), and its `strictVerify`.
296
+ */
297
+ function macSigning(config, keys) {
298
+ let sign = undefined;
299
+ let where = "mac.sign";
300
+ for (const key of keys) {
301
+ const value = config[key]?.sign;
302
+ if (value === undefined) {
303
+ continue;
304
+ }
305
+ where = `${key}.sign`;
306
+ sign = isPlainSignObject(value) && isPlainSignObject(sign) ? { ...sign, ...value } : value;
307
+ }
308
+ if (sign === null || (isPlainSignObject(sign) && sign.identity === null)) {
309
+ return { signingOptOut: `${where} (or its identity) is null in the configuration`, strict: undefined };
310
+ }
311
+ const strict = isPlainSignObject(sign) ? sign.strictVerify : undefined;
312
+ return { signingOptOut: null, strict: typeof strict === "boolean" || typeof strict === "string" ? strict : undefined };
313
+ }
314
+ function isPlainSignObject(value) {
315
+ return value != null && typeof value === "object" && !Array.isArray(value);
316
+ }
317
+ async function verifyMacArtifacts(apps, files, outDir, config) {
318
+ const macApps = apps.filter(it => it.platform === "mac");
319
+ const pkgs = files.filter(it => it.endsWith(".pkg"));
320
+ const dmgs = config.dmg?.sign === true ? files.filter(it => it.endsWith(".dmg") && path.dirname(it) === outDir) : [];
321
+ const notarizeDisabled = config.mac?.notarize === false;
322
+ const results = [];
323
+ const run = async (check, file, optOut, task) => {
324
+ if (optOut != null) {
325
+ results.push({ status: "skipped", check, file, message: optOut });
326
+ }
327
+ else if (process.platform !== "darwin") {
328
+ results.push({ status: "unverifiable", check, file, message: `needs Apple's tools, which run on macOS only (this host is ${process.platform})` });
329
+ }
330
+ else {
331
+ const problem = await task();
332
+ results.push(problem == null ? { status: "verified", check, file, message: "valid" } : { status: "failed", check, file, message: problem });
333
+ }
334
+ };
335
+ const notarizeOptOut = notarizeDisabled ? "mac.notarize is false in the configuration" : null;
336
+ for (const app of macApps) {
337
+ // a MAS app is signed with its mas (and masDev) configuration, which cascades over mac
338
+ const { signingOptOut, strict } = macSigning(config, app.macConfigKeys);
339
+ await run("code signature", app.path, signingOptOut, () => verifyMacCodeSignature(app.path, { deep: true, strict }));
340
+ if (!app.isMas) {
341
+ await run("notarization ticket", app.path, signingOptOut ?? notarizeOptOut, () => validateStapledTicket(app.path));
342
+ }
343
+ }
344
+ const signingOptOut = macSigning(config, ["mac"]).signingOptOut;
345
+ for (const pkg of pkgs) {
346
+ await run("installer signature", pkg, null, () => checkInstallerPackageSignature(pkg));
347
+ // the MAS installer (next to the app, in mas*/) goes to the App Store unnotarized
348
+ if (path.dirname(pkg) === outDir) {
349
+ await run("notarization ticket", pkg, notarizeOptOut, () => validateStapledTicket(pkg));
350
+ }
351
+ }
352
+ for (const dmg of dmgs) {
353
+ await run("code signature", dmg, signingOptOut, () => verifyMacCodeSignature(dmg, { deep: false }));
354
+ }
355
+ return results;
356
+ }
357
+ // ─── Windows ──────────────────────────────────────────────────────────────────
358
+ async function verifyWindowsArtifacts(apps, files, config, readSigner, updateInstallers) {
359
+ const check = "Authenticode signature";
360
+ const appExecutables = [];
361
+ for (const app of apps.filter(it => it.platform === "win")) {
362
+ for (const entry of await readdir(app.path, { withFileTypes: true })) {
363
+ if (entry.isFile() && entry.name.endsWith(".exe")) {
364
+ appExecutables.push(path.join(app.path, entry.name));
365
+ }
366
+ }
367
+ }
368
+ const targets = [...files.filter(it => isAuthenticodeFileType(it)), ...appExecutables];
369
+ const publisherNameSets = [];
370
+ for (const app of apps) {
371
+ const publisherNames = app.platform === "win" ? app.updateConfig?.publisherNames : null;
372
+ if (publisherNames != null) {
373
+ publisherNameSets.push(publisherNames);
374
+ }
375
+ }
376
+ const signingDisabled = config.win?.sign === false || config.win?.sign === null;
377
+ const results = [];
378
+ for (const file of targets) {
379
+ if (signingDisabled) {
380
+ results.push({ status: "skipped", check, file, message: "win.sign is false in the configuration" });
381
+ continue;
382
+ }
383
+ if (!shouldSignWindowsFile(file, config.win?.signExts, true)) {
384
+ results.push({ status: "skipped", check, file, message: "excluded from signing by win.signExts" });
385
+ continue;
386
+ }
387
+ const signer = await readSigner(file);
388
+ if (signer.type === "unsigned") {
389
+ results.push({ status: "failed", check, file, message: `carries no Authenticode signature (${signer.reason})` });
390
+ continue;
391
+ }
392
+ if (signer.type === "unreadable") {
393
+ results.push({ status: "unverifiable", check, file, message: `the signature cannot be read on this host (${signer.reason})` });
394
+ continue;
395
+ }
396
+ if (signer.status === AuthenticodeSignatureStatus.HashMismatch) {
397
+ results.push({ status: "failed", check, file, message: "the signature does not match the file (HashMismatch: it was modified after signing)" });
398
+ continue;
399
+ }
400
+ results.push(signer.status == null
401
+ ? { status: "unverifiable", check, file, message: `signed by ${signer.subject}, but the signature hash can only be validated on Windows` }
402
+ : { status: "verified", check, file, message: `signed by ${signer.subject} (${authenticodeSignatureStatusName(signer.status)})` });
403
+ if (updateInstallers.has(file)) {
404
+ // matchPublisherName takes the parsed Get-AuthenticodeSignature output, as electron-updater passes it
405
+ const signature = { SignerCertificate: { Subject: signer.subject } };
406
+ for (const publisherNames of publisherNameSets) {
407
+ results.push(matchPublisherName(signature, publisherNames)
408
+ ? { status: "verified", check: "update publisher", file, message: `the signer matches publisherName ${publisherNames.join(" | ")}` }
409
+ : {
410
+ status: "failed",
411
+ check: "update publisher",
412
+ file,
413
+ message: `the signer ${signer.subject} does not match publisherName ${publisherNames.join(" | ")} in app-update.yml, so electron-updater would reject this update`,
414
+ });
415
+ }
416
+ }
417
+ }
418
+ return results;
419
+ }
420
+ //# sourceMappingURL=buildOutputVerifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildOutputVerifier.js","sourceRoot":"","sources":["../../src/util/buildOutputVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAc,MAAM,sBAAsB,CAAA;AACtG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,8BAA8B,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MA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AAC,CAAA;YAC/I,SAAQ;QACV,CAAC;QACD,OAAO,CAAC,IAAI,CACV,MAAM,CAAC,MAAM,IAAI,IAAI;YACnB,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,MAAM,CAAC,OAAO,2DAA2D,EAAE;YAC1I,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,MAAM,CAAC,OAAO,KAAK,+BAA+B,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CACpI,CAAA;QAED,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,sGAAsG;YACtG,MAAM,SAAS,GAAG,EAAE,iBAAiB,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,CAAA;YACpE,KAAK,MAAM,cAAc,IAAI,iBAAiB,EAAE,CAAC;gBAC/C,OAAO,CAAC,IAAI,CACV,kBAAkB,CAAC,SAAS,EAAE,cAAc,CAAC;oBAC3C,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,EAAE,oCAAoC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE;oBACpI,CAAC,CAAC;wBACE,MAAM,EAAE,QAAQ;wBAChB,KAAK,EAAE,kBAAkB;wBACzB,IAAI;wBACJ,OAAO,EAAE,cAAc,MAAM,CAAC,OAAO,iCAAiC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,kEAAkE;qBACnK,CACN,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { isPathWithin } from \"builder-util\"\nimport { asArray, matchPublisherName, normalizePublicKeyList, UpdateInfo } from \"builder-util-runtime\"\nimport { readdir, readFile, realpath, stat } from \"fs/promises\"\nimport { load } from \"js-yaml\"\nimport * as path from \"path\"\nimport { checkInstallerPackageSignature, validateStapledTicket, verifyMacCodeSignature } from \"../codeSign/mac/macSignatureVerifier.js\"\nimport {\n AuthenticodeSignatureStatus,\n authenticodeSignatureStatusName,\n AuthenticodeSignerReader,\n isAuthenticodeFileType,\n readAuthenticodeSigner,\n} from \"../codeSign/win/authenticodeSignature.js\"\nimport type { Configuration } from \"../configuration.js\"\nimport { shouldSignWindowsFile } from \"../options/winOptions.js\"\nimport { updateManifestPlatform, verifyUpdateManifestContent } from \"../publish/updateManifestVerifier.js\"\nimport { hashFile } from \"./hash.js\"\n\n/**\n * - `verified` — the check passed\n * - `failed` — the check ran and failed\n * - `unverifiable` — the check cannot run here (e.g. codesign off macOS, no trust list to verify a manifest against)\n * - `skipped` — the configuration opts out of what the check verifies (e.g. `mac.notarize: false`)\n */\nexport type VerificationStatus = \"verified\" | \"failed\" | \"unverifiable\" | \"skipped\"\n\nexport interface VerificationResult {\n readonly status: VerificationStatus\n /** What was checked, e.g. \"update manifest signature\". */\n readonly check: string\n /** The file or directory the check is about. */\n readonly file: string\n readonly message: string\n}\n\nexport interface VerifyBuildOutputOptions {\n /** The output directory of the build (`directories.output`). */\n readonly outDir: string\n /** The configuration of the build that produced the output: its opt-outs are honored. */\n readonly config: Configuration\n /** Reads Windows Authenticode signatures; defaults to {@link readAuthenticodeSigner}. */\n readonly readSigner?: AuthenticodeSignerReader\n}\n\ntype PlatformKey = \"mac\" | \"win\" | \"linux\"\ntype MacConfigKey = \"mac\" | \"mas\" | \"masDev\"\n\n// The app output directories of the targets: `<platform><-arch, unless it is the default arch>`, with `-unpacked` for Windows and\n// Linux (PlatformPackager.computeAppOutDir) and the MAS target name for MAS (MacPackager.packMasTargets)\nconst ARCH_SUFFIX = \"(?:-(?:ia32|x64|armv7l|arm64|universal))?\"\nconst MAC_APP_DIR = new RegExp(`^(mac|mas|mas-dev)${ARCH_SUFFIX}$`)\nconst UNPACKED_APP_DIR = new RegExp(`^(win|linux)${ARCH_SUFFIX}-unpacked$`)\nconst MAC_CONFIG_KEYS: Readonly<Record<string, ReadonlyArray<MacConfigKey>>> = { mac: [\"mac\"], mas: [\"mac\", \"mas\"], \"mas-dev\": [\"mac\", \"mas\", \"masDev\"] }\n\ninterface PackagedApp {\n readonly platform: PlatformKey\n /** The `.app` bundle, or the `*-unpacked` directory. */\n readonly path: string\n readonly isMas: boolean\n /** The configuration blocks of a macOS app, in the order they cascade (`mac`, then `mas`, then `masDev`); empty for other platforms. */\n readonly macConfigKeys: ReadonlyArray<MacConfigKey>\n readonly updateConfigFile: string\n /** The parsed `app-update.yml`, or null when the app has none (it does not auto-update) or it cannot be read. */\n readonly updateConfig: { readonly trustedKeys: Array<string>; readonly publisherNames: Array<string> | null } | null\n /** Why `app-update.yml` cannot be read, or null. */\n readonly updateConfigProblem: string | null\n}\n\ninterface Manifest {\n readonly file: string\n readonly platform: PlatformKey\n readonly content: string\n readonly info: UpdateInfo\n}\n\nconst NOT_MANIFESTS = new Set([\"app-update.yml\", \"builder-debug.yml\", \"builder-effective-config.yaml\"])\n\n/**\n * Verifies the built artifacts in an output directory, the checks `forceCodeSigning` makes during a build plus what can\n * only be seen afterwards:\n * - every update manifest (`latest*.yml`, found by its shape) is signed by a key in the trust list (`updateManifestPublicKey`)\n * of every packaged app of its platform, and each file it lists matches an artifact (sha512 and size);\n * - macOS (on macOS only): every `.app` has a valid code signature and, outside the Mac App Store, a stapled notarization\n * ticket; a `.pkg` is signed (and notarized); a DMG with `dmg.sign: true` is signed;\n * - Windows: every installer, package and app executable carries a valid Authenticode signature (whose hash only Windows\n * can validate), and the update installers match the `publisherName` electron-updater verifies them against.\n *\n * Opt-outs in `config` (`updateManifest: false`, `mac.notarize: false`, `win.sign: false`, `signExts` exclusions, ...)\n * turn the affected checks into `skipped` results, whatever the host.\n */\nexport async function verifyBuildOutput(options: VerifyBuildOutputOptions): Promise<Array<VerificationResult>> {\n // absolute, so that every path handed to codesign, stapler or pkgutil starts with \"/\": a file name of the output (which is not\n // trusted) such as \"-v.pkg\" never reaches them as an option\n const outDir = path.resolve(options.outDir)\n const { config } = options\n const { apps, files } = await discover(outDir)\n const results: Array<VerificationResult> = []\n for (const app of apps) {\n if (app.updateConfigProblem != null) {\n results.push({ status: \"failed\", check: \"app update configuration\", file: app.updateConfigFile, message: app.updateConfigProblem })\n }\n }\n\n const manifests: Array<Manifest> = []\n for (const file of files.filter(it => /\\.ya?ml$/.test(it) && !NOT_MANIFESTS.has(path.basename(it)))) {\n const manifest = await readManifest(file)\n if (manifest != null) {\n manifests.push(manifest)\n }\n }\n\n const hashes = new Map<string, Promise<string>>()\n const sha512Of = (file: string) => {\n let hash = hashes.get(file)\n if (hash == null) {\n hash = hashFile(file)\n hashes.set(file, hash)\n }\n return hash\n }\n // the local files the Windows manifests point electron-updater at: their signer must match the embedded publisherName\n const windowsUpdateInstallers = new Set<string>()\n\n for (const manifest of manifests) {\n results.push(...verifyManifestSignature(manifest, apps, options))\n for (const { result, artifact } of await verifyManifestFiles(manifest, files, outDir, sha512Of)) {\n results.push(result)\n if (artifact != null && manifest.platform === \"win\") {\n windowsUpdateInstallers.add(artifact)\n }\n }\n }\n\n results.push(...(await verifyMacArtifacts(apps, files, outDir, config)))\n results.push(...(await verifyWindowsArtifacts(apps, files, config, options.readSigner ?? readAuthenticodeSigner, windowsUpdateInstallers)))\n return results\n}\n\n// ─── discovery ────────────────────────────────────────────────────────────────\n\n// How deep below a target folder files are collected: a further publish provider's manifest of a target with its own folder is\n// one level down (<outDir>/nsis-web/<provider>/latest.yml, see createUpdateInfoTasks)\nconst MAX_TARGET_DIR_DEPTH = 2\n\n/**\n * Collects the regular files of a target folder and of its subfolders, up to {@link MAX_TARGET_DIR_DEPTH} levels down. The output is not\n * trusted: a symlink is never followed, and a folder whose real path is not inside the output folder is not read.\n */\nasync function collectTargetFiles(dir: string, realOutDir: string, depth: number, files: Array<string>): Promise<void> {\n if (!isPathWithin(realOutDir, await realpath(dir))) {\n return\n }\n for (const child of await readdir(dir, { withFileTypes: true })) {\n if (child.name.startsWith(\".\")) {\n continue\n }\n const childPath = path.join(dir, child.name)\n // Dirent types come from lstat: a symlink is neither a file nor a directory here\n if (child.isFile()) {\n files.push(childPath)\n } else if (child.isDirectory() && depth < MAX_TARGET_DIR_DEPTH) {\n await collectTargetFiles(childPath, realOutDir, depth + 1, files)\n }\n }\n}\n\nasync function discover(outDir: string): Promise<{ apps: Array<PackagedApp>; files: Array<string> }> {\n const apps: Array<PackagedApp> = []\n const files: Array<string> = []\n const realOutDir = await realpath(outDir)\n for (const entry of await readdir(outDir, { withFileTypes: true })) {\n const entryPath = path.join(outDir, entry.name)\n if (entry.name.startsWith(\".\")) {\n continue\n }\n if (entry.isFile()) {\n files.push(entryPath)\n continue\n }\n // universal builds pack each arch into a temporary `*-temp` dir first\n if (!entry.isDirectory() || entry.name.endsWith(\"-temp\")) {\n continue\n }\n\n const macDir = MAC_APP_DIR.exec(entry.name)\n const unpackedDir = UNPACKED_APP_DIR.exec(entry.name)\n if (macDir != null) {\n const macConfigKeys = MAC_CONFIG_KEYS[macDir[1]] ?? [\"mac\"]\n const isMas = macDir[1] !== \"mac\"\n for (const child of await readdir(entryPath, { withFileTypes: true })) {\n const childPath = path.join(entryPath, child.name)\n if (child.isDirectory() && child.name.endsWith(\".app\")) {\n apps.push(await readApp(\"mac\", childPath, isMas, macConfigKeys, path.join(childPath, \"Contents\", \"Resources\", \"app-update.yml\")))\n } else if (child.isFile() && child.name.endsWith(\".pkg\")) {\n // the MAS installer is written next to the app\n files.push(childPath)\n }\n }\n } else if (unpackedDir != null) {\n const platform: PlatformKey = unpackedDir[1] === \"win\" ? \"win\" : \"linux\"\n apps.push(await readApp(platform, entryPath, false, [], path.join(entryPath, \"resources\", \"app-update.yml\")))\n } else {\n // nsis-web/, squirrel-windows*/, and the manifests of a further publish provider (<outDir>/<provider>/, <outDir>/nsis-web/<provider>/)\n await collectTargetFiles(entryPath, realOutDir, 0, files)\n }\n }\n return { apps, files }\n}\n\nasync function readApp(platform: PlatformKey, appPath: string, isMas: boolean, macConfigKeys: ReadonlyArray<MacConfigKey>, updateConfigFile: string): Promise<PackagedApp> {\n const app = { platform, path: appPath, isMas, macConfigKeys, updateConfigFile }\n const problem = (updateConfigProblem: string): PackagedApp => ({ ...app, updateConfig: null, updateConfigProblem })\n let content: string\n try {\n // The output can be downloaded artifacts, which are not trusted: app-update.yml is read only as a regular file inside the app,\n // never through a symlink to another file on this machine (whose content a YAML error would print)\n const [appRealPath, configRealPath] = await Promise.all([realpath(appPath), realpath(updateConfigFile)])\n if (!isPathWithin(appRealPath, configRealPath)) {\n return problem(\"app-update.yml is a symlink that leads out of the app\")\n }\n if (!(await stat(configRealPath)).isFile()) {\n return problem(\"app-update.yml is not a file\")\n }\n content = await readFile(configRealPath, \"utf8\")\n } catch (e: any) {\n // ENOTDIR: a \"resources\" (or \"Resources\") that is a file, so there is no app-update.yml either\n if (e.code === \"ENOENT\" || e.code === \"ENOTDIR\") {\n return { ...app, updateConfig: null, updateConfigProblem: null }\n }\n throw e\n }\n let parsed: unknown\n try {\n parsed = load(content)\n } catch (e: any) {\n // the reason only: the message of a YAML error quotes the content\n return problem(`app-update.yml is not valid YAML (${e.reason ?? \"cannot be parsed\"})`)\n }\n if (parsed == null || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n return problem(\"app-update.yml is not a YAML mapping\")\n }\n const updateConfig = parsed as Record<string, unknown>\n const publisherNames =\n updateConfig.verifyUpdateCodeSignature === false || updateConfig.publisherName == null\n ? null\n : asArray(updateConfig.publisherName).filter((it): it is string => typeof it === \"string\")\n return {\n ...app,\n updateConfig: { trustedKeys: normalizePublicKeyList(updateConfig.updateManifestPublicKey as Parameters<typeof normalizePublicKeyList>[0]), publisherNames },\n updateConfigProblem: null,\n }\n}\n\nasync function readManifest(file: string): Promise<Manifest | null> {\n const content = await readFile(file, \"utf8\")\n let info: any\n try {\n info = load(content)\n } catch {\n return null\n }\n if (info == null || typeof info !== \"object\" || typeof info.version !== \"string\" || !Array.isArray(info.files)) {\n return null\n }\n return { file, platform: updateManifestPlatform(file), content, info }\n}\n\n/** A platform-level value wins over the root one, as in the build (`PlatformPackager.updateManifestOptions`). */\nfunction platformOption(config: Configuration, platform: PlatformKey, key: string): any {\n return (config as any)[platform]?.[key] ?? (config as any)[key]\n}\n\n// ─── update manifests ─────────────────────────────────────────────────────────\n\nfunction verifyManifestSignature(manifest: Manifest, apps: Array<PackagedApp>, options: VerifyBuildOutputOptions): Array<VerificationResult> {\n const check = \"update manifest signature\"\n const result = (status: VerificationStatus, message: string): VerificationResult => ({ status, check, file: manifest.file, message })\n const updateManifest = platformOption(options.config, manifest.platform, \"updateManifest\")\n if (updateManifest === false) {\n return [result(\"skipped\", \"updateManifest is false in the configuration, so the manifest is not signed\")]\n }\n\n // Only public keys are used: verify never loads a signing (private) key, from the configuration or the environment.\n // A deliberate cutover release is signed with a key outside the trust list it embeds (updateManifest.allowSigningKeyOutsideTrustList),\n // whose public key verify does not have.\n const cutover = (reason: string): VerificationResult =>\n result(\"skipped\", `${reason}, which updateManifest.allowSigningKeyOutsideTrustList allows for a cutover release signed with a key outside the trust list`)\n\n const trustingApps: Array<{ app: PackagedApp; trustedKeys: Array<string> }> = []\n for (const app of apps) {\n if (app.platform === manifest.platform && !app.isMas && app.updateConfig != null) {\n trustingApps.push({ app, trustedKeys: app.updateConfig.trustedKeys })\n }\n }\n if (trustingApps.length === 0) {\n const keys = updateManifest?.publicKey == null ? [] : normalizePublicKeyList(updateManifest.publicKey)\n if (keys.length === 0) {\n return [\n result(\n \"unverifiable\",\n \"no packaged app embeds a trust list (app-update.yml), and updateManifest.publicKey is not set in the configuration: set it to the public keys to verify the manifest with\"\n ),\n ]\n }\n const verification = verifyUpdateManifestContent(manifest.content, keys)\n if (verification.ok) {\n return [result(\"verified\", `signed by ${verification.keyId}, a key in the configuration (no packaged app was found to read the trust list from)`)]\n }\n return [\n updateManifest?.allowSigningKeyOutsideTrustList === true\n ? cutover(`not signed by a key of updateManifest.publicKey (${verification.reason})`)\n : result(\"failed\", verification.reason),\n ]\n }\n\n return trustingApps.map(({ app, trustedKeys }) => {\n if (trustedKeys.length === 0) {\n return result(\"failed\", `${path.relative(options.outDir, app.updateConfigFile)} embeds no updateManifestPublicKey, so installs of this build accept any update manifest`)\n }\n const verification = verifyUpdateManifestContent(manifest.content, trustedKeys)\n if (verification.ok) {\n return result(\"verified\", `signed by ${verification.keyId}, which ${path.relative(options.outDir, app.updateConfigFile)} trusts`)\n }\n const reason = `not accepted by the trust list of ${path.relative(options.outDir, app.updateConfigFile)} (${verification.reason})`\n return updateManifest?.allowSigningKeyOutsideTrustList === true ? cutover(reason) : result(\"failed\", reason)\n })\n}\n\nasync function verifyManifestFiles(\n manifest: Manifest,\n files: Array<string>,\n outDir: string,\n sha512Of: (file: string) => Promise<string>\n): Promise<Array<{ result: VerificationResult; artifact: string | null }>> {\n const check = \"update manifest file\"\n // the artifacts of a target with its own folder (nsis-web/) are there, also for the manifest of a further provider (nsis-web/<provider>/)\n const parts = path.relative(outDir, manifest.file).split(path.sep)\n const targetDir = parts.length > 1 ? path.join(outDir, parts[0]) : outDir\n const dirs = new Set([path.dirname(manifest.file), targetDir, outDir])\n const candidates = files.filter(it => dirs.has(path.dirname(it)) && !/\\.(ya?ml|blockmap)$/.test(it))\n const verified: Array<{ result: VerificationResult; artifact: string | null }> = []\n for (const entry of manifest.info.files as Array<any>) {\n const name = typeof entry?.url === \"string\" ? entry.url : \"(no url)\"\n if (typeof entry?.sha512 !== \"string\") {\n verified.push({ result: { status: \"failed\", check, file: manifest.file, message: `files entry ${name} has no sha512` }, artifact: null })\n continue\n }\n // matched by hash, not by name: a GitHub manifest lists the safe artifact name, which can differ from the local file name\n let artifact: string | null = null\n for (const candidate of candidates) {\n if (typeof entry.size === \"number\" && (await stat(candidate)).size !== entry.size) {\n continue\n }\n if ((await sha512Of(candidate)) === entry.sha512) {\n artifact = candidate\n break\n }\n }\n verified.push({\n result:\n artifact == null\n ? {\n status: \"failed\",\n check,\n file: manifest.file,\n message: `no artifact matches the sha512${typeof entry.size === \"number\" ? \" and size\" : \"\"} of ${name}: it is missing, or it was changed after the manifest was written`,\n }\n : { status: \"verified\", check, file: manifest.file, message: `${name} matches ${path.relative(outDir, artifact)}` },\n artifact,\n })\n }\n return verified\n}\n\n// ─── macOS ────────────────────────────────────────────────────────────────────\n\n/**\n * The `sign` option of a macOS app, cascaded over its configuration blocks as the build does (a later block wins, and sign objects\n * are merged): whether it opts out of signing (`sign: null` or `sign.identity: null`), and its `strictVerify`.\n */\nfunction macSigning(config: Configuration, keys: ReadonlyArray<MacConfigKey>): { signingOptOut: string | null; strict: boolean | string | null | undefined } {\n let sign: unknown = undefined\n let where = \"mac.sign\"\n for (const key of keys) {\n const value: unknown = config[key]?.sign\n if (value === undefined) {\n continue\n }\n where = `${key}.sign`\n sign = isPlainSignObject(value) && isPlainSignObject(sign) ? { ...sign, ...value } : value\n }\n if (sign === null || (isPlainSignObject(sign) && sign.identity === null)) {\n return { signingOptOut: `${where} (or its identity) is null in the configuration`, strict: undefined }\n }\n const strict = isPlainSignObject(sign) ? sign.strictVerify : undefined\n return { signingOptOut: null, strict: typeof strict === \"boolean\" || typeof strict === \"string\" ? strict : undefined }\n}\n\nfunction isPlainSignObject(value: unknown): value is { readonly identity?: unknown; readonly strictVerify?: unknown } {\n return value != null && typeof value === \"object\" && !Array.isArray(value)\n}\n\nasync function verifyMacArtifacts(apps: Array<PackagedApp>, files: Array<string>, outDir: string, config: Configuration): Promise<Array<VerificationResult>> {\n const macApps = apps.filter(it => it.platform === \"mac\")\n const pkgs = files.filter(it => it.endsWith(\".pkg\"))\n const dmgs = config.dmg?.sign === true ? files.filter(it => it.endsWith(\".dmg\") && path.dirname(it) === outDir) : []\n const notarizeDisabled = config.mac?.notarize === false\n const results: Array<VerificationResult> = []\n\n const run = async (check: string, file: string, optOut: string | null, task: () => Promise<string | null>) => {\n if (optOut != null) {\n results.push({ status: \"skipped\", check, file, message: optOut })\n } else if (process.platform !== \"darwin\") {\n results.push({ status: \"unverifiable\", check, file, message: `needs Apple's tools, which run on macOS only (this host is ${process.platform})` })\n } else {\n const problem = await task()\n results.push(problem == null ? { status: \"verified\", check, file, message: \"valid\" } : { status: \"failed\", check, file, message: problem })\n }\n }\n\n const notarizeOptOut = notarizeDisabled ? \"mac.notarize is false in the configuration\" : null\n for (const app of macApps) {\n // a MAS app is signed with its mas (and masDev) configuration, which cascades over mac\n const { signingOptOut, strict } = macSigning(config, app.macConfigKeys)\n await run(\"code signature\", app.path, signingOptOut, () => verifyMacCodeSignature(app.path, { deep: true, strict }))\n if (!app.isMas) {\n await run(\"notarization ticket\", app.path, signingOptOut ?? notarizeOptOut, () => validateStapledTicket(app.path))\n }\n }\n const signingOptOut = macSigning(config, [\"mac\"]).signingOptOut\n for (const pkg of pkgs) {\n await run(\"installer signature\", pkg, null, () => checkInstallerPackageSignature(pkg))\n // the MAS installer (next to the app, in mas*/) goes to the App Store unnotarized\n if (path.dirname(pkg) === outDir) {\n await run(\"notarization ticket\", pkg, notarizeOptOut, () => validateStapledTicket(pkg))\n }\n }\n for (const dmg of dmgs) {\n await run(\"code signature\", dmg, signingOptOut, () => verifyMacCodeSignature(dmg, { deep: false }))\n }\n return results\n}\n\n// ─── Windows ──────────────────────────────────────────────────────────────────\n\nasync function verifyWindowsArtifacts(\n apps: Array<PackagedApp>,\n files: Array<string>,\n config: Configuration,\n readSigner: AuthenticodeSignerReader,\n updateInstallers: Set<string>\n): Promise<Array<VerificationResult>> {\n const check = \"Authenticode signature\"\n const appExecutables: Array<string> = []\n for (const app of apps.filter(it => it.platform === \"win\")) {\n for (const entry of await readdir(app.path, { withFileTypes: true })) {\n if (entry.isFile() && entry.name.endsWith(\".exe\")) {\n appExecutables.push(path.join(app.path, entry.name))\n }\n }\n }\n const targets = [...files.filter(it => isAuthenticodeFileType(it)), ...appExecutables]\n const publisherNameSets: Array<Array<string>> = []\n for (const app of apps) {\n const publisherNames = app.platform === \"win\" ? app.updateConfig?.publisherNames : null\n if (publisherNames != null) {\n publisherNameSets.push(publisherNames)\n }\n }\n const signingDisabled = config.win?.sign === false || config.win?.sign === null\n const results: Array<VerificationResult> = []\n\n for (const file of targets) {\n if (signingDisabled) {\n results.push({ status: \"skipped\", check, file, message: \"win.sign is false in the configuration\" })\n continue\n }\n if (!shouldSignWindowsFile(file, config.win?.signExts, true)) {\n results.push({ status: \"skipped\", check, file, message: \"excluded from signing by win.signExts\" })\n continue\n }\n\n const signer = await readSigner(file)\n if (signer.type === \"unsigned\") {\n results.push({ status: \"failed\", check, file, message: `carries no Authenticode signature (${signer.reason})` })\n continue\n }\n if (signer.type === \"unreadable\") {\n results.push({ status: \"unverifiable\", check, file, message: `the signature cannot be read on this host (${signer.reason})` })\n continue\n }\n if (signer.status === AuthenticodeSignatureStatus.HashMismatch) {\n results.push({ status: \"failed\", check, file, message: \"the signature does not match the file (HashMismatch: it was modified after signing)\" })\n continue\n }\n results.push(\n signer.status == null\n ? { status: \"unverifiable\", check, file, message: `signed by ${signer.subject}, but the signature hash can only be validated on Windows` }\n : { status: \"verified\", check, file, message: `signed by ${signer.subject} (${authenticodeSignatureStatusName(signer.status)})` }\n )\n\n if (updateInstallers.has(file)) {\n // matchPublisherName takes the parsed Get-AuthenticodeSignature output, as electron-updater passes it\n const signature = { SignerCertificate: { Subject: signer.subject } }\n for (const publisherNames of publisherNameSets) {\n results.push(\n matchPublisherName(signature, publisherNames)\n ? { status: \"verified\", check: \"update publisher\", file, message: `the signer matches publisherName ${publisherNames.join(\" | \")}` }\n : {\n status: \"failed\",\n check: \"update publisher\",\n file,\n message: `the signer ${signer.subject} does not match publisherName ${publisherNames.join(\" | \")} in app-update.yml, so electron-updater would reject this update`,\n }\n )\n }\n }\n }\n return results\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { InvalidConfigurationError, log } from "builder-util";
2
2
  import { DEFAULT_KEYWORD, resolveDefaultKeywordList } from "builder-util/internal";
3
- import { ALL_PLATFORM_KEYS, BREAKING_CHANGES_URL, FILE_OPTION_KEYS, FILE_OPTIONS_ANCHOR } from "./legacyOptions.js";
4
- const FILE_OPTIONS_URL = `${BREAKING_CHANGES_URL}#${FILE_OPTIONS_ANCHOR}`;
3
+ import { ALL_PLATFORM_KEYS, CONFIG_CHANGES_URL, FILE_OPTION_KEYS, FILE_OPTIONS_ANCHOR } from "./legacyOptions.js";
4
+ const FILE_OPTIONS_URL = `${CONFIG_CHANGES_URL}#${FILE_OPTIONS_ANCHOR}`;
5
5
  export function isPlainObject(value) {
6
6
  return value != null && typeof value === "object" && !Array.isArray(value);
7
7
  }