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
@@ -1,5 +1,5 @@
1
1
  import { sign as _sign } from "@electron/osx-sign";
2
- import { copyFile, exec, InvalidConfigurationError, isEmptyOrSpaces, isPullRequest, log, Logger, retry, unlinkIfExists } from "builder-util";
2
+ import { copyFile, exec, Executables, InvalidConfigurationError, isEmptyOrSpaces, isPullRequest, log, Logger, retry, unlinkIfExists } from "builder-util";
3
3
  import { createHash, randomBytes } from "crypto";
4
4
  import { rename } from "fs/promises";
5
5
  import { Lazy } from "lazy-val";
@@ -8,6 +8,7 @@ import * as path from "path";
8
8
  import { getTempName } from "temp-file";
9
9
  import { isAutoDiscoveryCodeSignIdentity, isCscForPullRequest, isTravis } from "../../util/flags.js";
10
10
  import { importCertificate } from "../codesign.js";
11
+ import { forceCodeSigningError } from "../forceCodeSigning.js";
11
12
  import { cacheDirectoryOverrideAllowed } from "../../util/electronGet.js";
12
13
  export const appleCertificatePrefixes = ["Developer ID Application:", "Developer ID Installer:", "3rd Party Mac Developer Application:", "3rd Party Mac Developer Installer:"];
13
14
  export function isSignAllowed(isPrintWarn = true) {
@@ -35,6 +36,23 @@ export function isSignAllowed(isPrintWarn = true) {
35
36
  }
36
37
  return true;
37
38
  }
