app-builder-lib 26.0.0-alpha.8 → 26.0.0
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.
- package/out/asar/asarUtil.js +14 -3
- package/out/asar/asarUtil.js.map +1 -1
- package/out/asar/integrity.d.ts +4 -1
- package/out/asar/integrity.js +37 -8
- package/out/asar/integrity.js.map +1 -1
- package/out/codeSign/windowsCodeSign.d.ts +0 -2
- package/out/codeSign/windowsCodeSign.js +1 -33
- package/out/codeSign/windowsCodeSign.js.map +1 -1
- package/out/codeSign/windowsSignAzureManager.js +2 -3
- package/out/codeSign/windowsSignAzureManager.js.map +1 -1
- package/out/codeSign/windowsSignToolManager.js +13 -17
- package/out/codeSign/windowsSignToolManager.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js.map +1 -1
- package/out/macPackager.d.ts +3 -3
- package/out/macPackager.js +24 -13
- package/out/macPackager.js.map +1 -1
- package/out/options/AppXOptions.d.ts +26 -0
- package/out/options/AppXOptions.js.map +1 -1
- package/out/options/FileAssociation.d.ts +1 -1
- package/out/options/FileAssociation.js.map +1 -1
- package/out/options/macOptions.d.ts +3 -10
- package/out/options/macOptions.js.map +1 -1
- package/out/options/winOptions.d.ts +2 -62
- package/out/options/winOptions.js.map +1 -1
- package/out/platformPackager.d.ts +15 -1
- package/out/platformPackager.js +27 -8
- package/out/platformPackager.js.map +1 -1
- package/out/targets/AppxTarget.js +6 -1
- package/out/targets/AppxTarget.js.map +1 -1
- package/out/targets/FpmTarget.js +1 -1
- package/out/targets/FpmTarget.js.map +1 -1
- package/out/targets/nsis/NsisTarget.d.ts +4 -3
- package/out/targets/nsis/NsisTarget.js +23 -10
- package/out/targets/nsis/NsisTarget.js.map +1 -1
- package/out/targets/nsis/WebInstallerTarget.d.ts +3 -1
- package/out/targets/nsis/WebInstallerTarget.js +8 -2
- package/out/targets/nsis/WebInstallerTarget.js.map +1 -1
- package/out/targets/nsis/nsisOptions.d.ts +6 -0
- package/out/targets/nsis/nsisOptions.js.map +1 -1
- package/out/version.d.ts +1 -1
- package/out/version.js +1 -1
- package/out/version.js.map +1 -1
- package/out/vm/PwshVm.d.ts +6 -0
- package/out/vm/PwshVm.js +25 -0
- package/out/vm/PwshVm.js.map +1 -0
- package/out/vm/vm.d.ts +4 -0
- package/out/vm/vm.js +42 -3
- package/out/vm/vm.js.map +1 -1
- package/out/winPackager.js +4 -5
- package/out/winPackager.js.map +1 -1
- package/package.json +9 -9
- package/scheme.json +21 -142
package/out/asar/asarUtil.js
CHANGED
|
@@ -65,11 +65,11 @@ class AsarPackager {
|
|
|
65
65
|
const createdSourceDirs = new Set();
|
|
66
66
|
const links = [];
|
|
67
67
|
const symlinkType = (0, os_1.platform)() === "win32" ? "junction" : "file";
|
|
68
|
-
const matchUnpacker = (file, dest, stat) => {
|
|
68
|
+
const matchUnpacker = (file, dest, stat, tmpUnpackedPaths) => {
|
|
69
69
|
var _a, _b;
|
|
70
70
|
if ((_b = (_a = this.config).unpackPattern) === null || _b === void 0 ? void 0 : _b.call(_a, file, stat)) {
|
|
71
71
|
builder_util_1.log.debug({ file }, "unpacking");
|
|
72
|
-
|
|
72
|
+
tmpUnpackedPaths.add(dest);
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
};
|
|
@@ -111,18 +111,29 @@ class AsarPackager {
|
|
|
111
111
|
(0, unpackDetector_1.detectUnpackedDirs)(fileSet, unpackedPaths);
|
|
112
112
|
}
|
|
113
113
|
// Don't use BluebirdPromise, we need to retain order of execution/iteration through the ordered fileset
|
|
114
|
+
const tmpUnpackedPaths = new Set();
|
|
114
115
|
for (let i = 0; i < fileSet.files.length; i++) {
|
|
115
116
|
const file = fileSet.files[i];
|
|
116
117
|
const transformedData = (_a = fileSet.transformedFiles) === null || _a === void 0 ? void 0 : _a.get(i);
|
|
117
118
|
const stat = fileSet.metadata.get(file);
|
|
118
119
|
const relative = path.relative(this.config.defaultDestination, (0, appFileCopier_1.getDestinationPath)(file, fileSet));
|
|
119
120
|
const destination = path.resolve(this.rootForAppFilesWithoutAsar, relative);
|
|
120
|
-
matchUnpacker(file, destination, stat);
|
|
121
|
+
matchUnpacker(file, destination, stat, tmpUnpackedPaths);
|
|
121
122
|
taskManager.addTask(writeFileOrProcessSymlink({ transformedData, file, destination, stat, fileSet }));
|
|
122
123
|
if (taskManager.tasks.length > fs_1.MAX_FILE_REQUESTS) {
|
|
123
124
|
await taskManager.awaitTasks();
|
|
124
125
|
}
|
|
125
126
|
}
|
|
127
|
+
if (tmpUnpackedPaths.size === fileSet.files.length) {
|
|
128
|
+
const relative = path.relative(this.config.defaultDestination, fileSet.destination);
|
|
129
|
+
unpackedPaths.add(relative);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// add all tmpUnpackedPaths to unpackedPaths
|
|
133
|
+
for (const it of tmpUnpackedPaths) {
|
|
134
|
+
unpackedPaths.add(it);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
126
137
|
}
|
|
127
138
|
// finish copy then set up all symlinks
|
|
128
139
|
await taskManager.awaitTasks();
|
package/out/asar/asarUtil.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asarUtil.js","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":";;;AAAA,yCAAwE;AACxE,+CAAoD;AAEpD,4CAAiF;AACjF,+BAA8B;AAC9B,uCAAmD;AACnD,2BAA6B;AAC7B,6BAA4B;AAI5B,yDAA2E;AAC3E,qDAAqD;AAErD,gBAAgB;AAChB,MAAa,YAAY;IAOvB,YACW,QAA+B,EACvB,MAKhB;QANQ,aAAQ,GAAR,QAAQ,CAAuB;QACvB,WAAM,GAAN,MAAM,CAKtB;QAXc,eAAU,GAAG,IAAI,eAAU,EAAE,CAAA;QAa5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;QACzD,IAAI,CAAC,MAAM,G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AE,EAAE,CAAC;YACjE,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QAClC,CAAC;QAED,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YACzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;gBACpC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,+BAA+B,CAAC,CAAA;YACzE,CAAC;YAED,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;IAED,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAE9C,OAAO;QACL,GAAG;QACH,WAAW;QACX,QAAQ;QACR,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;QAChD,gBAAgB;KACjB,CAAA;AACH,CAAC","sourcesContent":["import { CreateOptions, createPackageWithOptions } from \"@electron/asar\"\nimport { AsyncTaskManager, log } from \"builder-util\"\nimport { CancellationToken } from \"builder-util-runtime\"\nimport { FileCopier, Filter, Link, MAX_FILE_REQUESTS } from \"builder-util/out/fs\"\nimport * as fs from \"fs-extra\"\nimport { mkdir, readlink, symlink } from \"fs-extra\"\nimport { platform } from \"os\"\nimport * as path from \"path\"\nimport * as tempFile from \"temp-file\"\nimport { AsarOptions } from \"../options/PlatformSpecificBuildOptions\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { ResolvedFileSet, getDestinationPath } from \"../util/appFileCopier\"\nimport { detectUnpackedDirs } from \"./unpackDetector\"\n\n/** @internal */\nexport class AsarPackager {\n private readonly outFile: string\n private rootForAppFilesWithoutAsar!: string\n private readonly fileCopier = new FileCopier()\n private readonly tmpDir: tempFile.TmpDir\n private readonly cancellationToken: CancellationToken\n\n constructor(\n readonly packager: PlatformPackager<any>,\n private readonly config: {\n defaultDestination: string\n resourcePath: string\n options: AsarOptions\n unpackPattern: Filter | undefined\n }\n ) {\n this.outFile = path.join(config.resourcePath, `app.asar`)\n this.tmpDir = packager.info.tempDirManager\n this.cancellationToken = packager.info.cancellationToken\n }\n\n async pack(fileSets: Array<ResolvedFileSet>) {\n this.rootForAppFilesWithoutAsar = await this.tmpDir.getTempDir({ prefix: \"asar-app\" })\n\n const orderedFileSets = [\n // Write dependencies first to minimize offset changes to asar header\n ...fileSets.slice(1),\n\n // Finish with the app files that change most often\n fileSets[0],\n ].map(orderFileSet)\n\n const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets)\n const unpackGlob = unpackedPaths.length > 1 ? `{${unpackedPaths.join(\",\")}}` : unpackedPaths.pop()\n\n await this.executeElectronAsar(copiedFiles, unpackGlob)\n }\n\n private async executeElectronAsar(copiedFiles: string[], unpackGlob: string | undefined) {\n let ordering = this.config.options.ordering || undefined\n if (!ordering) {\n // `copiedFiles` are already ordered due to `orderedFileSets` input, so we just map to their relative paths (via substring) within the asar.\n const filesSorted = copiedFiles.map(file => file.substring(this.rootForAppFilesWithoutAsar.length))\n ordering = await this.tmpDir.getTempFile({ prefix: \"asar-ordering\", suffix: \".txt\" })\n await fs.writeFile(ordering, filesSorted.join(\"\\n\"))\n }\n\n const options: CreateOptions = {\n unpack: unpackGlob,\n unpackDir: unpackGlob,\n ordering,\n dot: true,\n }\n // override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)\n const consoleLogger = console.log\n console.log = (...args) => {\n if (args[0] === \"Ordering file has 100% coverage.\") {\n return // no need to log, this means our ordering logic is working correctly\n }\n log.info({ args }, \"logging @electron/asar\")\n }\n await createPackageWithOptions(this.rootForAppFilesWithoutAsar, this.outFile, options)\n console.log = consoleLogger\n }\n\n private async detectAndCopy(fileSets: ResolvedFileSet[]) {\n const taskManager = new AsyncTaskManager(this.cancellationToken)\n const unpackedPaths = new Set<string>()\n const copiedFiles = new Set<string>()\n\n const createdSourceDirs = new Set<string>()\n const links: Array<Link> = []\n const symlinkType = platform() === \"win32\" ? \"junction\" : \"file\"\n\n const matchUnpacker = (file: string, dest: string, stat: fs.Stats) => {\n if (this.config.unpackPattern?.(file, stat)) {\n log.debug({ file }, \"unpacking\")\n unpackedPaths.add(dest)\n return\n }\n }\n const writeFileOrProcessSymlink = async (options: {\n file: string\n destination: string\n stat: fs.Stats\n fileSet: ResolvedFileSet\n transformedData: string | Buffer | undefined\n }) => {\n const { transformedData, file, destination, stat, fileSet } = options\n if (!stat.isFile() && !stat.isSymbolicLink()) {\n return\n }\n copiedFiles.add(destination)\n\n const dir = path.dirname(destination)\n if (!createdSourceDirs.has(dir)) {\n await mkdir(dir, { recursive: true })\n createdSourceDirs.add(dir)\n }\n\n // write any data if provided, skip symlink check\n if (transformedData != null) {\n return fs.writeFile(destination, transformedData, { mode: stat.mode })\n }\n\n const realPathFile = await fs.realpath(file)\n const realPathRelative = path.relative(fileSet.src, realPathFile)\n const isOutsidePackage = realPathRelative.startsWith(\"..\")\n if (isOutsidePackage) {\n log.error({ source: log.filePath(file), realPathFile: log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`)\n throw new Error(`Cannot copy file (${path.basename(file)}) symlinked to file (${path.basename(realPathFile)}) outside the package as that violates asar security integrity`)\n }\n\n // not a symlink, copy directly\n if (file === realPathFile) {\n return this.fileCopier.copy(file, destination, stat)\n }\n\n // okay, it must be a symlink. evaluate link to be relative to source file in asar\n let link = await readlink(file)\n if (path.isAbsolute(link)) {\n link = path.relative(path.dirname(file), link)\n }\n links.push({ file: destination, link })\n }\n\n for (const fileSet of fileSets) {\n if (this.config.options.smartUnpack !== false) {\n detectUnpackedDirs(fileSet, unpackedPaths)\n }\n\n // Don't use BluebirdPromise, we need to retain order of execution/iteration through the ordered fileset\n for (let i = 0; i < fileSet.files.length; i++) {\n const file = fileSet.files[i]\n const transformedData = fileSet.transformedFiles?.get(i)\n const stat = fileSet.metadata.get(file)!\n\n const relative = path.relative(this.config.defaultDestination, getDestinationPath(file, fileSet))\n const destination = path.resolve(this.rootForAppFilesWithoutAsar, relative)\n\n matchUnpacker(file, destination, stat)\n taskManager.addTask(writeFileOrProcessSymlink({ transformedData, file, destination, stat, fileSet }))\n\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n }\n }\n // finish copy then set up all symlinks\n await taskManager.awaitTasks()\n for (const it of links) {\n taskManager.addTask(symlink(it.link, it.file, symlinkType))\n\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n }\n await taskManager.awaitTasks()\n return {\n unpackedPaths: Array.from(unpackedPaths),\n copiedFiles: Array.from(copiedFiles),\n }\n }\n}\n\nfunction orderFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {\n const sortedFileEntries = Array.from(fileSet.files.entries())\n\n sortedFileEntries.sort(([, a], [, b]) => {\n if (a === b) {\n return 0\n }\n\n // Place addons last because their signature changes per build\n const isAAddon = a.endsWith(\".node\")\n const isBAddon = b.endsWith(\".node\")\n if (isAAddon && !isBAddon) {\n return 1\n }\n if (isBAddon && !isAAddon) {\n return -1\n }\n\n // Otherwise order by name\n return a < b ? -1 : 1\n })\n\n let transformedFiles: Map<number, string | Buffer> | undefined\n if (fileSet.transformedFiles) {\n transformedFiles = new Map()\n\n const indexMap = new Map<number, number>()\n for (const [newIndex, [oldIndex]] of sortedFileEntries.entries()) {\n indexMap.set(oldIndex, newIndex)\n }\n\n for (const [oldIndex, value] of fileSet.transformedFiles) {\n const newIndex = indexMap.get(oldIndex)\n if (newIndex === undefined) {\n const file = fileSet.files[oldIndex]\n throw new Error(`Internal error: ${file} was lost while ordering asar`)\n }\n\n transformedFiles.set(newIndex, value)\n }\n }\n\n const { src, destination, metadata } = fileSet\n\n return {\n src,\n destination,\n metadata,\n files: sortedFileEntries.map(([, file]) => file),\n transformedFiles,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"asarUtil.js","sourceRoot":"","sources":["../../src/asar/asarUtil.ts"],"names":[],"mappings":";;;AAAA,yCAAwE;AACxE,+CAAoD;AAEpD,4CAAiF;AACjF,+BAA8B;AAC9B,uCAAmD;AACnD,2BAA6B;AAC7B,6BAA4B;AAI5B,yDAA2E;AAC3E,qDAAqD;AAErD,gBAAgB;AAChB,MAAa,YAAY;IAOvB,YACW,QAA+B,EACvB,MAKhB;QANQ,aAAQ,GAAR,QAAQ,CAAuB;QACvB,WAAM,GAAN,MAAM,CAKtB;QAXc,eAAU,GAAG,IAAI,eAAU,EAAE,CAAA;QAa5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;QACzD,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAA;QAC1C,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAA;IAC1D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAgC;QACzC,IAAI,CAAC,0BAA0B,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;QAEtF,MAAM,eAAe,GAAG;YACtB,qEAAqE;YACrE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YAEpB,mDAAmD;YACnD,QAAQ,CAAC,CAAC,CAAC;SACZ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAEnB,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAA;QAChF,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,GA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K,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YACzD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;gBACpC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,+BAA+B,CAAC,CAAA;YACzE,CAAC;YAED,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;IAED,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAE9C,OAAO;QACL,GAAG;QACH,WAAW;QACX,QAAQ;QACR,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;QAChD,gBAAgB;KACjB,CAAA;AACH,CAAC","sourcesContent":["import { CreateOptions, createPackageWithOptions } from \"@electron/asar\"\nimport { AsyncTaskManager, log } from \"builder-util\"\nimport { CancellationToken } from \"builder-util-runtime\"\nimport { FileCopier, Filter, Link, MAX_FILE_REQUESTS } from \"builder-util/out/fs\"\nimport * as fs from \"fs-extra\"\nimport { mkdir, readlink, symlink } from \"fs-extra\"\nimport { platform } from \"os\"\nimport * as path from \"path\"\nimport * as tempFile from \"temp-file\"\nimport { AsarOptions } from \"../options/PlatformSpecificBuildOptions\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { ResolvedFileSet, getDestinationPath } from \"../util/appFileCopier\"\nimport { detectUnpackedDirs } from \"./unpackDetector\"\n\n/** @internal */\nexport class AsarPackager {\n private readonly outFile: string\n private rootForAppFilesWithoutAsar!: string\n private readonly fileCopier = new FileCopier()\n private readonly tmpDir: tempFile.TmpDir\n private readonly cancellationToken: CancellationToken\n\n constructor(\n readonly packager: PlatformPackager<any>,\n private readonly config: {\n defaultDestination: string\n resourcePath: string\n options: AsarOptions\n unpackPattern: Filter | undefined\n }\n ) {\n this.outFile = path.join(config.resourcePath, `app.asar`)\n this.tmpDir = packager.info.tempDirManager\n this.cancellationToken = packager.info.cancellationToken\n }\n\n async pack(fileSets: Array<ResolvedFileSet>) {\n this.rootForAppFilesWithoutAsar = await this.tmpDir.getTempDir({ prefix: \"asar-app\" })\n\n const orderedFileSets = [\n // Write dependencies first to minimize offset changes to asar header\n ...fileSets.slice(1),\n\n // Finish with the app files that change most often\n fileSets[0],\n ].map(orderFileSet)\n\n const { unpackedPaths, copiedFiles } = await this.detectAndCopy(orderedFileSets)\n const unpackGlob = unpackedPaths.length > 1 ? `{${unpackedPaths.join(\",\")}}` : unpackedPaths.pop()\n\n await this.executeElectronAsar(copiedFiles, unpackGlob)\n }\n\n private async executeElectronAsar(copiedFiles: string[], unpackGlob: string | undefined) {\n let ordering = this.config.options.ordering || undefined\n if (!ordering) {\n // `copiedFiles` are already ordered due to `orderedFileSets` input, so we just map to their relative paths (via substring) within the asar.\n const filesSorted = copiedFiles.map(file => file.substring(this.rootForAppFilesWithoutAsar.length))\n ordering = await this.tmpDir.getTempFile({ prefix: \"asar-ordering\", suffix: \".txt\" })\n await fs.writeFile(ordering, filesSorted.join(\"\\n\"))\n }\n\n const options: CreateOptions = {\n unpack: unpackGlob,\n unpackDir: unpackGlob,\n ordering,\n dot: true,\n }\n // override logger temporarily to clean up console (electron/asar does some internal logging that blogs up the default electron-builder logs)\n const consoleLogger = console.log\n console.log = (...args) => {\n if (args[0] === \"Ordering file has 100% coverage.\") {\n return // no need to log, this means our ordering logic is working correctly\n }\n log.info({ args }, \"logging @electron/asar\")\n }\n await createPackageWithOptions(this.rootForAppFilesWithoutAsar, this.outFile, options)\n console.log = consoleLogger\n }\n\n private async detectAndCopy(fileSets: ResolvedFileSet[]) {\n const taskManager = new AsyncTaskManager(this.cancellationToken)\n const unpackedPaths = new Set<string>()\n const copiedFiles = new Set<string>()\n\n const createdSourceDirs = new Set<string>()\n const links: Array<Link> = []\n const symlinkType = platform() === \"win32\" ? \"junction\" : \"file\"\n\n const matchUnpacker = (file: string, dest: string, stat: fs.Stats, tmpUnpackedPaths: Set<string>) => {\n if (this.config.unpackPattern?.(file, stat)) {\n log.debug({ file }, \"unpacking\")\n tmpUnpackedPaths.add(dest)\n return\n }\n }\n const writeFileOrProcessSymlink = async (options: {\n file: string\n destination: string\n stat: fs.Stats\n fileSet: ResolvedFileSet\n transformedData: string | Buffer | undefined\n }) => {\n const { transformedData, file, destination, stat, fileSet } = options\n if (!stat.isFile() && !stat.isSymbolicLink()) {\n return\n }\n copiedFiles.add(destination)\n\n const dir = path.dirname(destination)\n if (!createdSourceDirs.has(dir)) {\n await mkdir(dir, { recursive: true })\n createdSourceDirs.add(dir)\n }\n\n // write any data if provided, skip symlink check\n if (transformedData != null) {\n return fs.writeFile(destination, transformedData, { mode: stat.mode })\n }\n\n const realPathFile = await fs.realpath(file)\n const realPathRelative = path.relative(fileSet.src, realPathFile)\n const isOutsidePackage = realPathRelative.startsWith(\"..\")\n if (isOutsidePackage) {\n log.error({ source: log.filePath(file), realPathFile: log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`)\n throw new Error(`Cannot copy file (${path.basename(file)}) symlinked to file (${path.basename(realPathFile)}) outside the package as that violates asar security integrity`)\n }\n\n // not a symlink, copy directly\n if (file === realPathFile) {\n return this.fileCopier.copy(file, destination, stat)\n }\n\n // okay, it must be a symlink. evaluate link to be relative to source file in asar\n let link = await readlink(file)\n if (path.isAbsolute(link)) {\n link = path.relative(path.dirname(file), link)\n }\n links.push({ file: destination, link })\n }\n\n for (const fileSet of fileSets) {\n if (this.config.options.smartUnpack !== false) {\n detectUnpackedDirs(fileSet, unpackedPaths)\n }\n\n // Don't use BluebirdPromise, we need to retain order of execution/iteration through the ordered fileset\n const tmpUnpackedPaths = new Set<string>()\n for (let i = 0; i < fileSet.files.length; i++) {\n const file = fileSet.files[i]\n const transformedData = fileSet.transformedFiles?.get(i)\n const stat = fileSet.metadata.get(file)!\n\n const relative = path.relative(this.config.defaultDestination, getDestinationPath(file, fileSet))\n const destination = path.resolve(this.rootForAppFilesWithoutAsar, relative)\n\n matchUnpacker(file, destination, stat, tmpUnpackedPaths)\n taskManager.addTask(writeFileOrProcessSymlink({ transformedData, file, destination, stat, fileSet }))\n\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n }\n\n if (tmpUnpackedPaths.size === fileSet.files.length) {\n const relative = path.relative(this.config.defaultDestination, fileSet.destination)\n unpackedPaths.add(relative)\n } else {\n // add all tmpUnpackedPaths to unpackedPaths\n for (const it of tmpUnpackedPaths) {\n unpackedPaths.add(it)\n }\n }\n }\n // finish copy then set up all symlinks\n await taskManager.awaitTasks()\n for (const it of links) {\n taskManager.addTask(symlink(it.link, it.file, symlinkType))\n\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n }\n await taskManager.awaitTasks()\n return {\n unpackedPaths: Array.from(unpackedPaths),\n copiedFiles: Array.from(copiedFiles),\n }\n }\n}\n\nfunction orderFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {\n const sortedFileEntries = Array.from(fileSet.files.entries())\n\n sortedFileEntries.sort(([, a], [, b]) => {\n if (a === b) {\n return 0\n }\n\n // Place addons last because their signature changes per build\n const isAAddon = a.endsWith(\".node\")\n const isBAddon = b.endsWith(\".node\")\n if (isAAddon && !isBAddon) {\n return 1\n }\n if (isBAddon && !isAAddon) {\n return -1\n }\n\n // Otherwise order by name\n return a < b ? -1 : 1\n })\n\n let transformedFiles: Map<number, string | Buffer> | undefined\n if (fileSet.transformedFiles) {\n transformedFiles = new Map()\n\n const indexMap = new Map<number, number>()\n for (const [newIndex, [oldIndex]] of sortedFileEntries.entries()) {\n indexMap.set(oldIndex, newIndex)\n }\n\n for (const [oldIndex, value] of fileSet.transformedFiles) {\n const newIndex = indexMap.get(oldIndex)\n if (newIndex === undefined) {\n const file = fileSet.files[oldIndex]\n throw new Error(`Internal error: ${file} was lost while ordering asar`)\n }\n\n transformedFiles.set(newIndex, value)\n }\n }\n\n const { src, destination, metadata } = fileSet\n\n return {\n src,\n destination,\n metadata,\n files: sortedFileEntries.map(([, file]) => file),\n transformedFiles,\n }\n}\n"]}
|
package/out/asar/integrity.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { NodeIntegrity } from "./asar";
|
|
2
|
+
import { FileMatcher } from "../fileMatcher";
|
|
2
3
|
export interface AsarIntegrityOptions {
|
|
3
4
|
readonly resourcesPath: string;
|
|
4
5
|
readonly resourcesRelativePath: string;
|
|
6
|
+
readonly resourcesDestinationPath: string;
|
|
7
|
+
readonly extraResourceMatchers: Array<FileMatcher> | null;
|
|
5
8
|
}
|
|
6
9
|
export interface HeaderHash {
|
|
7
10
|
algorithm: "SHA256";
|
|
@@ -10,6 +13,6 @@ export interface HeaderHash {
|
|
|
10
13
|
export interface AsarIntegrity {
|
|
11
14
|
[key: string]: HeaderHash;
|
|
12
15
|
}
|
|
13
|
-
export declare function computeData({ resourcesPath, resourcesRelativePath }: AsarIntegrityOptions): Promise<AsarIntegrity>;
|
|
16
|
+
export declare function computeData({ resourcesPath, resourcesRelativePath, resourcesDestinationPath, extraResourceMatchers }: AsarIntegrityOptions): Promise<AsarIntegrity>;
|
|
14
17
|
export declare function hashFile(file: string, blockSize?: number): Promise<NodeIntegrity>;
|
|
15
18
|
export declare function hashFileContents(contents: Buffer | string, blockSize?: number): NodeIntegrity;
|
package/out/asar/integrity.js
CHANGED
|
@@ -9,15 +9,44 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const promises_1 = require("fs/promises");
|
|
10
10
|
const path = require("path");
|
|
11
11
|
const asar_1 = require("./asar");
|
|
12
|
-
|
|
12
|
+
const builder_util_1 = require("builder-util");
|
|
13
|
+
async function computeData({ resourcesPath, resourcesRelativePath, resourcesDestinationPath, extraResourceMatchers }) {
|
|
14
|
+
const isAsar = (filepath) => filepath.endsWith(".asar");
|
|
15
|
+
const resources = await (0, promises_1.readdir)(resourcesPath);
|
|
16
|
+
const resourceAsars = resources.filter(isAsar).reduce((prev, filename) => ({
|
|
17
|
+
...prev,
|
|
18
|
+
[path.join(resourcesRelativePath, filename)]: path.join(resourcesPath, filename),
|
|
19
|
+
}), {});
|
|
20
|
+
const extraResources = await bluebird_lst_1.default.map(extraResourceMatchers !== null && extraResourceMatchers !== void 0 ? extraResourceMatchers : [], async (matcher) => {
|
|
21
|
+
const { from, to } = matcher;
|
|
22
|
+
const stat = await (0, builder_util_1.statOrNull)(from);
|
|
23
|
+
if (stat == null) {
|
|
24
|
+
builder_util_1.log.warn({ from }, `file source doesn't exist`);
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
if (stat.isFile()) {
|
|
28
|
+
return [{ from, to }];
|
|
29
|
+
}
|
|
30
|
+
if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {
|
|
31
|
+
matcher.prependPattern("**/*");
|
|
32
|
+
}
|
|
33
|
+
const matcherFilter = matcher.createFilter();
|
|
34
|
+
const extraResourceMatches = await (0, builder_util_1.walk)(matcher.from, (file, stats) => matcherFilter(file, stats) || stats.isDirectory());
|
|
35
|
+
return extraResourceMatches.map(from => ({ from, to: matcher.to }));
|
|
36
|
+
});
|
|
37
|
+
const extraResourceAsars = extraResources
|
|
38
|
+
.flat(1)
|
|
39
|
+
.filter(match => isAsar(match.from))
|
|
40
|
+
.reduce((prev, { to, from }) => {
|
|
41
|
+
const prefix = path.relative(resourcesDestinationPath, to);
|
|
42
|
+
return {
|
|
43
|
+
...prev,
|
|
44
|
+
[path.join(resourcesRelativePath, prefix, path.basename(from))]: from,
|
|
45
|
+
};
|
|
46
|
+
}, {});
|
|
13
47
|
// sort to produce constant result
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const result = {};
|
|
17
|
-
for (let i = 0; i < names.length; i++) {
|
|
18
|
-
result[path.join(resourcesRelativePath, names[i])] = checksums[i];
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
48
|
+
const allAsars = [...Object.entries(resourceAsars), ...Object.entries(extraResourceAsars)].sort(([name1], [name2]) => name1.localeCompare(name2));
|
|
49
|
+
return bluebird_lst_1.default.reduce(allAsars, async (prev, [relativePathKey, from]) => ({ ...prev, [relativePathKey]: await hashHeader(from) }), {});
|
|
21
50
|
}
|
|
22
51
|
async function hashHeader(file) {
|
|
23
52
|
const hash = (0, crypto_1.createHash)("sha256");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integrity.js","sourceRoot":"","sources":["../../src/asar/integrity.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"integrity.js","sourceRoot":"","sources":["../../src/asar/integrity.ts"],"names":[],"mappings":";;AAyBA,kCAgDC;AAYD,4BA4CC;AAED,4CAmBC;AAtJD,+CAA0C;AAC1C,mCAAmC;AACnC,2BAAqC;AACrC,0CAAqC;AACrC,6BAA4B;AAC5B,iCAAsD;AAEtD,+CAAiE;AAkB1D,KAAK,UAAU,WAAW,CAAC,EAAE,aAAa,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,qBAAqB,EAAwB;IAK/I,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAE/D,MAAM,SAAS,GAAG,MAAM,IAAA,kBAAO,EAAC,aAAa,CAAC,CAAA;IAC9C,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CACnD,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnB,GAAG,IAAI;QACP,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAA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AC;QACxB,SAAS;QACT,MAAM;KACP,CAAA;AACH,CAAC","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport { readdir } from \"fs/promises\"\nimport * as path from \"path\"\nimport { readAsarHeader, NodeIntegrity } from \"./asar\"\nimport { FileMatcher } from \"../fileMatcher\"\nimport { statOrNull, walk, FilterStats, log } from \"builder-util\"\n\nexport interface AsarIntegrityOptions {\n readonly resourcesPath: string\n readonly resourcesRelativePath: string\n readonly resourcesDestinationPath: string\n readonly extraResourceMatchers: Array<FileMatcher> | null\n}\n\nexport interface HeaderHash {\n algorithm: \"SHA256\"\n hash: string\n}\n\nexport interface AsarIntegrity {\n [key: string]: HeaderHash\n}\n\nexport async function computeData({ resourcesPath, resourcesRelativePath, resourcesDestinationPath, extraResourceMatchers }: AsarIntegrityOptions): Promise<AsarIntegrity> {\n type Match = Pick<FileMatcher, \"to\" | \"from\">\n type IntegrityMap = {\n [filepath: string]: string\n }\n const isAsar = (filepath: string) => filepath.endsWith(\".asar\")\n\n const resources = await readdir(resourcesPath)\n const resourceAsars = resources.filter(isAsar).reduce<IntegrityMap>(\n (prev, filename) => ({\n ...prev,\n [path.join(resourcesRelativePath, filename)]: path.join(resourcesPath, filename),\n }),\n {}\n )\n\n const extraResources = await BluebirdPromise.map(extraResourceMatchers ?? [], async (matcher: FileMatcher): Promise<Match[]> => {\n const { from, to } = matcher\n const stat = await statOrNull(from)\n if (stat == null) {\n log.warn({ from }, `file source doesn't exist`)\n return []\n }\n if (stat.isFile()) {\n return [{ from, to }]\n }\n\n if (matcher.isEmpty() || matcher.containsOnlyIgnore()) {\n matcher.prependPattern(\"**/*\")\n }\n const matcherFilter = matcher.createFilter()\n const extraResourceMatches = await walk(matcher.from, (file: string, stats: FilterStats) => matcherFilter(file, stats) || stats.isDirectory())\n return extraResourceMatches.map(from => ({ from, to: matcher.to }))\n })\n const extraResourceAsars = extraResources\n .flat(1)\n .filter(match => isAsar(match.from))\n .reduce<IntegrityMap>((prev, { to, from }) => {\n const prefix = path.relative(resourcesDestinationPath, to)\n return {\n ...prev,\n [path.join(resourcesRelativePath, prefix, path.basename(from))]: from,\n }\n }, {})\n\n // sort to produce constant result\n const allAsars = [...Object.entries(resourceAsars), ...Object.entries(extraResourceAsars)].sort(([name1], [name2]) => name1.localeCompare(name2))\n return BluebirdPromise.reduce(allAsars, async (prev, [relativePathKey, from]) => ({ ...prev, [relativePathKey]: await hashHeader(from) }), {} as AsarIntegrity)\n}\n\nasync function hashHeader(file: string): Promise<HeaderHash> {\n const hash = createHash(\"sha256\")\n const { header } = await readAsarHeader(file)\n hash.update(header)\n return {\n algorithm: \"SHA256\",\n hash: hash.digest(\"hex\"),\n }\n}\n\nexport function hashFile(file: string, blockSize = 4 * 1024 * 1024): Promise<NodeIntegrity> {\n return new Promise<NodeIntegrity>((resolve, reject) => {\n const hash = createHash(\"sha256\")\n\n const blocks = new Array<string>()\n\n let blockBytes = 0\n let blockHash = createHash(\"sha256\")\n\n function updateBlockHash(chunk: Buffer) {\n let off = 0\n while (off < chunk.length) {\n const toHash = Math.min(blockSize - blockBytes, chunk.length - off)\n blockHash.update(chunk.slice(off, off + toHash))\n off += toHash\n blockBytes += toHash\n\n if (blockBytes === blockSize) {\n blocks.push(blockHash.digest(\"hex\"))\n blockHash = createHash(\"sha256\")\n blockBytes = 0\n }\n }\n }\n\n createReadStream(file)\n .on(\"data\", it => {\n // Note that `it` is a Buffer anyway so this cast is a no-op\n updateBlockHash(Buffer.from(it))\n hash.update(it)\n })\n .on(\"error\", reject)\n .on(\"end\", () => {\n if (blockBytes !== 0) {\n blocks.push(blockHash.digest(\"hex\"))\n }\n resolve({\n algorithm: \"SHA256\",\n hash: hash.digest(\"hex\"),\n blockSize,\n blocks,\n })\n })\n })\n}\n\nexport function hashFileContents(contents: Buffer | string, blockSize = 4 * 1024 * 1024): NodeIntegrity {\n const buffer = Buffer.from(contents)\n const hash = createHash(\"sha256\")\n hash.update(buffer)\n\n const blocks = new Array<string>()\n\n for (let off = 0; off < buffer.length; off += blockSize) {\n const blockHash = createHash(\"sha256\")\n blockHash.update(buffer.slice(off, off + blockSize))\n blocks.push(blockHash.digest(\"hex\"))\n }\n\n return {\n algorithm: \"SHA256\",\n hash: hash.digest(\"hex\"),\n blockSize,\n blocks,\n }\n}\n"]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { WindowsConfiguration } from "../options/winOptions";
|
|
2
|
-
import { VmManager } from "../vm/vm";
|
|
3
2
|
import { WinPackager } from "../winPackager";
|
|
4
3
|
export interface WindowsSignOptions {
|
|
5
4
|
readonly path: string;
|
|
6
5
|
readonly options: WindowsConfiguration;
|
|
7
6
|
}
|
|
8
7
|
export declare function signWindows(options: WindowsSignOptions, packager: WinPackager): Promise<boolean>;
|
|
9
|
-
export declare function getPSCmd(vm: VmManager): Promise<string>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.signWindows = signWindows;
|
|
4
|
-
exports.getPSCmd = getPSCmd;
|
|
5
4
|
const builder_util_1 = require("builder-util");
|
|
6
5
|
async function signWindows(options, packager) {
|
|
7
|
-
const packageManager = await packager.signingManager.value;
|
|
8
6
|
if (options.options.azureSignOptions) {
|
|
9
7
|
if (options.options.signtoolOptions) {
|
|
10
8
|
builder_util_1.log.warn(null, "ignoring signtool options, using Azure Trusted Signing; please only configure one");
|
|
@@ -13,26 +11,8 @@ async function signWindows(options, packager) {
|
|
|
13
11
|
}
|
|
14
12
|
else {
|
|
15
13
|
builder_util_1.log.info({ path: builder_util_1.log.filePath(options.path) }, "signing with signtool.exe");
|
|
16
|
-
const deprecatedFields = {
|
|
17
|
-
sign: options.options.sign,
|
|
18
|
-
signDlls: options.options.signDlls,
|
|
19
|
-
signingHashAlgorithms: options.options.signingHashAlgorithms,
|
|
20
|
-
certificateFile: options.options.certificateFile,
|
|
21
|
-
certificatePassword: options.options.certificatePassword,
|
|
22
|
-
certificateSha1: options.options.certificateSha1,
|
|
23
|
-
certificateSubjectName: options.options.certificateSubjectName,
|
|
24
|
-
additionalCertificateFile: options.options.additionalCertificateFile,
|
|
25
|
-
rfc3161TimeStampServer: options.options.rfc3161TimeStampServer,
|
|
26
|
-
timeStampServer: options.options.timeStampServer,
|
|
27
|
-
publisherName: options.options.publisherName,
|
|
28
|
-
};
|
|
29
|
-
const fields = Object.entries(deprecatedFields)
|
|
30
|
-
.filter(([, value]) => !!value)
|
|
31
|
-
.map(([field]) => field);
|
|
32
|
-
if (fields.length) {
|
|
33
|
-
builder_util_1.log.warn({ fields, reason: "please move to win.signtoolOptions.<field_name>" }, `deprecated field`);
|
|
34
|
-
}
|
|
35
14
|
}
|
|
15
|
+
const packageManager = await packager.signingManager.value;
|
|
36
16
|
return signWithRetry(async () => packageManager.signFile(options));
|
|
37
17
|
}
|
|
38
18
|
function signWithRetry(signer) {
|
|
@@ -50,16 +30,4 @@ function signWithRetry(signer) {
|
|
|
50
30
|
return false;
|
|
51
31
|
});
|
|
52
32
|
}
|
|
53
|
-
async function getPSCmd(vm) {
|
|
54
|
-
return await vm
|
|
55
|
-
.exec("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", `Get-Command pwsh.exe`])
|
|
56
|
-
.then(() => {
|
|
57
|
-
builder_util_1.log.debug(null, "identified pwsh.exe for executing code signing");
|
|
58
|
-
return "pwsh.exe";
|
|
59
|
-
})
|
|
60
|
-
.catch(() => {
|
|
61
|
-
builder_util_1.log.debug(null, "unable to find pwsh.exe, falling back to powershell.exe");
|
|
62
|
-
return "powershell.exe";
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
33
|
//# sourceMappingURL=windowsCodeSign.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windowsCodeSign.js","sourceRoot":"","sources":["../../src/codeSign/windowsCodeSign.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,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AI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,sDAAsD,CAAC,CAAA;YACpF,OAAO,IAAI,CAAA;QACb,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { log, retry } from \"builder-util\"\nimport { WindowsConfiguration } from \"../options/winOptions\"\nimport { WinPackager } from \"../winPackager\"\n\nexport interface WindowsSignOptions {\n readonly path: string\n readonly options: WindowsConfiguration\n}\n\nexport async function signWindows(options: WindowsSignOptions, packager: WinPackager): Promise<boolean> {\n if (options.options.azureSignOptions) {\n if (options.options.signtoolOptions) {\n log.warn(null, \"ignoring signtool options, using Azure Trusted Signing; please only configure one\")\n }\n log.info({ path: log.filePath(options.path) }, \"signing with Azure Trusted Signing (beta)\")\n } else {\n log.info({ path: log.filePath(options.path) }, \"signing with signtool.exe\")\n }\n const packageManager = await packager.signingManager.value\n return signWithRetry(async () => packageManager.signFile(options))\n}\n\nfunction signWithRetry(signer: () => Promise<boolean>): Promise<boolean> {\n return retry(signer, 3, 1000, 1000, 0, (e: any) => {\n const message = e.message\n if (\n // https://github.com/electron-userland/electron-builder/issues/1414\n message?.includes(\"Couldn't resolve host name\") ||\n // https://github.com/electron-userland/electron-builder/issues/8615\n message?.includes(\"being used by another process.\")\n ) {\n log.warn({ error: message }, \"attempt to sign failed, another attempt will be made\")\n return true\n }\n return false\n })\n}\n"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WindowsSignAzureManager = void 0;
|
|
4
4
|
const builder_util_1 = require("builder-util");
|
|
5
|
-
const windowsCodeSign_1 = require("./windowsCodeSign");
|
|
6
5
|
const lazy_val_1 = require("lazy-val");
|
|
7
6
|
const builder_util_runtime_1 = require("builder-util-runtime");
|
|
8
7
|
class WindowsSignAzureManager {
|
|
@@ -26,7 +25,7 @@ class WindowsSignAzureManager {
|
|
|
26
25
|
}
|
|
27
26
|
async initialize() {
|
|
28
27
|
const vm = await this.packager.vm.value;
|
|
29
|
-
const ps = await
|
|
28
|
+
const ps = await vm.powershellCommand.value;
|
|
30
29
|
builder_util_1.log.info(null, "installing required module (TrustedSigning) with scope CurrentUser");
|
|
31
30
|
try {
|
|
32
31
|
await vm.exec(ps, ["-NoProfile", "-NonInteractive", "-Command", "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser"]);
|
|
@@ -89,7 +88,7 @@ class WindowsSignAzureManager {
|
|
|
89
88
|
// prerequisite: requires `initializeProviderModules` to already have been executed
|
|
90
89
|
async signFile(options) {
|
|
91
90
|
const vm = await this.packager.vm.value;
|
|
92
|
-
const ps = await
|
|
91
|
+
const ps = await vm.powershellCommand.value;
|
|
93
92
|
const { publisherName: _publisher, // extract from `extraSigningArgs`
|
|
94
93
|
endpoint, certificateProfileName, codeSigningAccountName, fileDigest, timestampRfc3161, timestampDigest, ...extraSigningArgs } = options.options.azureSignOptions;
|
|
95
94
|
const params = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windowsSignAzureManager.js","sourceRoot":"","sources":["../../src/codeSign/windowsSignAzureManager.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AAGtE,uDAAgE;AAChE,uCAA+B;AAE/B,+DAA+C;AAG/C,MAAa,uBAAuB;IAgBlC,YAA6B,QAAqB;QAArB,aAAQ,GAAR,QAAQ,CAAa;QAbzC,0BAAqB,GAAG,IAAI,eAAI,CAAuB,GAAG,EAAE;;YACnE,MAAM,aAAa,GAAG,MAAA,IAAI,CAAC,4BAA4B,CAAC,gBAAgB,0CAAE,aAAa,CAAA;YACvF,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;gBAC3B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9B,CAAC;iBAAM,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;gBACjC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAA,sB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IAAI,QAAQ;YAClC,KAAK,EAAE,IAAI,OAAO,CAAC,IAAI,GAAG;SAC3B,CAAA;QACD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;aACxC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC;aACrC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE;YAC9B,OAAO,CAAC,GAAG,GAAG,EAAE,IAAI,KAAK,EAAE,EAAE,KAAK,CAAC,CAAA;QACrC,CAAC,EAAE,EAAc,CAAC;aACjB,IAAI,CAAC,GAAG,CAAC,CAAA;QACZ,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,yBAAyB,YAAY,EAAE,CAAC,CAAC,CAAA;QAEzG,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAlID,0DAkIC","sourcesContent":["import { asArray, InvalidConfigurationError, log } from \"builder-util\"\nimport { WindowsAzureSigningConfiguration, WindowsConfiguration } from \"../options/winOptions\"\nimport { WinPackager } from \"../winPackager\"\nimport { getPSCmd, WindowsSignOptions } from \"./windowsCodeSign\"\nimport { Lazy } from \"lazy-val\"\nimport { SignManager } from \"./signManager\"\nimport { MemoLazy } from \"builder-util-runtime\"\nimport { CertificateFromStoreInfo, FileCodeSigningInfo } from \"./windowsSignToolManager\"\n\nexport class WindowsSignAzureManager implements SignManager {\n private readonly platformSpecificBuildOptions: WindowsConfiguration\n\n readonly computedPublisherName = new Lazy<Array<string> | null>(() => {\n const publisherName = this.platformSpecificBuildOptions.azureSignOptions?.publisherName\n if (publisherName === null) {\n return Promise.resolve(null)\n } else if (publisherName != null) {\n return Promise.resolve(asArray(publisherName))\n }\n\n // TODO: Is there another way to automatically pull Publisher Name from AzureTrusted service?\n // For now return null.\n return Promise.resolve(null)\n })\n\n constructor(private readonly packager: WinPackager) {\n this.platformSpecificBuildOptions = packager.platformSpecificBuildOptions\n }\n\n async initialize() {\n const vm = await this.packager.vm.value\n const ps = await getPSCmd(vm)\n\n log.info(null, \"installing required module (TrustedSigning) with scope CurrentUser\")\n try {\n await vm.exec(ps, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", \"Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser\"])\n } catch (error: any) {\n // Might not be needed, seems GH runners already have NuGet set up.\n // Logging to debug just in case users run into this. If NuGet isn't present, Install-Module -Name TrustedSigning will fail, so we'll get the logs at that point\n log.debug({ message: error.message || error.stack }, \"unable to install PackageProvider Nuget. Might be a false alarm though as some systems already have it installed\")\n }\n await vm.exec(ps, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", \"Install-Module -Name TrustedSigning -RequiredVersion 0.4.1 -Force -Repository PSGallery -Scope CurrentUser\"])\n\n // Preemptively check env vars once during initialization\n // Options: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet#definition\n log.info(null, \"verifying env vars for authenticating to Microsoft Entra ID\")\n this.verifyRequiredEnvVars()\n if (!(this.verifyPrincipleSecretEnv() || this.verifyPrincipleCertificateEnv() || this.verifyUsernamePasswordEnv())) {\n throw new InvalidConfigurationError(\n `Unable to find valid azure env configuration for signing. Missing field(s) can be debugged via \"DEBUG=electron-builder\". Please refer to: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet#definition`\n )\n }\n }\n\n verifyRequiredEnvVars() {\n ;[\"AZURE_TENANT_ID\", \"AZURE_CLIENT_ID\"].forEach(field => {\n if (!process.env[field]) {\n throw new InvalidConfigurationError(\n `Unable to find valid azure env field ${field} for signing. Please refer to: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet#definition`\n )\n }\n })\n }\n\n verifyPrincipleSecretEnv() {\n if (!process.env.AZURE_CLIENT_SECRET) {\n log.debug({ envVar: \"AZURE_CLIENT_SECRET\" }, \"no secret found for authenticating to Microsoft Entra ID\")\n return false\n }\n return true\n }\n\n verifyPrincipleCertificateEnv() {\n if (!process.env.AZURE_CLIENT_CERTIFICATE_PATH) {\n log.debug({ envVar: \"AZURE_CLIENT_CERTIFICATE_PATH\" }, \"no path found for signing certificate for authenticating to Microsoft Entra ID\")\n return false\n }\n if (!process.env.AZURE_CLIENT_CERTIFICATE_PASSWORD) {\n log.debug({ envVar: \"AZURE_CLIENT_CERTIFICATE_PASSWORD\" }, \"(optional) certificate password not found, assuming no password\")\n }\n if (!process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN) {\n log.debug({ envVar: \"AZURE_CLIENT_SEND_CERTIFICATE_CHAIN\" }, \"(optional) certificate chain not found\")\n }\n return true\n }\n\n verifyUsernamePasswordEnv() {\n if (!process.env.AZURE_USERNAME) {\n log.debug({ envVar: \"AZURE_USERNAME\" }, \"no username found for authenticating to Microsoft Entra ID\")\n if (!process.env.AZURE_PASSWORD) {\n log.debug({ envVar: \"AZURE_PASSWORD\" }, \"no password found for authenticating to Microsoft Entra ID\")\n }\n return false\n }\n return true\n }\n\n computePublisherName(): Promise<string> {\n return Promise.resolve(this.packager.platformSpecificBuildOptions.azureSignOptions!.publisherName)\n }\n readonly cscInfo = new MemoLazy<WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null>(\n () => this.packager.platformSpecificBuildOptions,\n _selected => Promise.resolve(null)\n )\n // prerequisite: requires `initializeProviderModules` to already have been executed\n async signFile(options: WindowsSignOptions): Promise<boolean> {\n const vm = await this.packager.vm.value\n const ps = await getPSCmd(vm)\n\n const {\n publisherName: _publisher, // extract from `extraSigningArgs`\n endpoint,\n certificateProfileName,\n codeSigningAccountName,\n fileDigest,\n timestampRfc3161,\n timestampDigest,\n ...extraSigningArgs\n }: WindowsAzureSigningConfiguration = options.options.azureSignOptions!\n const params = {\n ...extraSigningArgs,\n Endpoint: endpoint,\n CertificateProfileName: certificateProfileName,\n CodeSigningAccountName: codeSigningAccountName,\n TimestampRfc3161: timestampRfc3161 || \"http://timestamp.acs.microsoft.com\",\n TimestampDigest: timestampDigest || \"SHA256\",\n FileDigest: fileDigest || \"SHA256\",\n Files: `\"${options.path}\"`,\n }\n const paramsString = Object.entries(params)\n .filter(([_, value]) => value != null)\n .reduce((res, [field, value]) => {\n return [...res, `-${field}`, value]\n }, [] as string[])\n .join(\" \")\n await vm.exec(ps, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", `Invoke-TrustedSigning ${paramsString}`])\n\n return true\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"windowsSignAzureManager.js","sourceRoot":"","sources":["../../src/codeSign/windowsSignAzureManager.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AAItE,uCAA+B;AAE/B,+DAA+C;AAG/C,MAAa,uBAAuB;IAgBlC,YAA6B,QAAqB;QAArB,aAAQ,GAAR,QAAQ,CAAa;QAbzC,0BAAqB,GAAG,IAAI,eAAI,CAAuB,GAAG,EAAE;;YACnE,MAAM,aAAa,GAAG,MAAA,IAAI,CAAC,4BAA4B,CAAC,gBAAgB,0CAAE,aAAa,CAAA;YACvF,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;gBAC3B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9B,CAAC;iBAAM,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;gBACjC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAA,sBAAO,EAAC,aAAa,CAAC,CAAC,CAAA;YAChD,CAAC;YAED,6FAA6F;YAC7F,uBAAuB;YACvB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC,CAAC,CAAA;QA6EO,YAAO,GAAG,IAAI,+BAAQ,CAC7B,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAChD,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAA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E,EAAE;YAC9B,OAAO,CAAC,GAAG,GAAG,EAAE,IAAI,KAAK,EAAE,EAAE,KAAK,CAAC,CAAA;QACrC,CAAC,EAAE,EAAc,CAAC;aACjB,IAAI,CAAC,GAAG,CAAC,CAAA;QACZ,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,yBAAyB,YAAY,EAAE,CAAC,CAAC,CAAA;QAEzG,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAlID,0DAkIC","sourcesContent":["import { asArray, InvalidConfigurationError, log } from \"builder-util\"\nimport { WindowsAzureSigningConfiguration, WindowsConfiguration } from \"../options/winOptions\"\nimport { WinPackager } from \"../winPackager\"\nimport { WindowsSignOptions } from \"./windowsCodeSign\"\nimport { Lazy } from \"lazy-val\"\nimport { SignManager } from \"./signManager\"\nimport { MemoLazy } from \"builder-util-runtime\"\nimport { CertificateFromStoreInfo, FileCodeSigningInfo } from \"./windowsSignToolManager\"\n\nexport class WindowsSignAzureManager implements SignManager {\n private readonly platformSpecificBuildOptions: WindowsConfiguration\n\n readonly computedPublisherName = new Lazy<Array<string> | null>(() => {\n const publisherName = this.platformSpecificBuildOptions.azureSignOptions?.publisherName\n if (publisherName === null) {\n return Promise.resolve(null)\n } else if (publisherName != null) {\n return Promise.resolve(asArray(publisherName))\n }\n\n // TODO: Is there another way to automatically pull Publisher Name from AzureTrusted service?\n // For now return null.\n return Promise.resolve(null)\n })\n\n constructor(private readonly packager: WinPackager) {\n this.platformSpecificBuildOptions = packager.platformSpecificBuildOptions\n }\n\n async initialize() {\n const vm = await this.packager.vm.value\n const ps = await vm.powershellCommand.value\n\n log.info(null, \"installing required module (TrustedSigning) with scope CurrentUser\")\n try {\n await vm.exec(ps, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", \"Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser\"])\n } catch (error: any) {\n // Might not be needed, seems GH runners already have NuGet set up.\n // Logging to debug just in case users run into this. If NuGet isn't present, Install-Module -Name TrustedSigning will fail, so we'll get the logs at that point\n log.debug({ message: error.message || error.stack }, \"unable to install PackageProvider Nuget. Might be a false alarm though as some systems already have it installed\")\n }\n await vm.exec(ps, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", \"Install-Module -Name TrustedSigning -RequiredVersion 0.4.1 -Force -Repository PSGallery -Scope CurrentUser\"])\n\n // Preemptively check env vars once during initialization\n // Options: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet#definition\n log.info(null, \"verifying env vars for authenticating to Microsoft Entra ID\")\n this.verifyRequiredEnvVars()\n if (!(this.verifyPrincipleSecretEnv() || this.verifyPrincipleCertificateEnv() || this.verifyUsernamePasswordEnv())) {\n throw new InvalidConfigurationError(\n `Unable to find valid azure env configuration for signing. Missing field(s) can be debugged via \"DEBUG=electron-builder\". Please refer to: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet#definition`\n )\n }\n }\n\n verifyRequiredEnvVars() {\n ;[\"AZURE_TENANT_ID\", \"AZURE_CLIENT_ID\"].forEach(field => {\n if (!process.env[field]) {\n throw new InvalidConfigurationError(\n `Unable to find valid azure env field ${field} for signing. Please refer to: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet#definition`\n )\n }\n })\n }\n\n verifyPrincipleSecretEnv() {\n if (!process.env.AZURE_CLIENT_SECRET) {\n log.debug({ envVar: \"AZURE_CLIENT_SECRET\" }, \"no secret found for authenticating to Microsoft Entra ID\")\n return false\n }\n return true\n }\n\n verifyPrincipleCertificateEnv() {\n if (!process.env.AZURE_CLIENT_CERTIFICATE_PATH) {\n log.debug({ envVar: \"AZURE_CLIENT_CERTIFICATE_PATH\" }, \"no path found for signing certificate for authenticating to Microsoft Entra ID\")\n return false\n }\n if (!process.env.AZURE_CLIENT_CERTIFICATE_PASSWORD) {\n log.debug({ envVar: \"AZURE_CLIENT_CERTIFICATE_PASSWORD\" }, \"(optional) certificate password not found, assuming no password\")\n }\n if (!process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN) {\n log.debug({ envVar: \"AZURE_CLIENT_SEND_CERTIFICATE_CHAIN\" }, \"(optional) certificate chain not found\")\n }\n return true\n }\n\n verifyUsernamePasswordEnv() {\n if (!process.env.AZURE_USERNAME) {\n log.debug({ envVar: \"AZURE_USERNAME\" }, \"no username found for authenticating to Microsoft Entra ID\")\n if (!process.env.AZURE_PASSWORD) {\n log.debug({ envVar: \"AZURE_PASSWORD\" }, \"no password found for authenticating to Microsoft Entra ID\")\n }\n return false\n }\n return true\n }\n\n computePublisherName(): Promise<string> {\n return Promise.resolve(this.packager.platformSpecificBuildOptions.azureSignOptions!.publisherName)\n }\n readonly cscInfo = new MemoLazy<WindowsConfiguration, FileCodeSigningInfo | CertificateFromStoreInfo | null>(\n () => this.packager.platformSpecificBuildOptions,\n _selected => Promise.resolve(null)\n )\n // prerequisite: requires `initializeProviderModules` to already have been executed\n async signFile(options: WindowsSignOptions): Promise<boolean> {\n const vm = await this.packager.vm.value\n const ps = await vm.powershellCommand.value\n\n const {\n publisherName: _publisher, // extract from `extraSigningArgs`\n endpoint,\n certificateProfileName,\n codeSigningAccountName,\n fileDigest,\n timestampRfc3161,\n timestampDigest,\n ...extraSigningArgs\n }: WindowsAzureSigningConfiguration = options.options.azureSignOptions!\n const params = {\n ...extraSigningArgs,\n Endpoint: endpoint,\n CertificateProfileName: certificateProfileName,\n CodeSigningAccountName: codeSigningAccountName,\n TimestampRfc3161: timestampRfc3161 || \"http://timestamp.acs.microsoft.com\",\n TimestampDigest: timestampDigest || \"SHA256\",\n FileDigest: fileDigest || \"SHA256\",\n Files: `\"${options.path}\"`,\n }\n const paramsString = Object.entries(params)\n .filter(([_, value]) => value != null)\n .reduce((res, [field, value]) => {\n return [...res, `-${field}`, value]\n }, [] as string[])\n .join(\" \")\n await vm.exec(ps, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", `Invoke-TrustedSigning ${paramsString}`])\n\n return true\n }\n}\n"]}
|
|
@@ -13,8 +13,6 @@ const path = require("path");
|
|
|
13
13
|
const resolve_1 = require("../util/resolve");
|
|
14
14
|
const flags_1 = require("../util/flags");
|
|
15
15
|
const vm_1 = require("../vm/vm");
|
|
16
|
-
const platformPackager_1 = require("../platformPackager");
|
|
17
|
-
const windowsCodeSign_1 = require("./windowsCodeSign");
|
|
18
16
|
const builder_util_runtime_1 = require("builder-util-runtime");
|
|
19
17
|
const lazy_val_1 = require("lazy-val");
|
|
20
18
|
const codesign_1 = require("./codesign");
|
|
@@ -27,7 +25,7 @@ class WindowsSignToolManager {
|
|
|
27
25
|
this.packager = packager;
|
|
28
26
|
this.computedPublisherName = new lazy_val_1.Lazy(async () => {
|
|
29
27
|
var _a;
|
|
30
|
-
const publisherName = (
|
|
28
|
+
const publisherName = (_a = this.platformSpecificBuildOptions.signtoolOptions) === null || _a === void 0 ? void 0 : _a.publisherName;
|
|
31
29
|
if (publisherName === null) {
|
|
32
30
|
return null;
|
|
33
31
|
}
|
|
@@ -57,15 +55,15 @@ class WindowsSignToolManager {
|
|
|
57
55
|
});
|
|
58
56
|
this.cscInfo = new builder_util_runtime_1.MemoLazy(() => this.platformSpecificBuildOptions, platformSpecificBuildOptions => {
|
|
59
57
|
var _a, _b, _c;
|
|
60
|
-
const subjectName = (
|
|
61
|
-
const shaType = (
|
|
58
|
+
const subjectName = (_a = platformSpecificBuildOptions.signtoolOptions) === null || _a === void 0 ? void 0 : _a.certificateSubjectName;
|
|
59
|
+
const shaType = (_b = platformSpecificBuildOptions.signtoolOptions) === null || _b === void 0 ? void 0 : _b.certificateSha1;
|
|
62
60
|
if (subjectName != null || shaType != null) {
|
|
63
61
|
return this.packager.vm.value
|
|
64
62
|
.then(vm => this.getCertificateFromStoreInfo(platformSpecificBuildOptions, vm))
|
|
65
63
|
.catch((e) => {
|
|
66
64
|
var _a;
|
|
67
65
|
// https://github.com/electron-userland/electron-builder/pull/2397
|
|
68
|
-
if ((
|
|
66
|
+
if (((_a = platformSpecificBuildOptions.signtoolOptions) === null || _a === void 0 ? void 0 : _a.sign) == null) {
|
|
69
67
|
throw e;
|
|
70
68
|
}
|
|
71
69
|
else {
|
|
@@ -74,7 +72,7 @@ class WindowsSignToolManager {
|
|
|
74
72
|
}
|
|
75
73
|
});
|
|
76
74
|
}
|
|
77
|
-
const certificateFile = (
|
|
75
|
+
const certificateFile = (_c = platformSpecificBuildOptions.signtoolOptions) === null || _c === void 0 ? void 0 : _c.certificateFile;
|
|
78
76
|
if (certificateFile != null) {
|
|
79
77
|
const certificatePassword = this.packager.getCscPassword();
|
|
80
78
|
return Promise.resolve({
|
|
@@ -123,7 +121,7 @@ class WindowsSignToolManager {
|
|
|
123
121
|
}
|
|
124
122
|
async signFile(options) {
|
|
125
123
|
var _a, _b;
|
|
126
|
-
let hashes = (
|
|
124
|
+
let hashes = (_a = options.options.signtoolOptions) === null || _a === void 0 ? void 0 : _a.signingHashAlgorithms;
|
|
127
125
|
// msi does not support dual-signing
|
|
128
126
|
if (options.path.endsWith(".msi")) {
|
|
129
127
|
hashes = [hashes != null && !hashes.includes("sha1") ? "sha256" : "sha1"];
|
|
@@ -139,7 +137,7 @@ class WindowsSignToolManager {
|
|
|
139
137
|
}
|
|
140
138
|
const name = this.packager.appInfo.productName;
|
|
141
139
|
const site = await this.packager.appInfo.computePackageUrl();
|
|
142
|
-
const customSign = await (0, resolve_1.resolveFunction)(this.packager.appInfo.type, (
|
|
140
|
+
const customSign = await (0, resolve_1.resolveFunction)(this.packager.appInfo.type, (_b = options.options.signtoolOptions) === null || _b === void 0 ? void 0 : _b.sign, "sign");
|
|
143
141
|
const cscInfo = await this.cscInfo.value;
|
|
144
142
|
if (cscInfo) {
|
|
145
143
|
let logInfo = {
|
|
@@ -206,11 +204,9 @@ class WindowsSignToolManager {
|
|
|
206
204
|
}
|
|
207
205
|
const args = isWin ? ["sign"] : ["-in", inputFile, "-out", outputPath];
|
|
208
206
|
if (process.env.ELECTRON_BUILDER_OFFLINE !== "true") {
|
|
209
|
-
const timestampingServiceUrl = (
|
|
207
|
+
const timestampingServiceUrl = ((_a = options.options.signtoolOptions) === null || _a === void 0 ? void 0 : _a.timeStampServer) || "http://timestamp.digicert.com";
|
|
210
208
|
if (isWin) {
|
|
211
|
-
args.push(options.isNest || options.hash === "sha256" ? "/tr" : "/t", options.isNest || options.hash === "sha256"
|
|
212
|
-
? (0, platformPackager_1.chooseNotNull)((_b = options.options.signtoolOptions) === null || _b === void 0 ? void 0 : _b.rfc3161TimeStampServer, options.options.rfc3161TimeStampServer) || "http://timestamp.digicert.com"
|
|
213
|
-
: timestampingServiceUrl);
|
|
209
|
+
args.push(options.isNest || options.hash === "sha256" ? "/tr" : "/t", options.isNest || options.hash === "sha256" ? ((_b = options.options.signtoolOptions) === null || _b === void 0 ? void 0 : _b.rfc3161TimeStampServer) || "http://timestamp.digicert.com" : timestampingServiceUrl);
|
|
214
210
|
}
|
|
215
211
|
else {
|
|
216
212
|
args.push("-t", timestampingServiceUrl);
|
|
@@ -258,7 +254,7 @@ class WindowsSignToolManager {
|
|
|
258
254
|
if (password) {
|
|
259
255
|
args.push(isWin ? "/p" : "-pass", password);
|
|
260
256
|
}
|
|
261
|
-
const additionalCert = (
|
|
257
|
+
const additionalCert = (_c = options.options.signtoolOptions) === null || _c === void 0 ? void 0 : _c.additionalCertificateFile;
|
|
262
258
|
if (additionalCert) {
|
|
263
259
|
args.push(isWin ? "/ac" : "-ac", vm.toVmFile(additionalCert));
|
|
264
260
|
}
|
|
@@ -313,9 +309,9 @@ class WindowsSignToolManager {
|
|
|
313
309
|
}
|
|
314
310
|
async getCertificateFromStoreInfo(options, vm) {
|
|
315
311
|
var _a, _b, _c;
|
|
316
|
-
const certificateSubjectName = (
|
|
317
|
-
const certificateSha1 = (_c = (
|
|
318
|
-
const ps = await
|
|
312
|
+
const certificateSubjectName = (_a = options.signtoolOptions) === null || _a === void 0 ? void 0 : _a.certificateSubjectName;
|
|
313
|
+
const certificateSha1 = (_c = (_b = options.signtoolOptions) === null || _b === void 0 ? void 0 : _b.certificateSha1) === null || _c === void 0 ? void 0 : _c.toUpperCase();
|
|
314
|
+
const ps = await vm.powershellCommand.value;
|
|
319
315
|
const rawResult = await vm.exec(ps, [
|
|
320
316
|
"-NoProfile",
|
|
321
317
|
"-NonInteractive",
|