app-builder-lib 27.0.0-alpha.11 → 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 (254) 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 +83 -0
  20. package/dist/codeSign/win/authenticodeSignature.d.ts.map +1 -0
  21. package/dist/codeSign/win/authenticodeSignature.js +289 -0
  22. package/dist/codeSign/win/authenticodeSignature.js.map +1 -0
  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 +27 -9
  31. package/dist/codeSign/win/signtoolBaseSignManager.d.ts.map +1 -1
  32. package/dist/codeSign/win/signtoolBaseSignManager.js +80 -49
  33. package/dist/codeSign/win/signtoolBaseSignManager.js.map +1 -1
  34. package/dist/codeSign/win/verifyUpdatePublisher.d.ts +25 -0
  35. package/dist/codeSign/win/verifyUpdatePublisher.d.ts.map +1 -0
  36. package/dist/codeSign/win/verifyUpdatePublisher.js +101 -0
  37. package/dist/codeSign/win/verifyUpdatePublisher.js.map +1 -0
  38. package/dist/codeSign/win/windowsSignAzureManager.d.ts +1 -1
  39. package/dist/codeSign/win/windowsSignAzureManager.d.ts.map +1 -1
  40. package/dist/codeSign/win/windowsSignAzureManager.js +24 -6
  41. package/dist/codeSign/win/windowsSignAzureManager.js.map +1 -1
  42. package/dist/configuration.d.ts +56 -12
  43. package/dist/configuration.d.ts.map +1 -1
  44. package/dist/configuration.js.map +1 -1
  45. package/dist/electron/ElectronFramework.d.ts +15 -0
  46. package/dist/electron/ElectronFramework.d.ts.map +1 -1
  47. package/dist/electron/ElectronFramework.js +33 -2
  48. package/dist/electron/ElectronFramework.js.map +1 -1
  49. package/dist/electron/mac/asarIntegrityDigest.d.ts +10 -0
  50. package/dist/electron/mac/asarIntegrityDigest.d.ts.map +1 -0
  51. package/dist/electron/mac/asarIntegrityDigest.js +122 -0
  52. package/dist/electron/mac/asarIntegrityDigest.js.map +1 -0
  53. package/dist/electron/mac/electronMac.js +1 -28
  54. package/dist/electron/mac/electronMac.js.map +1 -1
  55. package/dist/electron/mac/electronMacUtils.d.ts +9 -0
  56. package/dist/electron/mac/electronMacUtils.d.ts.map +1 -1
  57. package/dist/electron/mac/electronMacUtils.js +37 -0
  58. package/dist/electron/mac/electronMacUtils.js.map +1 -1
  59. package/dist/fileMatcher.d.ts +34 -11
  60. package/dist/fileMatcher.d.ts.map +1 -1
  61. package/dist/fileMatcher.js +125 -36
  62. package/dist/fileMatcher.js.map +1 -1
  63. package/dist/forge-maker.d.ts +64 -0
  64. package/dist/forge-maker.d.ts.map +1 -1
  65. package/dist/forge-maker.js +104 -2
  66. package/dist/forge-maker.js.map +1 -1
  67. package/dist/index.d.ts +2 -2
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +5 -4
  70. package/dist/index.js.map +1 -1
  71. package/dist/indexInternal.d.ts +9 -3
  72. package/dist/indexInternal.d.ts.map +1 -1
  73. package/dist/indexInternal.js +8 -3
  74. package/dist/indexInternal.js.map +1 -1
  75. package/dist/linuxPackager.js +1 -1
  76. package/dist/linuxPackager.js.map +1 -1
  77. package/dist/macPackager.d.ts +32 -0
  78. package/dist/macPackager.d.ts.map +1 -1
  79. package/dist/macPackager.js +215 -13
  80. package/dist/macPackager.js.map +1 -1
  81. package/dist/options/FuseOptionsV1.d.ts +4 -0
  82. package/dist/options/FuseOptionsV1.d.ts.map +1 -1
  83. package/dist/options/FuseOptionsV1.js.map +1 -1
  84. package/dist/options/PlatformSpecificBuildOptions.d.ts +93 -21
  85. package/dist/options/PlatformSpecificBuildOptions.d.ts.map +1 -1
  86. package/dist/options/PlatformSpecificBuildOptions.js.map +1 -1
  87. package/dist/options/SquirrelWindowsOptions.d.ts +3 -0
  88. package/dist/options/SquirrelWindowsOptions.d.ts.map +1 -1
  89. package/dist/options/SquirrelWindowsOptions.js.map +1 -1
  90. package/dist/options/macOptions.d.ts +22 -3
  91. package/dist/options/macOptions.d.ts.map +1 -1
  92. package/dist/options/macOptions.js.map +1 -1
  93. package/dist/options/winOptions.d.ts +68 -19
  94. package/dist/options/winOptions.d.ts.map +1 -1
  95. package/dist/options/winOptions.js +20 -0
  96. package/dist/options/winOptions.js.map +1 -1
  97. package/dist/packager.d.ts +3 -0
  98. package/dist/packager.d.ts.map +1 -1
  99. package/dist/packager.js +11 -2
  100. package/dist/packager.js.map +1 -1
  101. package/dist/platformPackager.d.ts +18 -7
  102. package/dist/platformPackager.d.ts.map +1 -1
  103. package/dist/platformPackager.js +56 -15
  104. package/dist/platformPackager.js.map +1 -1
  105. package/dist/publish/PublishManager.d.ts +4 -0
  106. package/dist/publish/PublishManager.d.ts.map +1 -1
  107. package/dist/publish/PublishManager.js +106 -28
  108. package/dist/publish/PublishManager.js.map +1 -1
  109. package/dist/publish/manifestUploadCheck.d.ts +10 -0
  110. package/dist/publish/manifestUploadCheck.d.ts.map +1 -0
  111. package/dist/publish/manifestUploadCheck.js +75 -0
  112. package/dist/publish/manifestUploadCheck.js.map +1 -0
  113. package/dist/publish/updateInfoBuilder.d.ts.map +1 -1
  114. package/dist/publish/updateInfoBuilder.js +51 -17
  115. package/dist/publish/updateInfoBuilder.js.map +1 -1
  116. package/dist/publish/updateManifestVerifier.d.ts +22 -0
  117. package/dist/publish/updateManifestVerifier.d.ts.map +1 -0
  118. package/dist/publish/updateManifestVerifier.js +65 -0
  119. package/dist/publish/updateManifestVerifier.js.map +1 -0
  120. package/dist/targets/ArchiveTarget.d.ts.map +1 -1
  121. package/dist/targets/ArchiveTarget.js +6 -2
  122. package/dist/targets/ArchiveTarget.js.map +1 -1
  123. package/dist/targets/archive.d.ts +6 -0
  124. package/dist/targets/archive.d.ts.map +1 -1
  125. package/dist/targets/archive.js +15 -5
  126. package/dist/targets/archive.js.map +1 -1
  127. package/dist/targets/differentialUpdateInfoBuilder.d.ts.map +1 -1
  128. package/dist/targets/differentialUpdateInfoBuilder.js +4 -0
  129. package/dist/targets/differentialUpdateInfoBuilder.js.map +1 -1
  130. package/dist/targets/linux/FlatpakTarget.js +5 -5
  131. package/dist/targets/linux/FlatpakTarget.js.map +1 -1
  132. package/dist/targets/linux/FpmTarget.d.ts.map +1 -1
  133. package/dist/targets/linux/FpmTarget.js +12 -17
  134. package/dist/targets/linux/FpmTarget.js.map +1 -1
  135. package/dist/targets/linux/LinuxTargetHelper.js +1 -1
  136. package/dist/targets/linux/LinuxTargetHelper.js.map +1 -1
  137. package/dist/targets/linux/appimage/AppImageTarget.d.ts.map +1 -1
  138. package/dist/targets/linux/appimage/AppImageTarget.js +6 -1
  139. package/dist/targets/linux/appimage/AppImageTarget.js.map +1 -1
  140. package/dist/targets/linux/appimage/appImageUtil.js +9 -9
  141. package/dist/targets/linux/appimage/appImageUtil.js.map +1 -1
  142. package/dist/targets/linux/flatpakBundle.d.ts.map +1 -1
  143. package/dist/targets/linux/flatpakBundle.js +25 -20
  144. package/dist/targets/linux/flatpakBundle.js.map +1 -1
  145. package/dist/targets/linux/snap/core24.d.ts.map +1 -1
  146. package/dist/targets/linux/snap/core24.js +2 -9
  147. package/dist/targets/linux/snap/core24.js.map +1 -1
  148. package/dist/targets/linux/snap/coreLegacy.d.ts.map +1 -1
  149. package/dist/targets/linux/snap/coreLegacy.js +22 -6
  150. package/dist/targets/linux/snap/coreLegacy.js.map +1 -1
  151. package/dist/targets/linux/snap/snapPlugs.d.ts +2 -2
  152. package/dist/targets/linux/snap/snapPlugs.d.ts.map +1 -1
  153. package/dist/targets/linux/snap/snapPlugs.js +1 -1
  154. package/dist/targets/linux/snap/snapPlugs.js.map +1 -1
  155. package/dist/targets/linux/snap/snapcraftBuilder.d.ts.map +1 -1
  156. package/dist/targets/linux/snap/snapcraftBuilder.js +19 -17
  157. package/dist/targets/linux/snap/snapcraftBuilder.js.map +1 -1
  158. package/dist/targets/mac/MacTargetHelper.d.ts +21 -3
  159. package/dist/targets/mac/MacTargetHelper.d.ts.map +1 -1
  160. package/dist/targets/mac/MacTargetHelper.js +140 -13
  161. package/dist/targets/mac/MacTargetHelper.js.map +1 -1
  162. package/dist/targets/mac/pkg.d.ts.map +1 -1
  163. package/dist/targets/mac/pkg.js +8 -5
  164. package/dist/targets/mac/pkg.js.map +1 -1
  165. package/dist/targets/win/nsis/NsisTarget.d.ts.map +1 -1
  166. package/dist/targets/win/nsis/NsisTarget.js +15 -3
  167. package/dist/targets/win/nsis/NsisTarget.js.map +1 -1
  168. package/dist/targets/win/nsis/nsisOptions.d.ts +1 -1
  169. package/dist/targets/win/nsis/nsisOptions.js.map +1 -1
  170. package/dist/toolsets/nsis.js +1 -1
  171. package/dist/toolsets/nsis.js.map +1 -1
  172. package/dist/toolsets/winCodeSign.d.ts +14 -1
  173. package/dist/toolsets/winCodeSign.d.ts.map +1 -1
  174. package/dist/toolsets/winCodeSign.js +14 -1
  175. package/dist/toolsets/winCodeSign.js.map +1 -1
  176. package/dist/toolsets/wine.d.ts +3 -0
  177. package/dist/toolsets/wine.d.ts.map +1 -1
  178. package/dist/toolsets/wine.js +14 -5
  179. package/dist/toolsets/wine.js.map +1 -1
  180. package/dist/util/appFileCopier.d.ts.map +1 -1
  181. package/dist/util/appFileCopier.js +15 -11
  182. package/dist/util/appFileCopier.js.map +1 -1
  183. package/dist/util/buildOutputVerifier.d.ts +40 -0
  184. package/dist/util/buildOutputVerifier.d.ts.map +1 -0
  185. package/dist/util/buildOutputVerifier.js +420 -0
  186. package/dist/util/buildOutputVerifier.js.map +1 -0
  187. package/dist/util/config/config.d.ts.map +1 -1
  188. package/dist/util/config/config.js +9 -1
  189. package/dist/util/config/config.js.map +1 -1
  190. package/dist/util/config/fileOptions.d.ts +22 -0
  191. package/dist/util/config/fileOptions.d.ts.map +1 -1
  192. package/dist/util/config/fileOptions.js +92 -2
  193. package/dist/util/config/fileOptions.js.map +1 -1
  194. package/dist/util/config/legacyConfigGuard.d.ts.map +1 -1
  195. package/dist/util/config/legacyConfigGuard.js +2 -2
  196. package/dist/util/config/legacyConfigGuard.js.map +1 -1
  197. package/dist/util/config/legacyOptions.d.ts +9 -2
  198. package/dist/util/config/legacyOptions.d.ts.map +1 -1
  199. package/dist/util/config/legacyOptions.js +20 -2
  200. package/dist/util/config/legacyOptions.js.map +1 -1
  201. package/dist/util/electronGet.d.ts.map +1 -1
  202. package/dist/util/electronGet.js +3 -1
  203. package/dist/util/electronGet.js.map +1 -1
  204. package/dist/util/flags.d.ts.map +1 -1
  205. package/dist/util/flags.js +3 -9
  206. package/dist/util/flags.js.map +1 -1
  207. package/dist/util/mac/macosIconComposer.d.ts.map +1 -1
  208. package/dist/util/mac/macosIconComposer.js +6 -5
  209. package/dist/util/mac/macosIconComposer.js.map +1 -1
  210. package/dist/util/macroExpander.js +1 -1
  211. package/dist/util/macroExpander.js.map +1 -1
  212. package/dist/util/nativeBinaryVerifier.d.ts.map +1 -1
  213. package/dist/util/nativeBinaryVerifier.js +3 -1
  214. package/dist/util/nativeBinaryVerifier.js.map +1 -1
  215. package/dist/util/packageMetadata.js +1 -1
  216. package/dist/util/packageMetadata.js.map +1 -1
  217. package/dist/util/removedEnvVars.d.ts +2 -0
  218. package/dist/util/removedEnvVars.d.ts.map +1 -1
  219. package/dist/util/removedEnvVars.js +15 -1
  220. package/dist/util/removedEnvVars.js.map +1 -1
  221. package/dist/util/streamSpawnToFile.d.ts +3 -1
  222. package/dist/util/streamSpawnToFile.d.ts.map +1 -1
  223. package/dist/util/streamSpawnToFile.js +6 -2
  224. package/dist/util/streamSpawnToFile.js.map +1 -1
  225. package/dist/version.d.ts +1 -1
  226. package/dist/version.js +1 -1
  227. package/dist/version.js.map +1 -1
  228. package/dist/vm/ParallelsVm.d.ts +10 -0
  229. package/dist/vm/ParallelsVm.d.ts.map +1 -1
  230. package/dist/vm/ParallelsVm.js +22 -8
  231. package/dist/vm/ParallelsVm.js.map +1 -1
  232. package/dist/vm/PwshVm.d.ts +0 -1
  233. package/dist/vm/PwshVm.d.ts.map +1 -1
  234. package/dist/vm/PwshVm.js +10 -15
  235. package/dist/vm/PwshVm.js.map +1 -1
  236. package/dist/vm/WineVm.d.ts.map +1 -1
  237. package/dist/vm/WineVm.js +4 -4
  238. package/dist/vm/WineVm.js.map +1 -1
  239. package/dist/vm/vm.d.ts +9 -3
  240. package/dist/vm/vm.d.ts.map +1 -1
  241. package/dist/vm/vm.js +40 -32
  242. package/dist/vm/vm.js.map +1 -1
  243. package/dist/winPackager.d.ts +16 -1
  244. package/dist/winPackager.d.ts.map +1 -1
  245. package/dist/winPackager.js +77 -19
  246. package/dist/winPackager.js.map +1 -1
  247. package/package.json +12 -10
  248. package/scheme.json +662 -50
  249. package/templates/nsis/include/allowOnlyOneInstallerInstance.nsh +14 -9
  250. package/templates/nsis/installSection.nsh +5 -0
  251. package/dist/vm/MonoVm.d.ts +0 -9
  252. package/dist/vm/MonoVm.d.ts.map +0 -1
  253. package/dist/vm/MonoVm.js +0 -16
  254. package/dist/vm/MonoVm.js.map +0 -1