39
+ /**
40
+ * The error for a `forceCodeSigning` build that cannot sign `subject` here — the two cases {@link isSignAllowed} skips
41
+ * signing for: a host other than macOS, and a pull-request build without `CSC_FOR_PULL_REQUEST`. `null` when signing
42
+ * is possible. `overrideHint` is the `-c` option that turns `forceCodeSigning` off (see `forceCodeSigningOverrideHint`).
43
+ */
44
+ export function macSigningUnavailableError(subject, overrideHint) {
45
+ if (process.platform !== "darwin") {
46
+ return forceCodeSigningError(`forceCodeSigning is enabled, but ${subject} cannot be code signed or notarized on ${process.platform}: macOS code signing needs a macOS host. ` +
47
+ `Build the macOS targets on macOS, or pass ${overrideHint} to build them unsigned.`);
48
+ }
49
+ if (isPullRequest() && !isCscForPullRequest()) {
50
+ return forceCodeSigningError(`forceCodeSigning is enabled, but this is a pull-request build (GITHUB_BASE_REF, TRAVIS_PULL_REQUEST, CIRCLE_PULL_REQUEST, BITRISE_PULL_REQUEST or APPVEYOR_PULL_REQUEST_NUMBER is set), ` +
51
+ `where electron-builder does not sign ${subject}. Set CSC_FOR_PULL_REQUEST=true to sign pull-request builds (only if untrusted forks cannot open pull requests, since the build gets your signing credentials), ` +
52
+ `or pass ${overrideHint} for pull-request builds.`);
53
+ }
54
+ return null;
55
+ }
38
56
  export async function reportError(isMas, certificateTypes, qualifier, keychainFile, isForceCodeSigning) {
39
57
  const logFields = {};
40
58
  if (qualifier == null) {
@@ -145,10 +163,19 @@ export async function createKeychain({ tmpDir, cscLink, cscKeyPassword, cscILink
145
163
  }
146
164
  return await importCerts(keychainFile, certPaths, cscPasswords, keychainPassword);
147
165
  }
166
+ /**
167
+ * The programs the imported signing keys may be used by without a prompt (`security import -T`): the codesign and productbuild
168
+ * that electron-builder starts (from `toolsets.executables` or their default locations), and /usr/bin/codesign, which
169
+ * @electron/osx-sign starts by name.
170
+ */
171
+ export function keychainTrustedApplications() {
172
+ return Array.from(new Set(["/usr/bin/codesign", Executables.resolve("codesign"), Executables.resolve("productbuild")]));
173
+ }
148
174
  async function importCerts(keychainFile, paths, keyPasswords, keychainPassword) {
175
+ const trustedApplications = keychainTrustedApplications().flatMap(it => ["-T", it]);
149
176
  for (let i = 0; i < paths.length; i++) {
150
177
  const password = keyPasswords[i] ?? "";
151
- await exec("/usr/bin/security", ["import", paths[i], "-k", keychainFile, "-T", "/usr/bin/codesign", "-T", "/usr/bin/productbuild", "-P", password]);
178
+ await exec("/usr/bin/security", ["import", paths[i], "-k", keychainFile, ...trustedApplications, "-P", password]);
152
179
  // https://stackoverflow.com/questions/39868578/security-codesign-in-sierra-keychain-ignores-access-control-settings-and-ui-p
153
180
  // https://github.com/electron-userland/electron-packager/issues/701#issuecomment-322315996
154
181
  // `-k` expects the keychain's own unlock password (as used by create-keychain/unlock-keychain above),
@@ -1 +1 @@
1
- {"version":3,"file":"macCodeSign.js","sourceRoot":"","sources":["../../../src/codeSign/mac/macCodeSign.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAU,yBAAyB,EAAE,eAAe,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAU,cAAc,EAAE,MAAM,cAAc,CAAA;AAE5J,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAC3B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,EAAE,+BAA+B,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACpG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAA;AAEzE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,2BAA2B,EAAE,yBAAyB,EAAE,sCAAsC,EAAE,oCAAoC,CAAC,CAAA;AAe9K,MAAM,UAAU,aAAa,CAAC,WAAW,GAAG,IAAI;IAC9C,IAAI,OAAO,CAAC,Q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AI,CAAC,SAAS,CAAC,eAAe,GAAG,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,eAAe,GAAG,CAAC,CAAC,CAAA;IACnD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAkB,EAAE,SAAyB,EAAE,QAAwB;IAClG,IAAI,QAAQ,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAA;IAChD,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,IAAI,+BAA+B,EAAE,EAAE,CAAC;YACtC,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;QAChD,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC;IACH,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;QAC1B,KAAK,MAAM,MAAM,IAAI,wBAAwB,EAAE,CAAC;YAC9C,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAC/B,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACpD,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,MAAc;IAC/C,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,yBAAyB,CAAC,yBAAyB,MAAM,kFAAkF,CAAC,CAAA;IACxJ,CAAC;AACH,CAAC","sourcesContent":["import type { SignOptions } from \"@electron/osx-sign\"\nimport { sign as _sign } from \"@electron/osx-sign\"\nimport { copyFile, exec, Fields, InvalidConfigurationError, isEmptyOrSpaces, isPullRequest, log, Logger, retry, TmpDir, unlinkIfExists } from \"builder-util\"\nimport { Nullish } from \"builder-util-runtime\"\nimport { createHash, randomBytes } from \"crypto\"\nimport { rename } from \"fs/promises\"\nimport { Lazy } from \"lazy-val\"\nimport { tmpdir } from \"os\"\nimport * as path from \"path\"\nimport { getTempName } from \"temp-file\"\nimport { isAutoDiscoveryCodeSignIdentity, isCscForPullRequest, isTravis } from \"../../util/flags.js\"\nimport { importCertificate } from \"../codesign.js\"\nimport { cacheDirectoryOverrideAllowed } from \"../../util/electronGet.js\"\n\nexport const appleCertificatePrefixes = [\"Developer ID Application:\", \"Developer ID Installer:\", \"3rd Party Mac Developer Application:\", \"3rd Party Mac Developer Installer:\"]\n\nexport type CertType =\n | \"Developer ID Application\"\n | \"Developer ID Installer\"\n | \"3rd Party Mac Developer Application\"\n | \"3rd Party Mac Developer Installer\"\n | \"Mac Developer\"\n | \"Apple Development\"\n | \"Apple Distribution\"\n\nexport interface CodeSigningInfo {\n keychainFile?: string | null\n}\n\nexport function isSignAllowed(isPrintWarn = true): boolean {\n if (process.platform !== \"darwin\") {\n if (isPrintWarn) {\n log.warn({ reason: \"supported only on macOS\" }, \"skipped macOS application code signing\")\n }\n return false\n }\n\n if (isPullRequest()) {\n const buildForPrWarning =\n \"There are serious security concerns with CSC_FOR_PULL_REQUEST=true (see the CircleCI documentation (https://circleci.com/docs/guides/integration/oss/#pass-secrets-to-builds-from-forked-pull-requests) for details)\" +\n \"\\nIf you have SSH keys, sensitive env vars or AWS credentials stored in your project settings and untrusted forks can make pull requests against your repo, then this option isn't for you.\"\n\n if (isCscForPullRequest()) {\n if (isPrintWarn) {\n log.warn(buildForPrWarning)\n }\n } else {\n if (isPrintWarn) {\n // https://github.com/electron-userland/electron-builder/issues/1524\n log.warn(\n \"Current build is a part of pull request, code signing will be skipped.\" + \"\\nSet env CSC_FOR_PULL_REQUEST to true to force code signing.\" + `\\n${buildForPrWarning}`\n )\n }\n return false\n }\n }\n\n return true\n}\n\nexport async function reportError(isMas: boolean, certificateTypes: CertType[], qualifier: string | Nullish, keychainFile: string | Nullish, isForceCodeSigning: boolean) {\n const logFields: Fields = {}\n if (qualifier == null) {\n logFields.reason = \"\"\n if (isAutoDiscoveryCodeSignIdentity()) {\n logFields.reason += `cannot find valid \"${certificateTypes.join(\", \")}\" identity${\n isMas ? \"\" : ` or custom non-Apple code signing certificate, it could cause some undefined behaviour, e.g. macOS localized description not visible`\n }`\n }\n logFields.reason += \", see https://electron.build/docs/features/code-signing\"\n if (!isAutoDiscoveryCodeSignIdentity()) {\n logFields.CSC_IDENTITY_AUTO_DISCOVERY = false\n }\n } else {\n logFields.reason = \"Identity name is specified, but no valid identity with this name in the keychain\"\n logFields.identity = qualifier\n }\n\n const args = [\"find-identity\"]\n if (keychainFile != null) {\n args.push(keychainFile)\n }\n\n if (qualifier != null || isAutoDiscoveryCodeSignIdentity()) {\n logFields.allIdentities = (await exec(\"/usr/bin/security\", args))\n .trim()\n .split(\"\\n\")\n .filter(it => !(it.includes(\"Policy: X.509 Basic\") || it.includes(\"Matching identities\")))\n .join(\"\\n\")\n }\n\n const skipMessage = \"skipped macOS application code signing\"\n if (isMas || isForceCodeSigning) {\n throw new Error(Logger.createMessage(skipMessage, logFields, \"error\", it => it))\n } else {\n log.warn(logFields, skipMessage)\n }\n}\n\n// \"Note that filename will not be searched to resolve the signing identity's certificate chain unless it is also on the user's keychain search list.\"\n// but \"security list-keychains\" doesn't support add - we should 1) get current list 2) set new list - it is very bad http://stackoverflow.com/questions/10538942/add-a-keychain-to-search-list\n// \"overly complicated and introduces a race condition.\"\n// https://github.com/electron-userland/electron-builder/issues/398\nconst bundledCertKeychainAdded = new Lazy<void>(async () => {\n // copy to temp and then atomic rename to final path\n const cacheDir = await cacheDirectoryOverrideAllowed.value\n const tmpKeychainPath = path.join(cacheDir, getTempName(\"electron-builder-root-certs\"))\n const keychainPath = path.join(cacheDir, \"electron-builder-root-certs.keychain\")\n const results = await Promise.all<any>([\n listUserKeychains(),\n copyFile(path.join(import.meta.dirname, \"..\", \"..\", \"..\", \"certs\", \"root_certs.keychain\"), tmpKeychainPath).then(() => rename(tmpKeychainPath, keychainPath)),\n ])\n const list = results[0]\n if (!list.includes(keychainPath)) {\n await exec(\"/usr/bin/security\", [\"list-keychains\", \"-d\", \"user\", \"-s\", keychainPath].concat(list))\n }\n})\n\nfunction listUserKeychains(): Promise<Array<string>> {\n return exec(\"/usr/bin/security\", [\"list-keychains\", \"-d\", \"user\"]).then(it =>\n it\n .split(\"\\n\")\n .map(it => {\n const r = it.trim()\n return r.substring(1, r.length - 1)\n })\n .filter(it => it.length > 0)\n )\n}\n\nexport interface CreateKeychainOptions {\n tmpDir: TmpDir\n cscLink: string\n cscKeyPassword: string\n cscILink?: string | null\n cscIKeyPassword?: string | null\n currentDir: string\n}\n\nexport function removeKeychain(keychainFile: string, printWarn = true): Promise<any> {\n return exec(\"/usr/bin/security\", [\"delete-keychain\", keychainFile]).catch((e: any) => {\n if (printWarn) {\n log.warn({ file: keychainFile, error: e.stack || e }, \"cannot delete keychain\")\n }\n return unlinkIfExists(keychainFile)\n })\n}\n\nexport async function createKeychain({ tmpDir, cscLink, cscKeyPassword, cscILink, cscIKeyPassword, currentDir }: CreateKeychainOptions): Promise<CodeSigningInfo> {\n // travis has correct AppleWWDRCA cert\n if (!isTravis()) {\n await bundledCertKeychainAdded.value\n }\n\n // https://github.com/electron-userland/electron-builder/issues/3685\n // use constant file\n const keychainFile = path.join(process.env.APP_BUILDER_TMP_DIR || tmpdir(), `${createHash(\"sha256\").update(currentDir).update(\"app-builder\").digest(\"hex\")}.keychain`)\n // noinspection JSUnusedLocalSymbols\n\n await removeKeychain(keychainFile, false).catch(_ => {\n /* ignore*/\n })\n\n const certLinks = [cscLink]\n if (cscILink != null) {\n certLinks.push(cscILink)\n }\n\n const certPaths = new Array(certLinks.length)\n const keychainPassword = randomBytes(32).toString(\"base64\")\n const securityCommands = [\n [\"create-keychain\", \"-p\", keychainPassword, keychainFile],\n [\"unlock-keychain\", \"-p\", keychainPassword, keychainFile],\n [\"set-keychain-settings\", keychainFile],\n ]\n\n // https://stackoverflow.com/questions/42484678/codesign-keychain-gets-ignored\n // https://github.com/electron-userland/electron-builder/issues/1457\n const list = await listUserKeychains()\n if (!list.includes(keychainFile)) {\n securityCommands.push([\"list-keychains\", \"-d\", \"user\", \"-s\", keychainFile].concat(list))\n }\n\n // Import all certs in parallel, then run security commands sequentially.\n await Promise.all(certLinks.map((link, i) => importCertificate(link, tmpDir, currentDir).then(it => (certPaths[i] = it))))\n for (const cmd of securityCommands) {\n await exec(\"/usr/bin/security\", cmd)\n }\n const cscPasswords: Array<string> = [cscKeyPassword]\n if (cscIKeyPassword != null) {\n cscPasswords.push(cscIKeyPassword)\n }\n return await importCerts(keychainFile, certPaths, cscPasswords, keychainPassword)\n}\n\nasync function importCerts(keychainFile: string, paths: Array<string>, keyPasswords: Array<string>, keychainPassword: string): Promise<CodeSigningInfo> {\n for (let i = 0; i < paths.length; i++) {\n const password = keyPasswords[i] ?? \"\"\n await exec(\"/usr/bin/security\", [\"import\", paths[i], \"-k\", keychainFile, \"-T\", \"/usr/bin/codesign\", \"-T\", \"/usr/bin/productbuild\", \"-P\", password])\n\n // https://stackoverflow.com/questions/39868578/security-codesign-in-sierra-keychain-ignores-access-control-settings-and-ui-p\n // https://github.com/electron-userland/electron-packager/issues/701#issuecomment-322315996\n // `-k` expects the keychain's own unlock password (as used by create-keychain/unlock-keychain above),\n // not the imported item's password used by `security import -P`.\n await exec(\"/usr/bin/security\", [\"set-key-partition-list\", \"-S\", \"apple-tool:,apple:\", \"-s\", \"-k\", keychainPassword, keychainFile])\n }\n\n return {\n keychainFile,\n }\n}\n\nexport async function sign(opts: SignOptions): Promise<void> {\n return retry(() => _sign(opts), {\n retries: 3,\n interval: 5000,\n backoff: 5000,\n })\n}\n\nexport let findIdentityRawResult: Promise<Array<string>> | null = null\n\n// Discovery of untrusted self-signed identities is OFF in production, and there is intentionally NO env var\n// or build-config option to enable it: an untrusted identity must never be silently accepted in a real\n// build. This in-process flag exists solely as a seam for electron-builder's own signing tests, which\n// provision an ephemeral self-signed cert and flip it via setAllowUntrustedSelfSignedIdentityForTesting().\nlet allowUntrustedSelfSignedIdentity = false\n\n/** @internal Test-only. Enables discovery of untrusted self-signed code-signing identities. Never use in production. */\nexport function setAllowUntrustedSelfSignedIdentityForTesting(value: boolean): void {\n allowUntrustedSelfSignedIdentity = value\n}\n\nasync function getValidIdentities(keychain?: string | null): Promise<Array<string>> {\n function addKeychain(args: Array<string>) {\n if (keychain != null) {\n args.push(keychain)\n }\n return args\n }\n\n let result = findIdentityRawResult\n if (result == null || keychain != null) {\n // https://github.com/electron-userland/electron-builder/issues/481\n // https://github.com/electron-userland/electron-builder/issues/535\n const commands = [\n exec(\"/usr/bin/security\", addKeychain([\"find-identity\", \"-v\"])).then(it =>\n it\n .trim()\n .split(\"\\n\")\n .filter(it => {\n for (const prefix of appleCertificatePrefixes) {\n if (it.includes(prefix)) {\n return true\n }\n }\n return false\n })\n ),\n exec(\"/usr/bin/security\", addKeychain([\"find-identity\", \"-v\", \"-p\", \"codesigning\"])).then(it => it.trim().split(\"\\n\")),\n ]\n\n // Test-only seam: also accept untrusted self-signed identities. `find-identity` without `-v` lists them;\n // trusted identities discovered above still take precedence (they appear first and dupes are de-duped).\n if (allowUntrustedSelfSignedIdentity) {\n commands.push(exec(\"/usr/bin/security\", addKeychain([\"find-identity\"])).then(it => it.trim().split(\"\\n\")))\n }\n\n result = Promise.all<Array<string>>(commands).then(it => {\n const array = it\n .flat()\n .filter(\n it =>\n !it.includes(\"(Missing required extension)\") &&\n !it.includes(\"identities found\") &&\n !it.includes(\"Policy: X.509 Basic\") &&\n !it.includes(\"Matching identities\") &&\n !it.includes(\"Valid identities only\") &&\n !it.includes(\"iPhone \") &&\n !it.includes(\"com.apple.idms.appleid.prd.\")\n )\n // remove 1)\n .map(it => it.substring(it.indexOf(\")\") + 1).trim())\n return Array.from(new Set(array))\n })\n\n if (keychain == null) {\n findIdentityRawResult = result\n }\n }\n return result\n}\n\nasync function _findIdentity(type: CertType, qualifier?: string | null, keychain?: string | null): Promise<Identity | null> {\n // https://github.com/electron-userland/electron-builder/issues/484\n //noinspection SpellCheckingInspection\n const lines = await getValidIdentities(keychain)\n const namePrefix = `${type}:`\n for (const line of lines) {\n if (qualifier != null && !line.includes(qualifier)) {\n continue\n }\n\n if (line.includes(namePrefix)) {\n return parseIdentity(line)\n }\n }\n\n if (type === \"Developer ID Application\") {\n // find non-Apple certificate\n // https://github.com/electron-userland/electron-builder/issues/458\n l: for (const line of lines) {\n if (qualifier != null && !line.includes(qualifier)) {\n continue\n }\n\n if (line.includes(\"Mac Developer:\")) {\n continue\n }\n\n for (const prefix of appleCertificatePrefixes) {\n if (line.includes(prefix)) {\n continue l\n }\n }\n\n return parseIdentity(line)\n }\n }\n return null\n}\n\n// @electron/osx-sign v2 no longer exposes its `Identity` class via the package's public exports, so we own this lightweight equivalent.\nexport class Identity {\n constructor(\n readonly name: string,\n readonly hash?: string\n ) {}\n}\n\nfunction parseIdentity(line: string): Identity {\n const firstQuoteIndex = line.indexOf('\"')\n const name = line.substring(firstQuoteIndex + 1, line.lastIndexOf('\"'))\n const hash = line.substring(0, firstQuoteIndex - 1)\n return new Identity(name, hash)\n}\n\nexport function findIdentity(certType: CertType, qualifier?: string | null, keychain?: string | null): Promise<Identity | null> {\n let identity = qualifier || process.env.CSC_NAME\n if (isEmptyOrSpaces(identity)) {\n if (isAutoDiscoveryCodeSignIdentity()) {\n return _findIdentity(certType, null, keychain)\n } else {\n return Promise.resolve(null)\n }\n } else {\n identity = identity.trim()\n for (const prefix of appleCertificatePrefixes) {\n checkPrefix(identity, prefix)\n }\n return _findIdentity(certType, identity, keychain)\n }\n}\n\nfunction checkPrefix(name: string, prefix: string) {\n if (name.startsWith(prefix)) {\n throw new InvalidConfigurationError(`Please remove prefix \"${prefix}\" from the specified name — appropriate certificate will be chosen automatically`)\n }\n}\n"]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ACH,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;QAC1B,KAAK,MAAM,MAAM,IAAI,wBAAwB,EAAE,CAAC;YAC9C,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAC/B,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACpD,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,MAAc;IAC/C,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,yBAAyB,CAAC,yBAAyB,MAAM,kFAAkF,CAAC,CAAA;IACxJ,CAAC;AACH,CAAC","sourcesContent":["import type { SignOptions } from \"@electron/osx-sign\"\nimport { sign as _sign } from \"@electron/osx-sign\"\nimport { copyFile, exec, Executables, Fields, InvalidConfigurationError, isEmptyOrSpaces, isPullRequest, log, Logger, retry, TmpDir, unlinkIfExists } from \"builder-util\"\nimport { Nullish } from \"builder-util-runtime\"\nimport { createHash, randomBytes } from \"crypto\"\nimport { rename } from \"fs/promises\"\nimport { Lazy } from \"lazy-val\"\nimport { tmpdir } from \"os\"\nimport * as path from \"path\"\nimport { getTempName } from \"temp-file\"\nimport { isAutoDiscoveryCodeSignIdentity, isCscForPullRequest, isTravis } from \"../../util/flags.js\"\nimport { importCertificate } from \"../codesign.js\"\nimport { forceCodeSigningError } from \"../forceCodeSigning.js\"\nimport { cacheDirectoryOverrideAllowed } from \"../../util/electronGet.js\"\n\nexport const appleCertificatePrefixes = [\"Developer ID Application:\", \"Developer ID Installer:\", \"3rd Party Mac Developer Application:\", \"3rd Party Mac Developer Installer:\"]\n\nexport type CertType =\n | \"Developer ID Application\"\n | \"Developer ID Installer\"\n | \"3rd Party Mac Developer Application\"\n | \"3rd Party Mac Developer Installer\"\n | \"Mac Developer\"\n | \"Apple Development\"\n | \"Apple Distribution\"\n\nexport interface CodeSigningInfo {\n keychainFile?: string | null\n}\n\nexport function isSignAllowed(isPrintWarn = true): boolean {\n if (process.platform !== \"darwin\") {\n if (isPrintWarn) {\n log.warn({ reason: \"supported only on macOS\" }, \"skipped macOS application code signing\")\n }\n return false\n }\n\n if (isPullRequest()) {\n const buildForPrWarning =\n \"There are serious security concerns with CSC_FOR_PULL_REQUEST=true (see the CircleCI documentation (https://circleci.com/docs/guides/integration/oss/#pass-secrets-to-builds-from-forked-pull-requests) for details)\" +\n \"\\nIf you have SSH keys, sensitive env vars or AWS credentials stored in your project settings and untrusted forks can make pull requests against your repo, then this option isn't for you.\"\n\n if (isCscForPullRequest()) {\n if (isPrintWarn) {\n log.warn(buildForPrWarning)\n }\n } else {\n if (isPrintWarn) {\n // https://github.com/electron-userland/electron-builder/issues/1524\n log.warn(\n \"Current build is a part of pull request, code signing will be skipped.\" + \"\\nSet env CSC_FOR_PULL_REQUEST to true to force code signing.\" + `\\n${buildForPrWarning}`\n )\n }\n return false\n }\n }\n\n return true\n}\n\n/**\n * The error for a `forceCodeSigning` build that cannot sign `subject` here — the two cases {@link isSignAllowed} skips\n * signing for: a host other than macOS, and a pull-request build without `CSC_FOR_PULL_REQUEST`. `null` when signing\n * is possible. `overrideHint` is the `-c` option that turns `forceCodeSigning` off (see `forceCodeSigningOverrideHint`).\n */\nexport function macSigningUnavailableError(subject: string, overrideHint: string): InvalidConfigurationError | null {\n if (process.platform !== \"darwin\") {\n return forceCodeSigningError(\n `forceCodeSigning is enabled, but ${subject} cannot be code signed or notarized on ${process.platform}: macOS code signing needs a macOS host. ` +\n `Build the macOS targets on macOS, or pass ${overrideHint} to build them unsigned.`\n )\n }\n if (isPullRequest() && !isCscForPullRequest()) {\n return forceCodeSigningError(\n `forceCodeSigning is enabled, but this is a pull-request build (GITHUB_BASE_REF, TRAVIS_PULL_REQUEST, CIRCLE_PULL_REQUEST, BITRISE_PULL_REQUEST or APPVEYOR_PULL_REQUEST_NUMBER is set), ` +\n `where electron-builder does not sign ${subject}. Set CSC_FOR_PULL_REQUEST=true to sign pull-request builds (only if untrusted forks cannot open pull requests, since the build gets your signing credentials), ` +\n `or pass ${overrideHint} for pull-request builds.`\n )\n }\n return null\n}\n\nexport async function reportError(isMas: boolean, certificateTypes: CertType[], qualifier: string | Nullish, keychainFile: string | Nullish, isForceCodeSigning: boolean) {\n const logFields: Fields = {}\n if (qualifier == null) {\n logFields.reason = \"\"\n if (isAutoDiscoveryCodeSignIdentity()) {\n logFields.reason += `cannot find valid \"${certificateTypes.join(\", \")}\" identity${\n isMas ? \"\" : ` or custom non-Apple code signing certificate, it could cause some undefined behaviour, e.g. macOS localized description not visible`\n }`\n }\n logFields.reason += \", see https://electron.build/docs/features/code-signing\"\n if (!isAutoDiscoveryCodeSignIdentity()) {\n logFields.CSC_IDENTITY_AUTO_DISCOVERY = false\n }\n } else {\n logFields.reason = \"Identity name is specified, but no valid identity with this name in the keychain\"\n logFields.identity = qualifier\n }\n\n const args = [\"find-identity\"]\n if (keychainFile != null) {\n args.push(keychainFile)\n }\n\n if (qualifier != null || isAutoDiscoveryCodeSignIdentity()) {\n logFields.allIdentities = (await exec(\"/usr/bin/security\", args))\n .trim()\n .split(\"\\n\")\n .filter(it => !(it.includes(\"Policy: X.509 Basic\") || it.includes(\"Matching identities\")))\n .join(\"\\n\")\n }\n\n const skipMessage = \"skipped macOS application code signing\"\n if (isMas || isForceCodeSigning) {\n throw new Error(Logger.createMessage(skipMessage, logFields, \"error\", it => it))\n } else {\n log.warn(logFields, skipMessage)\n }\n}\n\n// \"Note that filename will not be searched to resolve the signing identity's certificate chain unless it is also on the user's keychain search list.\"\n// but \"security list-keychains\" doesn't support add - we should 1) get current list 2) set new list - it is very bad http://stackoverflow.com/questions/10538942/add-a-keychain-to-search-list\n// \"overly complicated and introduces a race condition.\"\n// https://github.com/electron-userland/electron-builder/issues/398\nconst bundledCertKeychainAdded = new Lazy<void>(async () => {\n // copy to temp and then atomic rename to final path\n const cacheDir = await cacheDirectoryOverrideAllowed.value\n const tmpKeychainPath = path.join(cacheDir, getTempName(\"electron-builder-root-certs\"))\n const keychainPath = path.join(cacheDir, \"electron-builder-root-certs.keychain\")\n const results = await Promise.all<any>([\n listUserKeychains(),\n copyFile(path.join(import.meta.dirname, \"..\", \"..\", \"..\", \"certs\", \"root_certs.keychain\"), tmpKeychainPath).then(() => rename(tmpKeychainPath, keychainPath)),\n ])\n const list = results[0]\n if (!list.includes(keychainPath)) {\n await exec(\"/usr/bin/security\", [\"list-keychains\", \"-d\", \"user\", \"-s\", keychainPath].concat(list))\n }\n})\n\nfunction listUserKeychains(): Promise<Array<string>> {\n return exec(\"/usr/bin/security\", [\"list-keychains\", \"-d\", \"user\"]).then(it =>\n it\n .split(\"\\n\")\n .map(it => {\n const r = it.trim()\n return r.substring(1, r.length - 1)\n })\n .filter(it => it.length > 0)\n )\n}\n\nexport interface CreateKeychainOptions {\n tmpDir: TmpDir\n cscLink: string\n cscKeyPassword: string\n cscILink?: string | null\n cscIKeyPassword?: string | null\n currentDir: string\n}\n\nexport function removeKeychain(keychainFile: string, printWarn = true): Promise<any> {\n return exec(\"/usr/bin/security\", [\"delete-keychain\", keychainFile]).catch((e: any) => {\n if (printWarn) {\n log.warn({ file: keychainFile, error: e.stack || e }, \"cannot delete keychain\")\n }\n return unlinkIfExists(keychainFile)\n })\n}\n\nexport async function createKeychain({ tmpDir, cscLink, cscKeyPassword, cscILink, cscIKeyPassword, currentDir }: CreateKeychainOptions): Promise<CodeSigningInfo> {\n // travis has correct AppleWWDRCA cert\n if (!isTravis()) {\n await bundledCertKeychainAdded.value\n }\n\n // https://github.com/electron-userland/electron-builder/issues/3685\n // use constant file\n const keychainFile = path.join(process.env.APP_BUILDER_TMP_DIR || tmpdir(), `${createHash(\"sha256\").update(currentDir).update(\"app-builder\").digest(\"hex\")}.keychain`)\n // noinspection JSUnusedLocalSymbols\n\n await removeKeychain(keychainFile, false).catch(_ => {\n /* ignore*/\n })\n\n const certLinks = [cscLink]\n if (cscILink != null) {\n certLinks.push(cscILink)\n }\n\n const certPaths = new Array(certLinks.length)\n const keychainPassword = randomBytes(32).toString(\"base64\")\n const securityCommands = [\n [\"create-keychain\", \"-p\", keychainPassword, keychainFile],\n [\"unlock-keychain\", \"-p\", keychainPassword, keychainFile],\n [\"set-keychain-settings\", keychainFile],\n ]\n\n // https://stackoverflow.com/questions/42484678/codesign-keychain-gets-ignored\n // https://github.com/electron-userland/electron-builder/issues/1457\n const list = await listUserKeychains()\n if (!list.includes(keychainFile)) {\n securityCommands.push([\"list-keychains\", \"-d\", \"user\", \"-s\", keychainFile].concat(list))\n }\n\n // Import all certs in parallel, then run security commands sequentially.\n await Promise.all(certLinks.map((link, i) => importCertificate(link, tmpDir, currentDir).then(it => (certPaths[i] = it))))\n for (const cmd of securityCommands) {\n await exec(\"/usr/bin/security\", cmd)\n }\n const cscPasswords: Array<string> = [cscKeyPassword]\n if (cscIKeyPassword != null) {\n cscPasswords.push(cscIKeyPassword)\n }\n return await importCerts(keychainFile, certPaths, cscPasswords, keychainPassword)\n}\n\n/**\n * The programs the imported signing keys may be used by without a prompt (`security import -T`): the codesign and productbuild\n * that electron-builder starts (from `toolsets.executables` or their default locations), and /usr/bin/codesign, which\n * @electron/osx-sign starts by name.\n */\nexport function keychainTrustedApplications(): Array<string> {\n return Array.from(new Set([\"/usr/bin/codesign\", Executables.resolve(\"codesign\"), Executables.resolve(\"productbuild\")]))\n}\n\nasync function importCerts(keychainFile: string, paths: Array<string>, keyPasswords: Array<string>, keychainPassword: string): Promise<CodeSigningInfo> {\n const trustedApplications = keychainTrustedApplications().flatMap(it => [\"-T\", it])\n for (let i = 0; i < paths.length; i++) {\n const password = keyPasswords[i] ?? \"\"\n await exec(\"/usr/bin/security\", [\"import\", paths[i], \"-k\", keychainFile, ...trustedApplications, \"-P\", password])\n\n // https://stackoverflow.com/questions/39868578/security-codesign-in-sierra-keychain-ignores-access-control-settings-and-ui-p\n // https://github.com/electron-userland/electron-packager/issues/701#issuecomment-322315996\n // `-k` expects the keychain's own unlock password (as used by create-keychain/unlock-keychain above),\n // not the imported item's password used by `security import -P`.\n await exec(\"/usr/bin/security\", [\"set-key-partition-list\", \"-S\", \"apple-tool:,apple:\", \"-s\", \"-k\", keychainPassword, keychainFile])\n }\n\n return {\n keychainFile,\n }\n}\n\nexport async function sign(opts: SignOptions): Promise<void> {\n return retry(() => _sign(opts), {\n retries: 3,\n interval: 5000,\n backoff: 5000,\n })\n}\n\nexport let findIdentityRawResult: Promise<Array<string>> | null = null\n\n// Discovery of untrusted self-signed identities is OFF in production, and there is intentionally NO env var\n// or build-config option to enable it: an untrusted identity must never be silently accepted in a real\n// build. This in-process flag exists solely as a seam for electron-builder's own signing tests, which\n// provision an ephemeral self-signed cert and flip it via setAllowUntrustedSelfSignedIdentityForTesting().\nlet allowUntrustedSelfSignedIdentity = false\n\n/** @internal Test-only. Enables discovery of untrusted self-signed code-signing identities. Never use in production. */\nexport function setAllowUntrustedSelfSignedIdentityForTesting(value: boolean): void {\n allowUntrustedSelfSignedIdentity = value\n}\n\nasync function getValidIdentities(keychain?: string | null): Promise<Array<string>> {\n function addKeychain(args: Array<string>) {\n if (keychain != null) {\n args.push(keychain)\n }\n return args\n }\n\n let result = findIdentityRawResult\n if (result == null || keychain != null) {\n // https://github.com/electron-userland/electron-builder/issues/481\n // https://github.com/electron-userland/electron-builder/issues/535\n const commands = [\n exec(\"/usr/bin/security\", addKeychain([\"find-identity\", \"-v\"])).then(it =>\n it\n .trim()\n .split(\"\\n\")\n .filter(it => {\n for (const prefix of appleCertificatePrefixes) {\n if (it.includes(prefix)) {\n return true\n }\n }\n return false\n })\n ),\n exec(\"/usr/bin/security\", addKeychain([\"find-identity\", \"-v\", \"-p\", \"codesigning\"])).then(it => it.trim().split(\"\\n\")),\n ]\n\n // Test-only seam: also accept untrusted self-signed identities. `find-identity` without `-v` lists them;\n // trusted identities discovered above still take precedence (they appear first and dupes are de-duped).\n if (allowUntrustedSelfSignedIdentity) {\n commands.push(exec(\"/usr/bin/security\", addKeychain([\"find-identity\"])).then(it => it.trim().split(\"\\n\")))\n }\n\n result = Promise.all<Array<string>>(commands).then(it => {\n const array = it\n .flat()\n .filter(\n it =>\n !it.includes(\"(Missing required extension)\") &&\n !it.includes(\"identities found\") &&\n !it.includes(\"Policy: X.509 Basic\") &&\n !it.includes(\"Matching identities\") &&\n !it.includes(\"Valid identities only\") &&\n !it.includes(\"iPhone \") &&\n !it.includes(\"com.apple.idms.appleid.prd.\")\n )\n // remove 1)\n .map(it => it.substring(it.indexOf(\")\") + 1).trim())\n return Array.from(new Set(array))\n })\n\n if (keychain == null) {\n findIdentityRawResult = result\n }\n }\n return result\n}\n\nasync function _findIdentity(type: CertType, qualifier?: string | null, keychain?: string | null): Promise<Identity | null> {\n // https://github.com/electron-userland/electron-builder/issues/484\n //noinspection SpellCheckingInspection\n const lines = await getValidIdentities(keychain)\n const namePrefix = `${type}:`\n for (const line of lines) {\n if (qualifier != null && !line.includes(qualifier)) {\n continue\n }\n\n if (line.includes(namePrefix)) {\n return parseIdentity(line)\n }\n }\n\n if (type === \"Developer ID Application\") {\n // find non-Apple certificate\n // https://github.com/electron-userland/electron-builder/issues/458\n l: for (const line of lines) {\n if (qualifier != null && !line.includes(qualifier)) {\n continue\n }\n\n if (line.includes(\"Mac Developer:\")) {\n continue\n }\n\n for (const prefix of appleCertificatePrefixes) {\n if (line.includes(prefix)) {\n continue l\n }\n }\n\n return parseIdentity(line)\n }\n }\n return null\n}\n\n// @electron/osx-sign v2 no longer exposes its `Identity` class via the package's public exports, so we own this lightweight equivalent.\nexport class Identity {\n constructor(\n readonly name: string,\n readonly hash?: string\n ) {}\n}\n\nfunction parseIdentity(line: string): Identity {\n const firstQuoteIndex = line.indexOf('\"')\n const name = line.substring(firstQuoteIndex + 1, line.lastIndexOf('\"'))\n const hash = line.substring(0, firstQuoteIndex - 1)\n return new Identity(name, hash)\n}\n\nexport function findIdentity(certType: CertType, qualifier?: string | null, keychain?: string | null): Promise<Identity | null> {\n let identity = qualifier || process.env.CSC_NAME\n if (isEmptyOrSpaces(identity)) {\n if (isAutoDiscoveryCodeSignIdentity()) {\n return _findIdentity(certType, null, keychain)\n } else {\n return Promise.resolve(null)\n }\n } else {\n identity = identity.trim()\n for (const prefix of appleCertificatePrefixes) {\n checkPrefix(identity, prefix)\n }\n return _findIdentity(certType, identity, keychain)\n }\n}\n\nfunction checkPrefix(name: string, prefix: string) {\n if (name.startsWith(prefix)) {\n throw new InvalidConfigurationError(`Please remove prefix \"${prefix}\" from the specified name — appropriate certificate will be chosen automatically`)\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `codesign --verify` of an app bundle (`deep`) or a single file such as a DMG. `strict` mirrors @electron/osx-sign's
3
+ * `strictVerify`: `true` (the default) adds `--strict`, `false` leaves it out, and a list of option keywords is passed as
4
+ * `--strict=<options>` (an unknown keyword is an `InvalidConfigurationError`). Any valid signature passes, including ad-hoc
5
+ * and self-signed ones.
6
+ */
7
+ export declare function verifyMacCodeSignature(file: string, options: {
8
+ readonly deep: boolean;
9
+ readonly strict?: boolean | string | null;
10
+ }): Promise<string | null>;
11
+ /** `stapler validate`: whether a valid notarization ticket is stapled to the app, pkg or DMG. */
12
+ export declare function validateStapledTicket(file: string): Promise<string | null>;
13
+ /**
14
+ * `pkgutil --check-signature` of an installer package. Any signature counts, including one by an untrusted or expired
15
+ * certificate; only a package without a signature, or with an invalid or revoked one, fails.
16
+ */
17
+ export declare function checkInstallerPackageSignature(pkg: string): Promise<string | null>;
18
+ /**
19
+ * The problem reported by `pkgutil --check-signature` output, or `null` when the package is signed. Decided on the
20
+ * `Status:` line: "no signature", "invalid" and "revoked" fail, any other signed status passes.
21
+ */
22
+ export declare function pkgutilSignatureProblem(output: string): string | null;
23
+ //# sourceMappingURL=macSignatureVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"macSignatureVerifier.d.ts","sourceRoot":"","sources":["../../../src/codeSign/mac/macSignatureVerifier.ts"],"names":[],"mappings":"AAoCA;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWjK;AAED,iGAAiG;AACjG,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAEhF;AAED;;;GAGG;AACH,wBAAsB,8BAA8B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAUxF;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASrE"}
@@ -0,0 +1,96 @@
1
+ import { exec, Executables, InvalidConfigurationError } from "builder-util";
2
+ import { stripVTControlCharacters } from "util";
3
+ /**
4
+ * Read-back checks of macOS signatures, shared by the `forceCodeSigning` build checks and `electron-builder verify`.
5
+ * Each returns `null` when the check passes, or the tool's complaint; none throws on a bad signature. They run Apple's
6
+ * tools, so they work on macOS only. Each tool is started by absolute path, from `toolsets.executables` or its default
7
+ * location (see {@link Executables}); a tool that cannot be located is an `InvalidConfigurationError`, not a complaint.
8
+ */
9
+ /** The option keywords of `codesign --strict=<options>`. */
10
+ const CODESIGN_STRICT_OPTIONS = { all: "all", symlinks: "symlinks", sideband: "sideband" };
11
+ /**
12
+ * The `--strict` argument for `strictVerify`: `true` is `--strict`, `false` none, and a string a comma-separated list of
13
+ * {@link CODESIGN_STRICT_OPTIONS}, which is rebuilt from those keywords so that no configuration text reaches the command line.
14
+ */
15
+ function codesignStrictArgument(strict) {
16
+ if (strict === false) {
17
+ return null;
18
+ }
19
+ if (strict === true) {
20
+ return "--strict";
21
+ }
22
+ const options = strict.split(",").map(it => {
23
+ const keyword = it.trim();
24
+ if (!Object.prototype.hasOwnProperty.call(CODESIGN_STRICT_OPTIONS, keyword)) {
25
+ throw new InvalidConfigurationError(`mac.sign.strictVerify has ${JSON.stringify(strict)}, but codesign --strict accepts only true, false or a comma-separated list of ${Object.keys(CODESIGN_STRICT_OPTIONS).join(", ")}`);
26
+ }
27
+ return CODESIGN_STRICT_OPTIONS[keyword];
28
+ });
29
+ return `--strict=${options.join(",")}`;
30
+ }
31
+ /**
32
+ * `codesign --verify` of an app bundle (`deep`) or a single file such as a DMG. `strict` mirrors @electron/osx-sign's
33
+ * `strictVerify`: `true` (the default) adds `--strict`, `false` leaves it out, and a list of option keywords is passed as
34
+ * `--strict=<options>` (an unknown keyword is an `InvalidConfigurationError`). Any valid signature passes, including ad-hoc
35
+ * and self-signed ones.
36
+ */
37
+ export async function verifyMacCodeSignature(file, options) {
38
+ const args = ["--verify"];
39
+ if (options.deep) {
40
+ args.push("--deep");
41
+ }
42
+ const strict = codesignStrictArgument(options.strict ?? true);
43
+ if (strict != null) {
44
+ args.push(strict);
45
+ }
46
+ args.push("--verbose=2", file);
47
+ return await toolProblem(Executables.resolve("codesign"), args);
48
+ }
49
+ /** `stapler validate`: whether a valid notarization ticket is stapled to the app, pkg or DMG. */
50
+ export async function validateStapledTicket(file) {
51
+ return await toolProblem(await Executables.stapler(), ["validate", file]);
52
+ }
53
+ /**
54
+ * `pkgutil --check-signature` of an installer package. Any signature counts, including one by an untrusted or expired
55
+ * certificate; only a package without a signature, or with an invalid or revoked one, fails.
56
+ */
57
+ export async function checkInstallerPackageSignature(pkg) {
58
+ const pkgutil = Executables.resolve("pkgutil");
59
+ let output;
60
+ try {
61
+ output = await exec(pkgutil, ["--check-signature", pkg], undefined, false);
62
+ }
63
+ catch (e) {
64
+ // pkgutil exits non-zero for some signed statuses too, so the decision is made on its Status line
65
+ output = errorText(e);
66
+ }
67
+ return pkgutilSignatureProblem(output);
68
+ }
69
+ /**
70
+ * The problem reported by `pkgutil --check-signature` output, or `null` when the package is signed. Decided on the
71
+ * `Status:` line: "no signature", "invalid" and "revoked" fail, any other signed status passes.
72
+ */
73
+ export function pkgutilSignatureProblem(output) {
74
+ const status = /Status:\s*(.+)/.exec(output)?.[1]?.trim();
75
+ if (status == null) {
76
+ return `pkgutil --check-signature reported no signature status: ${output.trim()}`;
77
+ }
78
+ if (!status.startsWith("signed") || /\b(invalid|revoked)\b/i.test(status)) {
79
+ return `pkgutil --check-signature: ${status}`;
80
+ }
81
+ return null;
82
+ }
83
+ async function toolProblem(file, args) {
84
+ try {
85
+ await exec(file, args, undefined, false);
86
+ return null;
87
+ }
88
+ catch (e) {
89
+ return errorText(e);
90
+ }
91
+ }
92
+ /** The message of a failed `exec` (which embeds the tool's output) without terminal colors. */
93
+ function errorText(e) {
94
+ return stripVTControlCharacters(String(e?.message ?? e)).trim();
95
+ }
96
+ //# sourceMappingURL=macSignatureVerifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"macSignatureVerifier.js","sourceRoot":"","sources":["../../../src/codeSign/mac/macSignatureVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,MAAM,CAAA;AAE/C;;;;;GAKG;AAEH,4DAA4D;AAC5D,MAAM,uBAAuB,GAAqC,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAA;AAE5H;;;GAGG;AACH,SAAS,sBAAsB,CAAC,MAAwB;IACtD,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAA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AAA;IACrB,CAAC;AACH,CAAC;AAED,+FAA+F;AAC/F,SAAS,SAAS,CAAC,CAAM;IACvB,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;AACjE,CAAC","sourcesContent":["import { exec, Executables, InvalidConfigurationError } from \"builder-util\"\nimport { stripVTControlCharacters } from \"util\"\n\n/**\n * Read-back checks of macOS signatures, shared by the `forceCodeSigning` build checks and `electron-builder verify`.\n * Each returns `null` when the check passes, or the tool's complaint; none throws on a bad signature. They run Apple's\n * tools, so they work on macOS only. Each tool is started by absolute path, from `toolsets.executables` or its default\n * location (see {@link Executables}); a tool that cannot be located is an `InvalidConfigurationError`, not a complaint.\n */\n\n/** The option keywords of `codesign --strict=<options>`. */\nconst CODESIGN_STRICT_OPTIONS: Readonly<Record<string, string>> = { all: \"all\", symlinks: \"symlinks\", sideband: \"sideband\" }\n\n/**\n * The `--strict` argument for `strictVerify`: `true` is `--strict`, `false` none, and a string a comma-separated list of\n * {@link CODESIGN_STRICT_OPTIONS}, which is rebuilt from those keywords so that no configuration text reaches the command line.\n */\nfunction codesignStrictArgument(strict: boolean | string): string | null {\n if (strict === false) {\n return null\n }\n if (strict === true) {\n return \"--strict\"\n }\n const options = strict.split(\",\").map(it => {\n const keyword = it.trim()\n if (!Object.prototype.hasOwnProperty.call(CODESIGN_STRICT_OPTIONS, keyword)) {\n throw new InvalidConfigurationError(\n `mac.sign.strictVerify has ${JSON.stringify(strict)}, but codesign --strict accepts only true, false or a comma-separated list of ${Object.keys(CODESIGN_STRICT_OPTIONS).join(\", \")}`\n )\n }\n return CODESIGN_STRICT_OPTIONS[keyword]\n })\n return `--strict=${options.join(\",\")}`\n}\n\n/**\n * `codesign --verify` of an app bundle (`deep`) or a single file such as a DMG. `strict` mirrors @electron/osx-sign's\n * `strictVerify`: `true` (the default) adds `--strict`, `false` leaves it out, and a list of option keywords is passed as\n * `--strict=<options>` (an unknown keyword is an `InvalidConfigurationError`). Any valid signature passes, including ad-hoc\n * and self-signed ones.\n */\nexport async function verifyMacCodeSignature(file: string, options: { readonly deep: boolean; readonly strict?: boolean | string | null }): Promise<string | null> {\n const args = [\"--verify\"]\n if (options.deep) {\n args.push(\"--deep\")\n }\n const strict = codesignStrictArgument(options.strict ?? true)\n if (strict != null) {\n args.push(strict)\n }\n args.push(\"--verbose=2\", file)\n return await toolProblem(Executables.resolve(\"codesign\"), args)\n}\n\n/** `stapler validate`: whether a valid notarization ticket is stapled to the app, pkg or DMG. */\nexport async function validateStapledTicket(file: string): Promise<string | null> {\n return await toolProblem(await Executables.stapler(), [\"validate\", file])\n}\n\n/**\n * `pkgutil --check-signature` of an installer package. Any signature counts, including one by an untrusted or expired\n * certificate; only a package without a signature, or with an invalid or revoked one, fails.\n */\nexport async function checkInstallerPackageSignature(pkg: string): Promise<string | null> {\n const pkgutil = Executables.resolve(\"pkgutil\")\n let output: string\n try {\n output = await exec(pkgutil, [\"--check-signature\", pkg], undefined, false)\n } catch (e: any) {\n // pkgutil exits non-zero for some signed statuses too, so the decision is made on its Status line\n output = errorText(e)\n }\n return pkgutilSignatureProblem(output)\n}\n\n/**\n * The problem reported by `pkgutil --check-signature` output, or `null` when the package is signed. Decided on the\n * `Status:` line: \"no signature\", \"invalid\" and \"revoked\" fail, any other signed status passes.\n */\nexport function pkgutilSignatureProblem(output: string): string | null {\n const status = /Status:\\s*(.+)/.exec(output)?.[1]?.trim()\n if (status == null) {\n return `pkgutil --check-signature reported no signature status: ${output.trim()}`\n }\n if (!status.startsWith(\"signed\") || /\\b(invalid|revoked)\\b/i.test(status)) {\n return `pkgutil --check-signature: ${status}`\n }\n return null\n}\n\nasync function toolProblem(file: string, args: Array<string>): Promise<string | null> {\n try {\n await exec(file, args, undefined, false)\n return null\n } catch (e: any) {\n return errorText(e)\n }\n}\n\n/** The message of a failed `exec` (which embeds the tool's output) without terminal colors. */\nfunction errorText(e: any): string {\n return stripVTControlCharacters(String(e?.message ?? e)).trim()\n}\n"]}
@@ -40,12 +40,24 @@ export type AuthenticodeSignerReader = (file: string) => Promise<AuthenticodeSig
40
40
  * the PE certificate table and its PKCS#7 signature directly (no external tool needed).
41
41
  */
42
42
  export declare function readAuthenticodeSigner(file: string): Promise<AuthenticodeSignerInfo>;
43
+ /** Whether `file` is a type whose Authenticode signature can be read back (see `AUTHENTICODE_FILE_EXTENSIONS`). */
44
+ export declare function isAuthenticodeFileType(file: string): boolean;
45
+ /**
46
+ * Why a signature read back with {@link readAuthenticodeSigner} does not count as valid, or `null` when it does. Any
47
+ * status but `HashMismatch` is accepted: the build host may not trust the signing chain that the users' machines
48
+ * trust, and the reader used off Windows reports no status at all.
49
+ */
50
+ export declare function authenticodeSignatureProblem(signer: AuthenticodeSignerInfo): string | null;
43
51
  /**
44
52
  * Reads the signer with `Get-AuthenticodeSignature`, with the helpers electron-updater verifies downloaded updates
45
- * with (builder-util-runtime: the same PowerShell invocation, path escaping and JSON parsing), so the build sees
46
- * exactly what the updater will see.
53
+ * with (builder-util-runtime: the same PowerShell invocation and JSON parsing), so the build sees exactly what the
54
+ * updater will see. Windows PowerShell is started from `toolsets.executables.powershell` or its default location, with
55
+ * the build's credential variables (signing passwords, tokens, keys) removed from its environment: reading a signature
56
+ * needs none of them.
47
57
  */
48
58
  export declare function readAuthenticodeSignerWithPowerShell(file: string): Promise<AuthenticodeSignerInfo>;
59
+ /** Quotes an RDN value the way Windows does when it formats a certificate subject (see {@link formatWindowsSubjectDn}). */
60
+ export declare function quoteWindowsDnValue(value: string): string;
49
61
  /**
50
62
  * Formats a certificate name the way Windows reports a certificate subject (`X509Certificate2.Subject`, which
51
63
  * electron-updater compares the configured publisher names against): RDNs in reverse encoding order separated by
@@ -1 +1 @@
1
- {"version":3,"file":"authenticodeSignature.d.ts","sourceRoot":"","sources":["../../../src/codeSign/win/authenticodeSignature.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9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AC,CAoClG;AAoDD,2HAA2H;AAC3H,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,0BAA0B,GAAG,MAAM,CAQrF;AAiBD;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA8CjH;AAQD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAyB1D;AAED,sGAAsG;AACtG,wBAAsB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAalG"}
@@ -1,7 +1,9 @@
1
1
  import * as asn1js from "asn1js";
2
- import { escapePowerShellSingleQuotes, parseAuthenticodeSignatureOutput, preparePowerShellExec } from "builder-util-runtime";
2
+ import { Executables, stripSensitiveEnvVars } from "builder-util";
3
+ import { parseAuthenticodeSignatureOutput, prepareAuthenticodeSignatureExec } from "builder-util-runtime";
3
4
  import { execFile } from "child_process";
4
5
  import { open } from "fs/promises";
6
+ import * as path from "path";
5
7
  import * as pkijs from "pkijs";
6
8
  /**
7
9
  * Values of `System.Management.Automation.SignatureStatus`. `ConvertTo-Json` serializes the enum as its numeric
@@ -36,42 +38,87 @@ export function authenticodeSignatureStatusName(status) {
36
38
  export function readAuthenticodeSigner(file) {
37
39
  return process.platform === "win32" ? readAuthenticodeSignerWithPowerShell(file) : readEmbeddedAuthenticodeSigner(file);
38
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
+ }
39
62
  // ─── Windows: Get-AuthenticodeSignature ──────────────────────────────────────
40
63
  /**
41
64
  * Reads the signer with `Get-AuthenticodeSignature`, with the helpers electron-updater verifies downloaded updates
42
- * with (builder-util-runtime: the same PowerShell invocation, path escaping and JSON parsing), so the build sees
43
- * exactly what the updater will see.
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.
44
69
  */
45
70
  export function readAuthenticodeSignerWithPowerShell(file) {
46
- const escapedFile = escapePowerShellSingleQuotes(file);
47
71
  return new Promise(resolve => {
48
- // longer than the updater's 20s: a busy build machine may still be preparing the PowerShell modules on first use,
49
- // and a timeout here fails the build
50
- execFile(...preparePowerShellExec(`Get-AuthenticodeSignature -LiteralPath '${escapedFile}' | ConvertTo-Json -Compress`, 60 * 1000), (error, stdout, stderr) => {
51
- if (error != null) {
52
- const stderrText = String(stderr ?? "").trim();
53
- resolve({ type: "unreadable", reason: `Get-AuthenticodeSignature failed: ${error.message}${stderrText.length > 0 ? `\n${stderrText}` : ""}` });
54
- return;
55
- }
56
- let data;
57
- try {
58
- data = parseAuthenticodeSignatureOutput(stdout);
59
- }
60
- catch (e) {
61
- resolve({ type: "unreadable", reason: `cannot parse Get-AuthenticodeSignature output (${e.message}): ${stdout}` });
62
- return;
63
- }
64
- const status = getProperty(data, "Status");
65
- const numericStatus = typeof status === "number" ? status : null;
66
- const subject = getProperty(getProperty(data, "SignerCertificate"), "Subject");
67
- if (typeof subject !== "string") {
68
- resolve({ type: "unsigned", reason: `Get-AuthenticodeSignature reports no signer certificate (status: ${authenticodeSignatureStatusName(numericStatus)})` });
69
- return;
70
- }
71
- resolve({ type: "signed", subject, status: numericStatus });
72
- });
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
+ }
73
107
  });
74
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
+ }
75
122
  function getProperty(value, name) {
76
123
  return value != null && typeof value === "object" && name in value ? Reflect.get(value, name) : undefined;
77
124
  }
@@ -104,7 +151,8 @@ const WINDOWS_ATTRIBUTE_TYPE_NAMES = {
104
151
  // Windows quotes an RDN value that has leading/trailing white space or contains one of these characters,
105
152
  // doubling embedded quotes.
106
153
  const NEEDS_WINDOWS_DN_QUOTING = /[,+="\n<>#;]/;
107
- function quoteWindowsDnValue(value) {
154
+ /** Quotes an RDN value the way Windows does when it formats a certificate subject (see {@link formatWindowsSubjectDn}). */
155
+ export function quoteWindowsDnValue(value) {
108
156
  if (value.length === 0 || value !== value.trim() || NEEDS_WINDOWS_DN_QUOTING.test(value)) {
109
157
  return `"${value.replace(/"/g, '""')}"`;
110
158
  }