@@ -0,0 +1,289 @@
1
+ import * as asn1js from "asn1js";
2
+ import { Executables, stripSensitiveEnvVars } from "builder-util";
3
+ import { parseAuthenticodeSignatureOutput, prepareAuthenticodeSignatureExec } from "builder-util-runtime";
4
+ import { execFile } from "child_process";
5
+ import { open } from "fs/promises";
6
+ import * as path from "path";
7
+ import * as pkijs from "pkijs";
8
+ /**
9
+ * Values of `System.Management.Automation.SignatureStatus`. `ConvertTo-Json` serializes the enum as its numeric
10
+ * value, which is the representation {@link AuthenticodeSignerInfo} carries.
11
+ */
12
+ export const AuthenticodeSignatureStatus = {
13
+ Valid: 0,
14
+ UnknownError: 1,
15
+ NotSigned: 2,
16
+ HashMismatch: 3,
17
+ NotTrusted: 4,
18
+ NotSupportedFileFormat: 5,
19
+ Incompatible: 6,
20
+ };
21
+ /** Returns the `SignatureStatus` name of a numeric status (e.g. `HashMismatch` for 3), or the number itself when unknown. */
22
+ export function authenticodeSignatureStatusName(status) {
23
+ if (status == null) {
24
+ return "unknown";
25
+ }
26
+ for (const [name, value] of Object.entries(AuthenticodeSignatureStatus)) {
27
+ if (value === status) {
28
+ return name;
29
+ }
30
+ }
31
+ return String(status);
32
+ }
33
+ /**
34
+ * Reads the signer of a Windows executable's embedded Authenticode signature: on Windows with
35
+ * `Get-AuthenticodeSignature`, the very API electron-updater verifies downloaded updates with; elsewhere by parsing
36
+ * the PE certificate table and its PKCS#7 signature directly (no external tool needed).
37
+ */
38
+ export function readAuthenticodeSigner(file) {
39
+ return process.platform === "win32" ? readAuthenticodeSignerWithPowerShell(file) : readEmbeddedAuthenticodeSigner(file);
40
+ }
41
+ /** File types electron-builder Authenticode-signs and can read the signature of back: PE files, MSI and AppX/MSIX packages. */
42
+ const AUTHENTICODE_FILE_EXTENSIONS = new Set([".exe", ".dll", ".node", ".msi", ".appx", ".appxbundle", ".msix", ".msixbundle"]);
43
+ /** Whether `file` is a type whose Authenticode signature can be read back (see `AUTHENTICODE_FILE_EXTENSIONS`). */
44
+ export function isAuthenticodeFileType(file) {
45
+ return AUTHENTICODE_FILE_EXTENSIONS.has(path.extname(file).toLowerCase());
46
+ }
47
+ /**
48
+ * Why a signature read back with {@link readAuthenticodeSigner} does not count as valid, or `null` when it does. Any
49
+ * status but `HashMismatch` is accepted: the build host may not trust the signing chain that the users' machines
50
+ * trust, and the reader used off Windows reports no status at all.
51
+ */
52
+ export function authenticodeSignatureProblem(signer) {
53
+ switch (signer.type) {
54
+ case "unsigned":
55
+ return `carries no Authenticode signature (${signer.reason})`;
56
+ case "unreadable":
57
+ return `has an Authenticode signature that cannot be read (${signer.reason})`;
58
+ case "signed":
59
+ return signer.status === AuthenticodeSignatureStatus.HashMismatch ? "has an invalid Authenticode signature (HashMismatch: the file was modified after signing)" : null;
60
+ }
61
+ }
62
+ // ─── Windows: Get-AuthenticodeSignature ──────────────────────────────────────
63
+ /**
64
+ * Reads the signer with `Get-AuthenticodeSignature`, with the helpers electron-updater verifies downloaded updates
65
+ * with (builder-util-runtime: the same PowerShell invocation and JSON parsing), so the build sees exactly what the
66
+ * updater will see. Windows PowerShell is started from `toolsets.executables.powershell` or its default location, with
67
+ * the build's credential variables (signing passwords, tokens, keys) removed from its environment: reading a signature
68
+ * needs none of them.
69
+ */
70
+ export function readAuthenticodeSignerWithPowerShell(file) {
71
+ return new Promise(resolve => {
72
+ try {
73
+ // a busy build machine may still be preparing the PowerShell modules on first use, and a timeout here fails the build
74
+ // like every PowerShell the build starts: from toolsets.executables, or its default location when that has none
75
+ const [powershell, args, options] = prepareAuthenticodeSignatureExec(file, 60 * 1000, Executables.resolve("powershell"));
76
+ execFile(powershell, args, { ...options, env: withoutInheritedCredentials(options.env ?? {}) }, (error, stdout, stderr) => {
77
+ if (error != null) {
78
+ const stderrText = String(stderr ?? "").trim();
79
+ // the message of a non-zero exit is "Command failed: <the whole command line, the encoded script included>\n<stderr>"
80
+ const failure = error.killed ? "did not finish within 60s" : typeof error.code === "number" ? `exited with code ${error.code}` : error.message;
81
+ resolve({ type: "unreadable", reason: `Get-AuthenticodeSignature failed: ${failure}${stderrText.length > 0 ? `\n${stderrText}` : ""}` });
82
+ return;
83
+ }
84
+ let data;
85
+ try {
86
+ data = parseAuthenticodeSignatureOutput(stdout);
87
+ }
88
+ catch (e) {
89
+ const stderrText = String(stderr ?? "").trim();
90
+ resolve({ type: "unreadable", reason: `cannot parse Get-AuthenticodeSignature output (${e.message}): ${stdout}${stderrText.length > 0 ? `\n${stderrText}` : ""}` });
91
+ return;
92
+ }
93
+ const status = getProperty(data, "Status");
94
+ const numericStatus = typeof status === "number" ? status : null;
95
+ const subject = getProperty(getProperty(data, "SignerCertificate"), "Subject");
96
+ if (typeof subject !== "string") {
97
+ resolve({ type: "unsigned", reason: `Get-AuthenticodeSignature reports no signer certificate (status: ${authenticodeSignatureStatusName(numericStatus)})` });
98
+ return;
99
+ }
100
+ resolve({ type: "signed", subject, status: numericStatus });
101
+ });
102
+ }
103
+ catch (e) {
104
+ // PowerShell cannot be located (no executable at its toolsets.executables locations, or no default location) or started at all
105
+ resolve({ type: "unreadable", reason: `Get-AuthenticodeSignature failed: ${e.message}` });
106
+ }
107
+ });
108
+ }
109
+ /**
110
+ * `env` without the credential variables it inherited from the build (see `stripSensitiveEnvVars`). The variables the command
111
+ * sets itself, such as the file to read, are kept: they are the ones whose value is not the inherited one.
112
+ */
113
+ function withoutInheritedCredentials(env) {
114
+ const result = stripSensitiveEnvVars(env);
115
+ for (const [key, value] of Object.entries(env)) {
116
+ if (process.env[key] !== value) {
117
+ result[key] = value;
118
+ }
119
+ }
120
+ return result;
121
+ }
122
+ function getProperty(value, name) {
123
+ return value != null && typeof value === "object" && name in value ? Reflect.get(value, name) : undefined;
124
+ }
125
+ // ─── Windows subject format ─────────────────────────────────────────────────
126
+ // Maps certificate attribute OIDs to the X.500 names Windows uses when it formats a certificate subject
127
+ // (CertNameToStr with CERT_X500_NAME_STR, i.e. `X509Certificate2.Subject` as Get-AuthenticodeSignature reports it).
128
+ // Other OIDs are written as `OID.<dotted oid>`, as Windows does (e.g. `OID.2.5.4.15` in EV certificates).
129
+ const WINDOWS_ATTRIBUTE_TYPE_NAMES = {
130
+ "2.5.4.3": "CN",
131
+ "2.5.4.4": "SN",
132
+ "2.5.4.5": "SERIALNUMBER",
133
+ "2.5.4.6": "C",
134
+ "2.5.4.7": "L",
135
+ "2.5.4.8": "S",
136
+ "2.5.4.9": "STREET",
137
+ "2.5.4.10": "O",
138
+ "2.5.4.11": "OU",
139
+ "2.5.4.12": "T",
140
+ "2.5.4.13": "Description",
141
+ "2.5.4.17": "PostalCode",
142
+ "2.5.4.18": "POBox",
143
+ "2.5.4.20": "Phone",
144
+ "2.5.4.24": "X21Address",
145
+ "2.5.4.42": "G",
146
+ "2.5.4.43": "I",
147
+ "2.5.4.46": "dnQualifier",
148
+ "1.2.840.113549.1.9.1": "E",
149
+ "0.9.2342.19200300.100.1.25": "DC",
150
+ };
151
+ // Windows quotes an RDN value that has leading/trailing white space or contains one of these characters,
152
+ // doubling embedded quotes.
153
+ const NEEDS_WINDOWS_DN_QUOTING = /[,+="\n<>#;]/;
154
+ /** Quotes an RDN value the way Windows does when it formats a certificate subject (see {@link formatWindowsSubjectDn}). */
155
+ export function quoteWindowsDnValue(value) {
156
+ if (value.length === 0 || value !== value.trim() || NEEDS_WINDOWS_DN_QUOTING.test(value)) {
157
+ return `"${value.replace(/"/g, '""')}"`;
158
+ }
159
+ return value;
160
+ }
161
+ /**
162
+ * Formats a certificate name the way Windows reports a certificate subject (`X509Certificate2.Subject`, which
163
+ * electron-updater compares the configured publisher names against): RDNs in reverse encoding order separated by
164
+ * `, `, with the Windows X.500 attribute names (e.g. `S` for the state, not `ST`).
165
+ */
166
+ export function formatWindowsSubjectDn(name) {
167
+ return name.typesAndValues
168
+ .map(attribute => {
169
+ const typeName = WINDOWS_ATTRIBUTE_TYPE_NAMES[attribute.type] ?? `OID.${attribute.type}`;
170
+ return `${typeName}=${quoteWindowsDnValue(String(attribute.value.valueBlock.value))}`;
171
+ })
172
+ .reverse()
173
+ .join(", ");
174
+ }
175
+ // ─── Any host: PE certificate table + PKCS#7 ────────────────────────────────
176
+ const WIN_CERT_TYPE_PKCS_SIGNED_DATA = 0x0002;
177
+ // The certificate table of a signed installer is a few KB; anything this large is not a real signature.
178
+ const MAX_CERTIFICATE_TABLE_SIZE = 16 * 1024 * 1024;
179
+ async function readExactly(handle, position, length) {
180
+ const buffer = Buffer.alloc(length);
181
+ const { bytesRead } = await handle.read(buffer, 0, length, position);
182
+ if (bytesRead !== length) {
183
+ throw new Error(`unexpected end of file reading ${length} bytes at offset ${position}`);
184
+ }
185
+ return buffer;
186
+ }
187
+ /**
188
+ * Returns the first `WIN_CERTIFICATE` entry of a PE file's certificate table (the primary Authenticode signature,
189
+ * which is the one Windows reports), or null when the file has no certificate table. Only the headers and the table
190
+ * itself are read, never the whole (possibly huge) installer.
191
+ */
192
+ export async function readPeSignatureBlob(file) {
193
+ const handle = await open(file, "r");
194
+ try {
195
+ const { size: fileSize } = await handle.stat();
196
+ const dosHeader = await readExactly(handle, 0, 64);
197
+ if (dosHeader.toString("latin1", 0, 2) !== "MZ") {
198
+ throw new Error("not a PE file (no MZ header)");
199
+ }
200
+ const peHeaderOffset = dosHeader.readUInt32LE(0x3c);
201
+ // PE signature (4) + COFF file header (20)
202
+ const peHeader = await readExactly(handle, peHeaderOffset, 24);
203
+ if (peHeader.toString("latin1", 0, 4) !== "PE\0\0") {
204
+ throw new Error("not a PE file (no PE signature)");
205
+ }
206
+ const optionalHeaderSize = peHeader.readUInt16LE(20);
207
+ const optionalHeader = await readExactly(handle, peHeaderOffset + 24, optionalHeaderSize);
208
+ const magic = optionalHeader.readUInt16LE(0);
209
+ // PE32 / PE32+: offset of NumberOfRvaAndSizes; the data directories follow it
210
+ const rvaCountOffset = magic === 0x10b ? 92 : magic === 0x20b ? 108 : -1;
211
+ if (rvaCountOffset === -1) {
212
+ throw new Error(`unknown optional header magic 0x${magic.toString(16)}`);
213
+ }
214
+ // the certificate table is data directory #4; each entry is VirtualAddress (u32) + Size (u32)
215
+ const securityDirectoryOffset = rvaCountOffset + 4 + 4 * 8;
216
+ if (optionalHeader.length < securityDirectoryOffset + 8 || optionalHeader.readUInt32LE(rvaCountOffset) <= 4) {
217
+ return null;
218
+ }
219
+ // for the certificate table, VirtualAddress is a file offset
220
+ const tableOffset = optionalHeader.readUInt32LE(securityDirectoryOffset);
221
+ const tableSize = optionalHeader.readUInt32LE(securityDirectoryOffset + 4);
222
+ if (tableOffset === 0 || tableSize === 0) {
223
+ return null;
224
+ }
225
+ if (tableSize < 8 || tableSize > MAX_CERTIFICATE_TABLE_SIZE || tableOffset + tableSize > fileSize) {
226
+ throw new Error(`invalid certificate table (offset ${tableOffset}, size ${tableSize}, file size ${fileSize})`);
227
+ }
228
+ const table = await readExactly(handle, tableOffset, tableSize);
229
+ // WIN_CERTIFICATE: dwLength (u32, includes this 8-byte header), wRevision (u16), wCertificateType (u16), bCertificate
230
+ const entryLength = table.readUInt32LE(0);
231
+ if (entryLength < 8 || entryLength > tableSize) {
232
+ throw new Error(`invalid WIN_CERTIFICATE length ${entryLength}`);
233
+ }
234
+ return { certificateType: table.readUInt16LE(6), data: table.subarray(8, entryLength) };
235
+ }
236
+ finally {
237
+ await handle.close();
238
+ }
239
+ }
240
+ function toArrayBuffer(buffer) {
241
+ const result = new ArrayBuffer(buffer.byteLength);
242
+ new Uint8Array(result).set(buffer);
243
+ return result;
244
+ }
245
+ /**
246
+ * Returns the subject of the certificate that made the first signer's signature in a DER-encoded PKCS#7 SignedData
247
+ * (`ContentInfo`), formatted the way Windows reports it.
248
+ */
249
+ export function readPkcs7SignerSubject(der) {
250
+ const asn1 = asn1js.fromBER(toArrayBuffer(der));
251
+ if (asn1.offset === -1) {
252
+ throw new Error("invalid PKCS#7 encoding");
253
+ }
254
+ const contentInfo = new pkijs.ContentInfo({ schema: asn1.result });
255
+ if (contentInfo.contentType !== pkijs.id_ContentType_SignedData) {
256
+ throw new Error(`unexpected PKCS#7 content type ${contentInfo.contentType}`);
257
+ }
258
+ const signedData = new pkijs.SignedData({ schema: contentInfo.content });
259
+ const signerInfo = signedData.signerInfos[0];
260
+ if (signerInfo == null) {
261
+ throw new Error("PKCS#7 signature has no signer");
262
+ }
263
+ const sid = signerInfo.sid;
264
+ if (!(sid instanceof pkijs.IssuerAndSerialNumber)) {
265
+ throw new Error("PKCS#7 signer is not identified by issuer and serial number");
266
+ }
267
+ const certificate = (signedData.certificates ?? []).find((it) => it instanceof pkijs.Certificate && it.issuer.isEqual(sid.issuer) && it.serialNumber.isEqual(sid.serialNumber));
268
+ if (certificate == null) {
269
+ throw new Error("the signer certificate is not embedded in the PKCS#7 signature");
270
+ }
271
+ return formatWindowsSubjectDn(certificate.subject);
272
+ }
273
+ /** Reads the embedded Authenticode signer of a PE file without external tools (works on any host). */
274
+ export async function readEmbeddedAuthenticodeSigner(file) {
275
+ try {
276
+ const blob = await readPeSignatureBlob(file);
277
+ if (blob == null) {
278
+ return { type: "unsigned", reason: "the file has no embedded Authenticode signature (empty PE certificate table)" };
279
+ }
280
+ if (blob.certificateType !== WIN_CERT_TYPE_PKCS_SIGNED_DATA) {
281
+ return { type: "unreadable", reason: `unsupported WIN_CERTIFICATE type 0x${blob.certificateType.toString(16)}` };
282
+ }
283
+ return { type: "signed", subject: readPkcs7SignerSubject(blob.data), status: null };
284
+ }
285
+ catch (e) {
286
+ return { type: "unreadable", reason: e.message || String(e) };
287
+ }
288
+ }
289
+ //# sourceMappingURL=authenticodeSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticodeSignature.js","sourceRo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,KAAK,CAAC,gEAAgE,CAAC,CAAA;IACnF,CAAC;IACD,OAAO,sBAAsB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AACpD,CAAC;AAED,sGAAsG;AACtG,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAC,IAAY;IAC/D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,8EAA8E,EAAE,CAAA;QACrH,CAAC;QACD,IAAI,IAAI,CAAC,eAAe,KAAK,8BAA8B,EAAE,CAAC;YAC5D,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,sCAAsC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,CAAA;QAClH,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;IACrF,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/D,CAAC;AACH,CAAC","sourcesContent":["import * as asn1js from \"asn1js\"\nimport { Executables, stripSensitiveEnvVars } from \"builder-util\"\nimport { parseAuthenticodeSignatureOutput, prepareAuthenticodeSignatureExec } from \"builder-util-runtime\"\nimport { execFile } from \"child_process\"\nimport { open } from \"fs/promises\"\nimport * as path from \"path\"\nimport * as pkijs from \"pkijs\"\n\n/**\n * Values of `System.Management.Automation.SignatureStatus`. `ConvertTo-Json` serializes the enum as its numeric\n * value, which is the representation {@link AuthenticodeSignerInfo} carries.\n */\nexport const AuthenticodeSignatureStatus = {\n Valid: 0,\n UnknownError: 1,\n NotSigned: 2,\n HashMismatch: 3,\n NotTrusted: 4,\n NotSupportedFileFormat: 5,\n Incompatible: 6,\n} as const\n\n/** Returns the `SignatureStatus` name of a numeric status (e.g. `HashMismatch` for 3), or the number itself when unknown. */\nexport function authenticodeSignatureStatusName(status: number | null): string {\n if (status == null) {\n return \"unknown\"\n }\n for (const [name, value] of Object.entries(AuthenticodeSignatureStatus)) {\n if (value === status) {\n return name\n }\n }\n return String(status)\n}\n\n/**\n * The embedded Authenticode signature of a Windows executable, as far as the update signature check needs it:\n * - `signed` — the subject of the certificate that made the (primary) signature, in the format Windows reports it\n * (`X509Certificate2.Subject`), plus the numeric `SignatureStatus` (see {@link AuthenticodeSignatureStatus}) when\n * the host can verify it (Windows only)\n * - `unsigned` — the file has no embedded signature\n * - `unreadable` — the signature could not be read (`reason` says why)\n */\nexport type AuthenticodeSignerInfo =\n | { readonly type: \"signed\"; readonly subject: string; readonly status: number | null }\n | { readonly type: \"unsigned\"; readonly reason: string }\n | { readonly type: \"unreadable\"; readonly reason: string }\n\nexport type AuthenticodeSignerReader = (file: string) => Promise<AuthenticodeSignerInfo>\n\n/**\n * Reads the signer of a Windows executable's embedded Authenticode signature: on Windows with\n * `Get-AuthenticodeSignature`, the very API electron-updater verifies downloaded updates with; elsewhere by parsing\n * the PE certificate table and its PKCS#7 signature directly (no external tool needed).\n */\nexport function readAuthenticodeSigner(file: string): Promise<AuthenticodeSignerInfo> {\n return process.platform === \"win32\" ? readAuthenticodeSignerWithPowerShell(file) : readEmbeddedAuthenticodeSigner(file)\n}\n\n/** File types electron-builder Authenticode-signs and can read the signature of back: PE files, MSI and AppX/MSIX packages. */\nconst AUTHENTICODE_FILE_EXTENSIONS = new Set([\".exe\", \".dll\", \".node\", \".msi\", \".appx\", \".appxbundle\", \".msix\", \".msixbundle\"])\n\n/** Whether `file` is a type whose Authenticode signature can be read back (see `AUTHENTICODE_FILE_EXTENSIONS`). */\nexport function isAuthenticodeFileType(file: string): boolean {\n return AUTHENTICODE_FILE_EXTENSIONS.has(path.extname(file).toLowerCase())\n}\n\n/**\n * Why a signature read back with {@link readAuthenticodeSigner} does not count as valid, or `null` when it does. Any\n * status but `HashMismatch` is accepted: the build host may not trust the signing chain that the users' machines\n * trust, and the reader used off Windows reports no status at all.\n */\nexport function authenticodeSignatureProblem(signer: AuthenticodeSignerInfo): string | null {\n switch (signer.type) {\n case \"unsigned\":\n return `carries no Authenticode signature (${signer.reason})`\n case \"unreadable\":\n return `has an Authenticode signature that cannot be read (${signer.reason})`\n case \"signed\":\n return signer.status === AuthenticodeSignatureStatus.HashMismatch ? \"has an invalid Authenticode signature (HashMismatch: the file was modified after signing)\" : null\n }\n}\n\n// ─── Windows: Get-AuthenticodeSignature ──────────────────────────────────────\n\n/**\n * Reads the signer with `Get-AuthenticodeSignature`, with the helpers electron-updater verifies downloaded updates\n * with (builder-util-runtime: the same PowerShell invocation and JSON parsing), so the build sees exactly what the\n * updater will see. Windows PowerShell is started from `toolsets.executables.powershell` or its default location, with\n * the build's credential variables (signing passwords, tokens, keys) removed from its environment: reading a signature\n * needs none of them.\n */\nexport function readAuthenticodeSignerWithPowerShell(file: string): Promise<AuthenticodeSignerInfo> {\n return new Promise<AuthenticodeSignerInfo>(resolve => {\n try {\n // a busy build machine may still be preparing the PowerShell modules on first use, and a timeout here fails the build\n // like every PowerShell the build starts: from toolsets.executables, or its default location when that has none\n const [powershell, args, options] = prepareAuthenticodeSignatureExec(file, 60 * 1000, Executables.resolve(\"powershell\"))\n execFile(powershell, args, { ...options, env: withoutInheritedCredentials(options.env ?? {}) }, (error, stdout, stderr) => {\n if (error != null) {\n const stderrText = String(stderr ?? \"\").trim()\n // the message of a non-zero exit is \"Command failed: <the whole command line, the encoded script included>\\n<stderr>\"\n const failure = error.killed ? \"did not finish within 60s\" : typeof error.code === \"number\" ? `exited with code ${error.code}` : error.message\n resolve({ type: \"unreadable\", reason: `Get-AuthenticodeSignature failed: ${failure}${stderrText.length > 0 ? `\\n${stderrText}` : \"\"}` })\n return\n }\n let data: unknown\n try {\n data = parseAuthenticodeSignatureOutput(stdout)\n } catch (e: any) {\n const stderrText = String(stderr ?? \"\").trim()\n resolve({ type: \"unreadable\", reason: `cannot parse Get-AuthenticodeSignature output (${e.message}): ${stdout}${stderrText.length > 0 ? `\\n${stderrText}` : \"\"}` })\n return\n }\n const status = getProperty(data, \"Status\")\n const numericStatus = typeof status === \"number\" ? status : null\n const subject = getProperty(getProperty(data, \"SignerCertificate\"), \"Subject\")\n if (typeof subject !== \"string\") {\n resolve({ type: \"unsigned\", reason: `Get-AuthenticodeSignature reports no signer certificate (status: ${authenticodeSignatureStatusName(numericStatus)})` })\n return\n }\n resolve({ type: \"signed\", subject, status: numericStatus })\n })\n } catch (e: any) {\n // PowerShell cannot be located (no executable at its toolsets.executables locations, or no default location) or started at all\n resolve({ type: \"unreadable\", reason: `Get-AuthenticodeSignature failed: ${e.message}` })\n }\n })\n}\n\n/**\n * `env` without the credential variables it inherited from the build (see `stripSensitiveEnvVars`). The variables the command\n * sets itself, such as the file to read, are kept: they are the ones whose value is not the inherited one.\n */\nfunction withoutInheritedCredentials(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n const result = stripSensitiveEnvVars(env)\n for (const [key, value] of Object.entries(env)) {\n if (process.env[key] !== value) {\n result[key] = value\n }\n }\n return result\n}\n\nfunction getProperty(value: unknown, name: string): unknown {\n return value != null && typeof value === \"object\" && name in value ? Reflect.get(value, name) : undefined\n}\n\n// ─── Windows subject format ─────────────────────────────────────────────────\n\n// Maps certificate attribute OIDs to the X.500 names Windows uses when it formats a certificate subject\n// (CertNameToStr with CERT_X500_NAME_STR, i.e. `X509Certificate2.Subject` as Get-AuthenticodeSignature reports it).\n// Other OIDs are written as `OID.<dotted oid>`, as Windows does (e.g. `OID.2.5.4.15` in EV certificates).\nconst WINDOWS_ATTRIBUTE_TYPE_NAMES: Record<string, string> = {\n \"2.5.4.3\": \"CN\",\n \"2.5.4.4\": \"SN\",\n \"2.5.4.5\": \"SERIALNUMBER\",\n \"2.5.4.6\": \"C\",\n \"2.5.4.7\": \"L\",\n \"2.5.4.8\": \"S\",\n \"2.5.4.9\": \"STREET\",\n \"2.5.4.10\": \"O\",\n \"2.5.4.11\": \"OU\",\n \"2.5.4.12\": \"T\",\n \"2.5.4.13\": \"Description\",\n \"2.5.4.17\": \"PostalCode\",\n \"2.5.4.18\": \"POBox\",\n \"2.5.4.20\": \"Phone\",\n \"2.5.4.24\": \"X21Address\",\n \"2.5.4.42\": \"G\",\n \"2.5.4.43\": \"I\",\n \"2.5.4.46\": \"dnQualifier\",\n \"1.2.840.113549.1.9.1\": \"E\",\n \"0.9.2342.19200300.100.1.25\": \"DC\",\n}\n\n// Windows quotes an RDN value that has leading/trailing white space or contains one of these characters,\n// doubling embedded quotes.\nconst NEEDS_WINDOWS_DN_QUOTING = /[,+=\"\\n<>#;]/\n\n/** Quotes an RDN value the way Windows does when it formats a certificate subject (see {@link formatWindowsSubjectDn}). */\nexport function quoteWindowsDnValue(value: string): string {\n if (value.length === 0 || value !== value.trim() || NEEDS_WINDOWS_DN_QUOTING.test(value)) {\n return `\"${value.replace(/\"/g, '\"\"')}\"`\n }\n return value\n}\n\n/**\n * Formats a certificate name the way Windows reports a certificate subject (`X509Certificate2.Subject`, which\n * electron-updater compares the configured publisher names against): RDNs in reverse encoding order separated by\n * `, `, with the Windows X.500 attribute names (e.g. `S` for the state, not `ST`).\n */\nexport function formatWindowsSubjectDn(name: pkijs.RelativeDistinguishedNames): string {\n return name.typesAndValues\n .map(attribute => {\n const typeName = WINDOWS_ATTRIBUTE_TYPE_NAMES[attribute.type] ?? `OID.${attribute.type}`\n return `${typeName}=${quoteWindowsDnValue(String(attribute.value.valueBlock.value))}`\n })\n .reverse()\n .join(\", \")\n}\n\n// ─── Any host: PE certificate table + PKCS#7 ────────────────────────────────\n\nconst WIN_CERT_TYPE_PKCS_SIGNED_DATA = 0x0002\n// The certificate table of a signed installer is a few KB; anything this large is not a real signature.\nconst MAX_CERTIFICATE_TABLE_SIZE = 16 * 1024 * 1024\n\nasync function readExactly(handle: Awaited<ReturnType<typeof open>>, position: number, length: number): Promise<Buffer> {\n const buffer = Buffer.alloc(length)\n const { bytesRead } = await handle.read(buffer, 0, length, position)\n if (bytesRead !== length) {\n throw new Error(`unexpected end of file reading ${length} bytes at offset ${position}`)\n }\n return buffer\n}\n\n/**\n * Returns the first `WIN_CERTIFICATE` entry of a PE file's certificate table (the primary Authenticode signature,\n * which is the one Windows reports), or null when the file has no certificate table. Only the headers and the table\n * itself are read, never the whole (possibly huge) installer.\n */\nexport async function readPeSignatureBlob(file: string): Promise<{ certificateType: number; data: Buffer } | null> {\n const handle = await open(file, \"r\")\n try {\n const { size: fileSize } = await handle.stat()\n const dosHeader = await readExactly(handle, 0, 64)\n if (dosHeader.toString(\"latin1\", 0, 2) !== \"MZ\") {\n throw new Error(\"not a PE file (no MZ header)\")\n }\n const peHeaderOffset = dosHeader.readUInt32LE(0x3c)\n // PE signature (4) + COFF file header (20)\n const peHeader = await readExactly(handle, peHeaderOffset, 24)\n if (peHeader.toString(\"latin1\", 0, 4) !== \"PE\\0\\0\") {\n throw new Error(\"not a PE file (no PE signature)\")\n }\n const optionalHeaderSize = peHeader.readUInt16LE(20)\n const optionalHeader = await readExactly(handle, peHeaderOffset + 24, optionalHeaderSize)\n const magic = optionalHeader.readUInt16LE(0)\n // PE32 / PE32+: offset of NumberOfRvaAndSizes; the data directories follow it\n const rvaCountOffset = magic === 0x10b ? 92 : magic === 0x20b ? 108 : -1\n if (rvaCountOffset === -1) {\n throw new Error(`unknown optional header magic 0x${magic.toString(16)}`)\n }\n // the certificate table is data directory #4; each entry is VirtualAddress (u32) + Size (u32)\n const securityDirectoryOffset = rvaCountOffset + 4 + 4 * 8\n if (optionalHeader.length < securityDirectoryOffset + 8 || optionalHeader.readUInt32LE(rvaCountOffset) <= 4) {\n return null\n }\n // for the certificate table, VirtualAddress is a file offset\n const tableOffset = optionalHeader.readUInt32LE(securityDirectoryOffset)\n const tableSize = optionalHeader.readUInt32LE(securityDirectoryOffset + 4)\n if (tableOffset === 0 || tableSize === 0) {\n return null\n }\n if (tableSize < 8 || tableSize > MAX_CERTIFICATE_TABLE_SIZE || tableOffset + tableSize > fileSize) {\n throw new Error(`invalid certificate table (offset ${tableOffset}, size ${tableSize}, file size ${fileSize})`)\n }\n const table = await readExactly(handle, tableOffset, tableSize)\n // WIN_CERTIFICATE: dwLength (u32, includes this 8-byte header), wRevision (u16), wCertificateType (u16), bCertificate\n const entryLength = table.readUInt32LE(0)\n if (entryLength < 8 || entryLength > tableSize) {\n throw new Error(`invalid WIN_CERTIFICATE length ${entryLength}`)\n }\n return { certificateType: table.readUInt16LE(6), data: table.subarray(8, entryLength) }\n } finally {\n await handle.close()\n }\n}\n\nfunction toArrayBuffer(buffer: Buffer): ArrayBuffer {\n const result = new ArrayBuffer(buffer.byteLength)\n new Uint8Array(result).set(buffer)\n return result\n}\n\n/**\n * Returns the subject of the certificate that made the first signer's signature in a DER-encoded PKCS#7 SignedData\n * (`ContentInfo`), formatted the way Windows reports it.\n */\nexport function readPkcs7SignerSubject(der: Buffer): string {\n const asn1 = asn1js.fromBER(toArrayBuffer(der))\n if (asn1.offset === -1) {\n throw new Error(\"invalid PKCS#7 encoding\")\n }\n const contentInfo = new pkijs.ContentInfo({ schema: asn1.result })\n if (contentInfo.contentType !== pkijs.id_ContentType_SignedData) {\n throw new Error(`unexpected PKCS#7 content type ${contentInfo.contentType}`)\n }\n const signedData = new pkijs.SignedData({ schema: contentInfo.content })\n const signerInfo = signedData.signerInfos[0]\n if (signerInfo == null) {\n throw new Error(\"PKCS#7 signature has no signer\")\n }\n const sid: unknown = signerInfo.sid\n if (!(sid instanceof pkijs.IssuerAndSerialNumber)) {\n throw new Error(\"PKCS#7 signer is not identified by issuer and serial number\")\n }\n const certificate = (signedData.certificates ?? []).find(\n (it): it is pkijs.Certificate => it instanceof pkijs.Certificate && it.issuer.isEqual(sid.issuer) && it.serialNumber.isEqual(sid.serialNumber)\n )\n if (certificate == null) {\n throw new Error(\"the signer certificate is not embedded in the PKCS#7 signature\")\n }\n return formatWindowsSubjectDn(certificate.subject)\n}\n\n/** Reads the embedded Authenticode signer of a PE file without external tools (works on any host). */\nexport async function readEmbeddedAuthenticodeSigner(file: string): Promise<AuthenticodeSignerInfo> {\n try {\n const blob = await readPeSignatureBlob(file)\n if (blob == null) {\n return { type: \"unsigned\", reason: \"the file has no embedded Authenticode signature (empty PE certificate table)\" }\n }\n if (blob.certificateType !== WIN_CERT_TYPE_PKCS_SIGNED_DATA) {\n return { type: \"unreadable\", reason: `unsupported WIN_CERTIFICATE type 0x${blob.certificateType.toString(16)}` }\n }\n return { type: \"signed\", subject: readPkcs7SignerSubject(blob.data), status: null }\n } catch (e: any) {\n return { type: \"unreadable\", reason: e.message || String(e) }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"pkcs11SignManager.d.ts","sourceRoot":"","sources":["../../../src/codeSign/win/pkcs11SignManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAsC,oBAAoB,EAA8B,MAAM,6BAA6B,CAAA;AAClI,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EAEnB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,8BAA8B,CAAA;AAErC,qBAAa,iBAAkB,SAAQ,uBAAuB;IAC5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;gBAE9C,QAAQ,EAAE,WAAW;IAsBjC,SAAkB,OAAO,wFAUxB;cAGkB,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO;IAIzG,SAAS,CAAC,sBAAsB,CAAC,QAAQ,EAAE,4BAA4B,EAAE,GAAG,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;IAIvG,SAAS,CAAC,uBAAuB,CAAC,OAAO,EAAE,4BAA4B,EAAE,EAAE,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;CAmDvG"}
1
+ {"version":3,"file":"pkcs11SignManager.d.ts","sourceRoot":"","sources":["../../../src/codeSign/win/pkcs11SignManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAsC,oBAAoB,EAA8B,MAAM,6BAA6B,CAAA;AAClI,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,mBAAmB,EAEnB,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,8BAA8B,CAAA;AAErC,qBAAa,iBAAkB,SAAQ,uBAAuB;IAC5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;gBAE9C,QAAQ,EAAE,WAAW;IAuBjC,SAAkB,OAAO,wFAUxB;cAGkB,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO;IAIzG,SAAS,CAAC,sBAAsB,CAAC,QAAQ,EAAE,4BAA4B,EAAE,GAAG,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;IAIvG,SAAS,CAAC,uBAAuB,CAAC,OAAO,EAAE,4BAA4B,EAAE,EAAE,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;CAmDvG"}
@@ -22,11 +22,12 @@ export class Pkcs11SignManager extends SigntoolBaseSignManager {
22
22
  this.signingConfig = signing;
23
23
  // publisherName == null means "auto-discover", but for PKCS#11 without a certificateFile
24
24
  // the cert lives inside the hardware token and cannot be read at build time. The result would be
25
- // a null publisherName in app-update.yml, silently disabling updater signature verification.
25
+ // a null publisherName in app-update.yml, with which electron-updater 7 rejects every update.
26
26
  if (signing.publisherName == null && !signing.certificateFile) {
27
27
  throw new InvalidConfigurationError("PKCS#11 signing requires either `win.sign.publisherName` or `win.sign.certificateFile` to be set. " +
28
- "Without one of these the publisher name cannot be determined at build time, and auto-updater signature verification will be silently skipped. " +
29
- "Set publisherName to the CN from your signing certificate, or provide certificateFile pointing to a certificate chain file (.crt / .cer).");
28
+ "Without one of these the publisher name cannot be determined at build time, and electron-updater rejects every update of an app whose app-update.yml has no publisherName. " +
29
+ 'Set publisherName to the subject of your signing certificate, as a distinguished name (e.g. "CN=My Company, O=My Company, C=US"), ' +
30
+ "or provide certificateFile pointing to a certificate chain file (.crt / .cer).");
30
31
  }
31
32
  }
32
33
  // PKCS#11: always proceed — the key URI is sufficient, no cert file required.
@@ -1 +1 @@
1
- {"version":3,"file":"pkcs11SignManager.js","sourceRoot":"","sources":["../../../src/codeSign/win/pkcs11SignManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,kCAAkC,EAAoD,MAAM,6BAA6B,CAAA;AAGlI,OAAO,EAIL,uBAAuB,EACvB,uBAAuB,GAExB,MAAM,8BAA8B,CAAA;AAErC,MAAM,OAAO,iBAAkB,SAAQ,uBAAuB;IAG5D,YAAY,QAAqB;QAC/B,KAAK,CAAC,QAAQ,CAAC,CAAA;QAmBjB,uFAAuF;QACvF,uGAAuG;QACrF,YAAO,GAAG,IAAI,QAAQ,CACtC,GAAG,EAAE,CAAC,IAAI,CAAC,4BAA4B,EACvC,6BAA6B,CAAC,EAAE;YAC9B,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,aAAa,CAAA;YAC9C,IAAI,eAAe,EAAE,CAA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AEnD,wFAAwF;QACxF,4FAA4F;QAC5F,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAA;YAC5E,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;gBAChB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;QAC1C,IAAI,UAAU,EAAE,MAAM,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAC7B,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { InvalidConfigurationError } from \"builder-util\"\nimport { MemoLazy } from \"builder-util-runtime\"\nimport { resolveWindowsSigningConfiguration, WindowsConfiguration, WindowsPkcs11SigningConfig } from \"../../options/winOptions.js\"\nimport { VmManager } from \"../../vm/vm.js\"\nimport type { WinPackager } from \"../../winPackager.js\"\nimport {\n CustomWindowsSign,\n CertificateFromStoreInfo,\n FileCodeSigningInfo,\n getSigntoolFamilyConfig,\n SigntoolBaseSignManager,\n WindowsSignTaskConfiguration,\n} from \"./signtoolBaseSignManager.js\"\n\nexport class Pkcs11SignManager extends SigntoolBaseSignManager {\n private readonly signingConfig: WindowsPkcs11SigningConfig\n\n constructor(packager: WinPackager) {\n super(packager)\n const signing = resolveWindowsSigningConfiguration(packager.platformOptions)\n if (signing?.type !== \"pkcs11\") {\n throw new Error(`Pkcs11SignManager requires signing.type = \"pkcs11\", got: ${signing?.type}`)\n }\n this.signingConfig = signing\n\n // publisherName == null means \"auto-discover\", but for PKCS#11 without a certificateFile\n // the cert lives inside the hardware token and cannot be read at build time. The result would be\n // a null publisherName in app-update.yml, silently disabling updater signature verification.\n if (signing.publisherName == null && !signing.certificateFile) {\n throw new InvalidConfigurationError(\n \"PKCS#11 signing requires either `win.sign.publisherName` or `win.sign.certificateFile` to be set. \" +\n \"Without one of these the publisher name cannot be determined at build time, and auto-updater signature verification will be silently skipped. \" +\n \"Set publisherName to the CN from your signing certificate, or provide certificateFile pointing to a certificate chain file (.crt / .cer).\"\n )\n }\n }\n\n // PKCS#11: key and cert are in the hardware token; cert file is optional (chain only).\n // When a cert file is supplied, the PIN (if any) is read from WIN_CSC_KEY_PASSWORD / CSC_KEY_PASSWORD.\n override readonly cscInfo = new MemoLazy<WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null>(\n () => this.platformSpecificBuildOptions,\n _platformSpecificBuildOptions => {\n const { certificateFile } = this.signingConfig\n if (certificateFile) {\n const pin = this.packager.getCscPassword() ?? null\n return Promise.resolve({ file: certificateFile, password: pin })\n }\n return Promise.resolve(null)\n }\n )\n\n // PKCS#11: always proceed — the key URI is sufficient, no cert file required.\n protected override handleNullCscInfo(_customSign: CustomWindowsSign | string | null | undefined): boolean {\n return false\n }\n\n protected computeWindowsSignArgs(_options: WindowsSignTaskConfiguration, _vm: VmManager): Array<string> {\n throw new InvalidConfigurationError('PKCS#11 signing is only supported via osslsigncode (non-Windows). Use type: \"signtool\" or type: \"hsm\" on Windows.')\n }\n\n protected computeOsslsigncodeArgs(options: WindowsSignTaskConfiguration, vm: VmManager): Array<string> {\n const signing = getSigntoolFamilyConfig(options.options) as WindowsPkcs11SigningConfig\n\n // Runtime guard: JSON configs can produce partial objects that bypass TypeScript.\n if (!signing.pkcs11Module || !signing.pkcs11KeyUri) {\n throw new InvalidConfigurationError('pkcs11Module and pkcs11KeyUri must both be set for type: \"pkcs11\" signing.')\n }\n\n const inputFile = vm.toVmFile(options.path)\n const outputPath = this.getOutputPath(inputFile, options.hash)\n options.resultOutputPath = outputPath\n\n const args = [\"sign\", \"-in\", inputFile, \"-out\", outputPath]\n\n // RFC 3161 for sha256/nested (mirrors signtool /tr); HTTP Authenticode for sha1 (/t).\n if (process.env.ELECTRON_BUILDER_OFFLINE !== \"true\") {\n const isRfc3161 = options.isNest || options.hash === \"sha256\"\n if (isRfc3161) {\n args.push(\"-ts\", signing.rfc3161TimeStampServer || \"http://timestamp.digicert.com\")\n } else {\n args.push(\"-t\", signing.timeStampServer || \"http://timestamp.digicert.com\")\n }\n }\n\n args.push(\"-pkcs11module\", signing.pkcs11Module)\n args.push(\"-key\", signing.pkcs11KeyUri)\n\n // External certificate chain (optional — token may carry the cert internally).\n if (signing.certificateFile) {\n args.push(\"-certs\", vm.toVmFile(signing.certificateFile))\n }\n\n args.push(\"-h\", options.hash.toLowerCase())\n this.addCommonSigningArgs(args, options, vm, false)\n\n // When cscInfo is null the token holds the cert; addCommonSigningArgs won't emit -pass.\n // Read the PIN from env vars so CI workflows can inject it without embedding it in the URI.\n if (!options.cscInfo) {\n const pin = process.env.WIN_CSC_KEY_PASSWORD ?? process.env.CSC_KEY_PASSWORD\n if (pin?.trim()) {\n args.push(\"-pass\", pin.trim())\n }\n }\n\n const httpsProxy = process.env.HTTPS_PROXY\n if (httpsProxy?.length) {\n args.push(\"-p\", httpsProxy)\n }\n\n return args\n }\n}\n"]}
1
+ {"version":3,"file":"pkcs11SignManager.js","sourceRoot":"","sources":["../../../src/codeSign/win/pkcs11SignManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,kCAAkC,EAAoD,MAAM,6BAA6B,CAAA;AAGlI,OAAO,EAIL,uBAAuB,EACvB,uBAAuB,GAExB,MAAM,8BAA8B,CAAA;AAErC,MAAM,OAAO,iBAAkB,SAAQ,uBAAuB;IAG5D,YAAY,QAAqB;QAC/B,KAAK,CAAC,QAAQ,CAAC,CAAA;QAoBjB,uFAAuF;QACvF,uGAAuG;QACrF,YAAO,GAAG,IA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,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;QAC3C,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAAA;QAEnD,wFAAwF;QACxF,4FAA4F;QAC5F,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAA;YAC5E,IAAI,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;gBAChB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;QAC1C,IAAI,UAAU,EAAE,MAAM,EAAE,CAAC;YACvB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QAC7B,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { InvalidConfigurationError } from \"builder-util\"\nimport { MemoLazy } from \"builder-util-runtime\"\nimport { resolveWindowsSigningConfiguration, WindowsConfiguration, WindowsPkcs11SigningConfig } from \"../../options/winOptions.js\"\nimport { VmManager } from \"../../vm/vm.js\"\nimport type { WinPackager } from \"../../winPackager.js\"\nimport {\n CustomWindowsSign,\n CertificateFromStoreInfo,\n FileCodeSigningInfo,\n getSigntoolFamilyConfig,\n SigntoolBaseSignManager,\n WindowsSignTaskConfiguration,\n} from \"./signtoolBaseSignManager.js\"\n\nexport class Pkcs11SignManager extends SigntoolBaseSignManager {\n private readonly signingConfig: WindowsPkcs11SigningConfig\n\n constructor(packager: WinPackager) {\n super(packager)\n const signing = resolveWindowsSigningConfiguration(packager.platformOptions)\n if (signing?.type !== \"pkcs11\") {\n throw new Error(`Pkcs11SignManager requires signing.type = \"pkcs11\", got: ${signing?.type}`)\n }\n this.signingConfig = signing\n\n // publisherName == null means \"auto-discover\", but for PKCS#11 without a certificateFile\n // the cert lives inside the hardware token and cannot be read at build time. The result would be\n // a null publisherName in app-update.yml, with which electron-updater 7 rejects every update.\n if (signing.publisherName == null && !signing.certificateFile) {\n throw new InvalidConfigurationError(\n \"PKCS#11 signing requires either `win.sign.publisherName` or `win.sign.certificateFile` to be set. \" +\n \"Without one of these the publisher name cannot be determined at build time, and electron-updater rejects every update of an app whose app-update.yml has no publisherName. \" +\n 'Set publisherName to the subject of your signing certificate, as a distinguished name (e.g. \"CN=My Company, O=My Company, C=US\"), ' +\n \"or provide certificateFile pointing to a certificate chain file (.crt / .cer).\"\n )\n }\n }\n\n // PKCS#11: key and cert are in the hardware token; cert file is optional (chain only).\n // When a cert file is supplied, the PIN (if any) is read from WIN_CSC_KEY_PASSWORD / CSC_KEY_PASSWORD.\n override readonly cscInfo = new MemoLazy<WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null>(\n () => this.platformSpecificBuildOptions,\n _platformSpecificBuildOptions => {\n const { certificateFile } = this.signingConfig\n if (certificateFile) {\n const pin = this.packager.getCscPassword() ?? null\n return Promise.resolve({ file: certificateFile, password: pin })\n }\n return Promise.resolve(null)\n }\n )\n\n // PKCS#11: always proceed — the key URI is sufficient, no cert file required.\n protected override handleNullCscInfo(_customSign: CustomWindowsSign | string | null | undefined): boolean {\n return false\n }\n\n protected computeWindowsSignArgs(_options: WindowsSignTaskConfiguration, _vm: VmManager): Array<string> {\n throw new InvalidConfigurationError('PKCS#11 signing is only supported via osslsigncode (non-Windows). Use type: \"signtool\" or type: \"hsm\" on Windows.')\n }\n\n protected computeOsslsigncodeArgs(options: WindowsSignTaskConfiguration, vm: VmManager): Array<string> {\n const signing = getSigntoolFamilyConfig(options.options) as WindowsPkcs11SigningConfig\n\n // Runtime guard: JSON configs can produce partial objects that bypass TypeScript.\n if (!signing.pkcs11Module || !signing.pkcs11KeyUri) {\n throw new InvalidConfigurationError('pkcs11Module and pkcs11KeyUri must both be set for type: \"pkcs11\" signing.')\n }\n\n const inputFile = vm.toVmFile(options.path)\n const outputPath = this.getOutputPath(inputFile, options.hash)\n options.resultOutputPath = outputPath\n\n const args = [\"sign\", \"-in\", inputFile, \"-out\", outputPath]\n\n // RFC 3161 for sha256/nested (mirrors signtool /tr); HTTP Authenticode for sha1 (/t).\n if (process.env.ELECTRON_BUILDER_OFFLINE !== \"true\") {\n const isRfc3161 = options.isNest || options.hash === \"sha256\"\n if (isRfc3161) {\n args.push(\"-ts\", signing.rfc3161TimeStampServer || \"http://timestamp.digicert.com\")\n } else {\n args.push(\"-t\", signing.timeStampServer || \"http://timestamp.digicert.com\")\n }\n }\n\n args.push(\"-pkcs11module\", signing.pkcs11Module)\n args.push(\"-key\", signing.pkcs11KeyUri)\n\n // External certificate chain (optional — token may carry the cert internally).\n if (signing.certificateFile) {\n args.push(\"-certs\", vm.toVmFile(signing.certificateFile))\n }\n\n args.push(\"-h\", options.hash.toLowerCase())\n this.addCommonSigningArgs(args, options, vm, false)\n\n // When cscInfo is null the token holds the cert; addCommonSigningArgs won't emit -pass.\n // Read the PIN from env vars so CI workflows can inject it without embedding it in the URI.\n if (!options.cscInfo) {\n const pin = process.env.WIN_CSC_KEY_PASSWORD ?? process.env.CSC_KEY_PASSWORD\n if (pin?.trim()) {\n args.push(\"-pass\", pin.trim())\n }\n }\n\n const httpsProxy = process.env.HTTPS_PROXY\n if (httpsProxy?.length) {\n args.push(\"-p\", httpsProxy)\n }\n\n return args\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { InvalidConfigurationError } from "builder-util";
2
+ import { WindowsConfiguration } from "../../options/winOptions.js";
3
+ export declare const PUBLISHER_NAME_DN_DOCS_URL = "https://www.electron.build/docs/migration/v27-build-changes#windows-publishername-must-be-a-distinguished-name";
4
+ export declare const MISSING_PUBLISHER_NAME_DOCS_URL = "https://www.electron.build/docs/migration/v27-build-changes#missing-publishername-fails-update-verification";
5
+ /** What electron-updater 7 requires of a publisher name, for the error messages of the build. */
6
+ export declare const PUBLISHER_NAME_DN_REQUIREMENT: string;
7
+ /** The entries of a publisherName that are not a valid publisher name DN ({@link isValidPublisherNameDn}). */
8
+ export declare function invalidPublisherNames(publisherName: string | ReadonlyArray<string>): Array<unknown>;
9
+ /**
10
+ * Throws an {@link InvalidConfigurationError} when an explicitly configured publisherName has an entry that is not a
11
+ * distinguished name ({@link isValidPublisherNameDn}), which electron-updater 7 could never match. `null` / `undefined` (none /
12
+ * derive from the certificate) are not validated: a build that writes `app-update.yml` without a publisherName fails elsewhere
13
+ * ({@link missingUpdatePublisherNameError}).
14
+ */
15
+ export declare function validatePublisherNameFormat(publisherName: string | ReadonlyArray<string> | null | undefined, configKey?: string): void;
16
+ /**
17
+ * The publisher name written to `app-update.yml` when none is configured: `CN=<common name>` of the signing certificate,
18
+ * with the value quoted the way Windows quotes it in the subject it reports (`X509Certificate2.Subject`, which electron-updater
19
+ * matches against), so a common name containing e.g. `,`, `+` or `"` matches the signer's CN. Only the CN is pinned, so a
20
+ * renewed certificate whose other subject attributes change still matches; a stricter pin is an explicit publisherName.
21
+ * Throws an {@link InvalidConfigurationError} when the certificate has no common name (empty).
22
+ */
23
+ export declare function derivePublisherName(commonName: string): string;
24
+ /**
25
+ * The error for a Windows build that would write `app-update.yml` without a publisherName while update signature verification is
26
+ * enabled (`win.verifyUpdateCodeSignature` is not `false`): electron-updater 7 rejects every update of such an app. The reason names
27
+ * what left the publisherName unresolved: signing disabled, an explicit `publisherName: null` (no opt-out any more since v27), or no
28
+ * certificate to derive it from.
29
+ */
30
+ export declare function missingUpdatePublisherNameError(options: WindowsConfiguration): InvalidConfigurationError;
31
+ //# sourceMappingURL=publisherName.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisherName.d.ts","sourceRoot":"","sources":["../../../src/codeSign/win/publisherName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAExD,OAAO,EAAgE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAGhI,eAAO,MAAM,0BAA0B,mHAAmH,CAAA;AAE1J,eAAO,MAAM,+BAA+B,gHAAgH,CAAA;AAE5J,iGAAiG;AACjG,eAAO,MAAM,6BAA6B,QAE0F,CAAA;AAEpI,8GAA8G;AAC9G,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAInG;AAMD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,SAAS,SAA2B,GAAG,IAAI,CAaxJ;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAU9D;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,oBAAoB,GAAG,yBAAyB,CAkBxG"}
@@ -0,0 +1,78 @@
1
+ import { InvalidConfigurationError } from "builder-util";
2
+ import { isValidPublisherNameDn } from "builder-util-runtime";
3
+ import { isWindowsSigningDisabled, resolveWindowsSigningConfiguration } from "../../options/winOptions.js";
4
+ import { quoteWindowsDnValue } from "./authenticodeSignature.js";
5
+ export const PUBLISHER_NAME_DN_DOCS_URL = "https://www.electron.build/docs/migration/v27-build-changes#windows-publishername-must-be-a-distinguished-name";
6
+ export const MISSING_PUBLISHER_NAME_DOCS_URL = "https://www.electron.build/docs/migration/v27-build-changes#missing-publishername-fails-update-verification";
7
+ /** What electron-updater 7 requires of a publisher name, for the error messages of the build. */
8
+ export const PUBLISHER_NAME_DN_REQUIREMENT = 'Since electron-builder v27, each publisherName entry must be in distinguished name (DN) format, e.g. "CN=My Company, O=My Company, C=US" ' +
9
+ "(the subject of the code signing certificate, or the attributes of it to compare) — electron-updater 7 never matches a bare name";
10
+ /** The entries of a publisherName that are not a valid publisher name DN ({@link isValidPublisherNameDn}). */
11
+ export function invalidPublisherNames(publisherName) {
12
+ // typed as configured, but a hand-written JSON value may be anything: an entry that is no string is reported as invalid
13
+ const entries = Array.isArray(publisherName) ? publisherName : [publisherName];
14
+ return entries.filter(it => !isValidPublisherNameDn(it));
15
+ }
16
+ function formatPublisherNames(names) {
17
+ return names.map(it => (typeof it === "string" ? `"${it}"` : `(${typeof it})`)).join(", ");
18
+ }
19
+ /**
20
+ * Throws an {@link InvalidConfigurationError} when an explicitly configured publisherName has an entry that is not a
21
+ * distinguished name ({@link isValidPublisherNameDn}), which electron-updater 7 could never match. `null` / `undefined` (none /
22
+ * derive from the certificate) are not validated: a build that writes `app-update.yml` without a publisherName fails elsewhere
23
+ * ({@link missingUpdatePublisherNameError}).
24
+ */
25
+ export function validatePublisherNameFormat(publisherName, configKey = "win.sign.publisherName") {
26
+ if (publisherName == null) {
27
+ return;
28
+ }
29
+ const invalid = invalidPublisherNames(publisherName);
30
+ if (invalid.length === 0) {
31
+ return;
32
+ }
33
+ throw new InvalidConfigurationError(`${configKey} ${formatPublisherNames(invalid)} is not a distinguished name. ${PUBLISHER_NAME_DN_REQUIREMENT}. ` +
34
+ `Set ${configKey} to the subject of the certificate that signs your app (on Windows, (Get-AuthenticodeSignature <signed .exe>).SignerCertificate.Subject prints it), ` +
35
+ `or set win.verifyUpdateCodeSignature: false to opt out of update signature verification. See ${PUBLISHER_NAME_DN_DOCS_URL}`);
36
+ }
37
+ /**
38
+ * The publisher name written to `app-update.yml` when none is configured: `CN=<common name>` of the signing certificate,
39
+ * with the value quoted the way Windows quotes it in the subject it reports (`X509Certificate2.Subject`, which electron-updater
40
+ * matches against), so a common name containing e.g. `,`, `+` or `"` matches the signer's CN. Only the CN is pinned, so a
41
+ * renewed certificate whose other subject attributes change still matches; a stricter pin is an explicit publisherName.
42
+ * Throws an {@link InvalidConfigurationError} when the certificate has no common name (empty).
43
+ */
44
+ export function derivePublisherName(commonName) {
45
+ const publisherName = `CN=${quoteWindowsDnValue(commonName)}`;
46
+ if (commonName.length === 0 || !isValidPublisherNameDn(publisherName)) {
47
+ throw new InvalidConfigurationError(`Cannot derive publisherName from the code signing certificate: its Common Name (${JSON.stringify(commonName)}) cannot form a distinguished name. ` +
48
+ `Set win.sign.publisherName explicitly to the subject of the certificate that signs your updates (or the attributes of it to compare), ` +
49
+ `or set win.verifyUpdateCodeSignature: false to opt out of update signature verification. See ${PUBLISHER_NAME_DN_DOCS_URL}`);
50
+ }
51
+ return publisherName;
52
+ }
53
+ /**
54
+ * The error for a Windows build that would write `app-update.yml` without a publisherName while update signature verification is
55
+ * enabled (`win.verifyUpdateCodeSignature` is not `false`): electron-updater 7 rejects every update of such an app. The reason names
56
+ * what left the publisherName unresolved: signing disabled, an explicit `publisherName: null` (no opt-out any more since v27), or no
57
+ * certificate to derive it from.
58
+ */
59
+ export function missingUpdatePublisherNameError(options) {
60
+ const signing = resolveWindowsSigningConfiguration(options);
61
+ let reason;
62
+ if (isWindowsSigningDisabled(options)) {
63
+ reason = `win.sign is ${options.sign === false ? "false" : "null"} (signing disabled), so no publisherName is derived from a code signing certificate`;
64
+ }
65
+ else if (signing?.publisherName === null) {
66
+ reason = "win.sign.publisherName is null, which no longer opts out of update signature verification since electron-builder v27";
67
+ }
68
+ else {
69
+ reason =
70
+ "no code signing certificate is configured (win.sign.certificateFile, WIN_CSC_LINK / CSC_LINK, win.sign.certificateSubjectName or win.sign.certificateSha1) to derive publisherName from";
71
+ }
72
+ return new InvalidConfigurationError(`Cannot write app-update.yml without publisherName: ${reason}. ` +
73
+ "Since electron-builder v27, electron-updater 7 rejects every update of an app whose app-update.yml has no publisherName (it used to skip the signature verification). " +
74
+ "Sign the build with a code signing certificate (electron-builder then writes CN=<common name> of it), " +
75
+ 'set win.sign.publisherName to the distinguished name of the certificate that signs your installer (e.g. win.sign: { type: "signtool", publisherName: ["CN=My Company, O=My Company, C=US"] } when you sign outside electron-builder), ' +
76
+ `or set win.verifyUpdateCodeSignature: false to opt out of update signature verification explicitly. See ${MISSING_PUBLISHER_NAME_DOCS_URL}`);
77
+ }
78
+ //# sourceMappingURL=publisherName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisherName.js","sourceRoot":"","sources":["../../../src/codeSign/win/publisherName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,wBAAwB,EAAE,kCAAkC,EAAwB,MAAM,6BAA6B,CAAA;AAChI,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE,MAAM,CAAC,MAAM,0BAA0B,GAAG,gHAAgH,CAAA;AAE1J,MAAM,CAAC,MAAM,+BAA+B,GAAG,6GAA6G,CAAA;AAE5J,iGAAiG;AACjG,MAAM,CAAC,MAAM,6BAA6B,GACxC,2IAA2I;IAC3I,kIAAkI,CAAA;AAEpI,8GAA8G;AAC9G,MAAM,UAAU,qBAAqB,CAAC,aAA6C;IACjF,wHAAwH;IACxH,MAAM,OAAO,GAA2B,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA;IACtG,OAAO,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED,SAAS,oBAAoB,CAAC,KAA6B;IACzD,OAAO,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAA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AAK,IAAI,EAAE,CAAC;QAC3C,MAAM,GAAG,sHAAsH,CAAA;IACjI,CAAC;SAAM,CAAC;QACN,MAAM;YACJ,yLAAyL,CAAA;IAC7L,CAAC;IACD,OAAO,IAAI,yBAAyB,CAClC,sDAAsD,MAAM,IAAI;QAC9D,wKAAwK;QACxK,wGAAwG;QACxG,wOAAwO;QACxO,2GAA2G,+BAA+B,EAAE,CAC/I,CAAA;AACH,CAAC","sourcesContent":["import { InvalidConfigurationError } from \"builder-util\"\nimport { isValidPublisherNameDn } from \"builder-util-runtime\"\nimport { isWindowsSigningDisabled, resolveWindowsSigningConfiguration, WindowsConfiguration } from \"../../options/winOptions.js\"\nimport { quoteWindowsDnValue } from \"./authenticodeSignature.js\"\n\nexport const PUBLISHER_NAME_DN_DOCS_URL = \"https://www.electron.build/docs/migration/v27-build-changes#windows-publishername-must-be-a-distinguished-name\"\n\nexport const MISSING_PUBLISHER_NAME_DOCS_URL = \"https://www.electron.build/docs/migration/v27-build-changes#missing-publishername-fails-update-verification\"\n\n/** What electron-updater 7 requires of a publisher name, for the error messages of the build. */\nexport const PUBLISHER_NAME_DN_REQUIREMENT =\n 'Since electron-builder v27, each publisherName entry must be in distinguished name (DN) format, e.g. \"CN=My Company, O=My Company, C=US\" ' +\n \"(the subject of the code signing certificate, or the attributes of it to compare) — electron-updater 7 never matches a bare name\"\n\n/** The entries of a publisherName that are not a valid publisher name DN ({@link isValidPublisherNameDn}). */\nexport function invalidPublisherNames(publisherName: string | ReadonlyArray<string>): Array<unknown> {\n // typed as configured, but a hand-written JSON value may be anything: an entry that is no string is reported as invalid\n const entries: ReadonlyArray<unknown> = Array.isArray(publisherName) ? publisherName : [publisherName]\n return entries.filter(it => !isValidPublisherNameDn(it))\n}\n\nfunction formatPublisherNames(names: ReadonlyArray<unknown>): string {\n return names.map(it => (typeof it === \"string\" ? `\"${it}\"` : `(${typeof it})`)).join(\", \")\n}\n\n/**\n * Throws an {@link InvalidConfigurationError} when an explicitly configured publisherName has an entry that is not a\n * distinguished name ({@link isValidPublisherNameDn}), which electron-updater 7 could never match. `null` / `undefined` (none /\n * derive from the certificate) are not validated: a build that writes `app-update.yml` without a publisherName fails elsewhere\n * ({@link missingUpdatePublisherNameError}).\n */\nexport function validatePublisherNameFormat(publisherName: string | ReadonlyArray<string> | null | undefined, configKey = \"win.sign.publisherName\"): void {\n if (publisherName == null) {\n return\n }\n const invalid = invalidPublisherNames(publisherName)\n if (invalid.length === 0) {\n return\n }\n throw new InvalidConfigurationError(\n `${configKey} ${formatPublisherNames(invalid)} is not a distinguished name. ${PUBLISHER_NAME_DN_REQUIREMENT}. ` +\n `Set ${configKey} to the subject of the certificate that signs your app (on Windows, (Get-AuthenticodeSignature <signed .exe>).SignerCertificate.Subject prints it), ` +\n `or set win.verifyUpdateCodeSignature: false to opt out of update signature verification. See ${PUBLISHER_NAME_DN_DOCS_URL}`\n )\n}\n\n/**\n * The publisher name written to `app-update.yml` when none is configured: `CN=<common name>` of the signing certificate,\n * with the value quoted the way Windows quotes it in the subject it reports (`X509Certificate2.Subject`, which electron-updater\n * matches against), so a common name containing e.g. `,`, `+` or `\"` matches the signer's CN. Only the CN is pinned, so a\n * renewed certificate whose other subject attributes change still matches; a stricter pin is an explicit publisherName.\n * Throws an {@link InvalidConfigurationError} when the certificate has no common name (empty).\n */\nexport function derivePublisherName(commonName: string): string {\n const publisherName = `CN=${quoteWindowsDnValue(commonName)}`\n if (commonName.length === 0 || !isValidPublisherNameDn(publisherName)) {\n throw new InvalidConfigurationError(\n `Cannot derive publisherName from the code signing certificate: its Common Name (${JSON.stringify(commonName)}) cannot form a distinguished name. ` +\n `Set win.sign.publisherName explicitly to the subject of the certificate that signs your updates (or the attributes of it to compare), ` +\n `or set win.verifyUpdateCodeSignature: false to opt out of update signature verification. See ${PUBLISHER_NAME_DN_DOCS_URL}`\n )\n }\n return publisherName\n}\n\n/**\n * The error for a Windows build that would write `app-update.yml` without a publisherName while update signature verification is\n * enabled (`win.verifyUpdateCodeSignature` is not `false`): electron-updater 7 rejects every update of such an app. The reason names\n * what left the publisherName unresolved: signing disabled, an explicit `publisherName: null` (no opt-out any more since v27), or no\n * certificate to derive it from.\n */\nexport function missingUpdatePublisherNameError(options: WindowsConfiguration): InvalidConfigurationError {\n const signing = resolveWindowsSigningConfiguration(options)\n let reason: string\n if (isWindowsSigningDisabled(options)) {\n reason = `win.sign is ${options.sign === false ? \"false\" : \"null\"} (signing disabled), so no publisherName is derived from a code signing certificate`\n } else if (signing?.publisherName === null) {\n reason = \"win.sign.publisherName is null, which no longer opts out of update signature verification since electron-builder v27\"\n } else {\n reason =\n \"no code signing certificate is configured (win.sign.certificateFile, WIN_CSC_LINK / CSC_LINK, win.sign.certificateSubjectName or win.sign.certificateSha1) to derive publisherName from\"\n }\n return new InvalidConfigurationError(\n `Cannot write app-update.yml without publisherName: ${reason}. ` +\n \"Since electron-builder v27, electron-updater 7 rejects every update of an app whose app-update.yml has no publisherName (it used to skip the signature verification). \" +\n \"Sign the build with a code signing certificate (electron-builder then writes CN=<common name> of it), \" +\n 'set win.sign.publisherName to the distinguished name of the certificate that signs your installer (e.g. win.sign: { type: \"signtool\", publisherName: [\"CN=My Company, O=My Company, C=US\"] } when you sign outside electron-builder), ' +\n `or set win.verifyUpdateCodeSignature: false to opt out of update signature verification explicitly. See ${MISSING_PUBLISHER_NAME_DOCS_URL}`\n )\n}\n"]}