app-builder-lib 27.0.0-alpha.10 → 27.0.0-alpha.12
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/dist/asar/asarAlign.d.ts +35 -0
- package/dist/asar/asarAlign.d.ts.map +1 -0
- package/dist/asar/asarAlign.js +149 -0
- package/dist/asar/asarAlign.js.map +1 -0
- package/dist/asar/asarUtil.d.ts +15 -1
- package/dist/asar/asarUtil.d.ts.map +1 -1
- package/dist/asar/asarUtil.js +111 -61
- package/dist/asar/asarUtil.js.map +1 -1
- package/dist/codeSign/win/authenticodeSignature.d.ts +71 -0
- package/dist/codeSign/win/authenticodeSignature.d.ts.map +1 -0
- package/dist/codeSign/win/authenticodeSignature.js +241 -0
- package/dist/codeSign/win/authenticodeSignature.js.map +1 -0
- package/dist/codeSign/win/signtoolBaseSignManager.d.ts +11 -0
- package/dist/codeSign/win/signtoolBaseSignManager.d.ts.map +1 -1
- package/dist/codeSign/win/signtoolBaseSignManager.js +36 -16
- package/dist/codeSign/win/signtoolBaseSignManager.js.map +1 -1
- package/dist/codeSign/win/verifyUpdatePublisher.d.ts +25 -0
- package/dist/codeSign/win/verifyUpdatePublisher.d.ts.map +1 -0
- package/dist/codeSign/win/verifyUpdatePublisher.js +98 -0
- package/dist/codeSign/win/verifyUpdatePublisher.js.map +1 -0
- package/dist/configuration.d.ts +16 -13
- package/dist/configuration.d.ts.map +1 -1
- package/dist/configuration.js.map +1 -1
- package/dist/electron/ElectronFramework.d.ts +15 -0
- package/dist/electron/ElectronFramework.d.ts.map +1 -1
- package/dist/electron/ElectronFramework.js +33 -2
- package/dist/electron/ElectronFramework.js.map +1 -1
- package/dist/electron/mac/asarIntegrityDigest.d.ts +10 -0
- package/dist/electron/mac/asarIntegrityDigest.d.ts.map +1 -0
- package/dist/electron/mac/asarIntegrityDigest.js +122 -0
- package/dist/electron/mac/asarIntegrityDigest.js.map +1 -0
- package/dist/electron/mac/electronMac.js +1 -28
- package/dist/electron/mac/electronMac.js.map +1 -1
- package/dist/electron/mac/electronMacUtils.d.ts +8 -0
- package/dist/electron/mac/electronMacUtils.d.ts.map +1 -1
- package/dist/electron/mac/electronMacUtils.js +36 -0
- package/dist/electron/mac/electronMacUtils.js.map +1 -1
- package/dist/fileMatcher.d.ts +47 -12
- package/dist/fileMatcher.d.ts.map +1 -1
- package/dist/fileMatcher.js +150 -45
- package/dist/fileMatcher.js.map +1 -1
- package/dist/forge-maker.d.ts +64 -0
- package/dist/forge-maker.d.ts.map +1 -1
- package/dist/forge-maker.js +104 -2
- package/dist/forge-maker.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/indexInternal.d.ts +5 -3
- package/dist/indexInternal.d.ts.map +1 -1
- package/dist/indexInternal.js +5 -3
- package/dist/indexInternal.js.map +1 -1
- package/dist/macPackager.d.ts +6 -0
- package/dist/macPackager.d.ts.map +1 -1
- package/dist/macPackager.js +48 -2
- package/dist/macPackager.js.map +1 -1
- package/dist/options/FuseOptionsV1.d.ts +4 -0
- package/dist/options/FuseOptionsV1.d.ts.map +1 -1
- package/dist/options/FuseOptionsV1.js.map +1 -1
- package/dist/options/PlatformSpecificBuildOptions.d.ts +166 -8
- package/dist/options/PlatformSpecificBuildOptions.d.ts.map +1 -1
- package/dist/options/PlatformSpecificBuildOptions.js.map +1 -1
- package/dist/options/SnapOptions.d.ts +36 -15
- package/dist/options/SnapOptions.d.ts.map +1 -1
- package/dist/options/SnapOptions.js.map +1 -1
- package/dist/options/linuxOptions.d.ts +53 -18
- package/dist/options/linuxOptions.d.ts.map +1 -1
- package/dist/options/linuxOptions.js.map +1 -1
- package/dist/options/macOptions.d.ts +15 -1
- package/dist/options/macOptions.d.ts.map +1 -1
- package/dist/options/macOptions.js.map +1 -1
- package/dist/options/winOptions.d.ts +7 -4
- package/dist/options/winOptions.d.ts.map +1 -1
- package/dist/options/winOptions.js.map +1 -1
- package/dist/packager.d.ts +2 -0
- package/dist/packager.d.ts.map +1 -1
- package/dist/packager.js +6 -0
- package/dist/packager.js.map +1 -1
- package/dist/platformPackager.d.ts +11 -4
- package/dist/platformPackager.d.ts.map +1 -1
- package/dist/platformPackager.js +53 -18
- package/dist/platformPackager.js.map +1 -1
- package/dist/presets/rectCra.js +3 -1
- package/dist/presets/rectCra.js.map +1 -1
- package/dist/publish/PublishManager.d.ts +6 -1
- package/dist/publish/PublishManager.d.ts.map +1 -1
- package/dist/publish/PublishManager.js +80 -58
- package/dist/publish/PublishManager.js.map +1 -1
- package/dist/publish/updateInfoBuilder.d.ts.map +1 -1
- package/dist/publish/updateInfoBuilder.js +8 -10
- package/dist/publish/updateInfoBuilder.js.map +1 -1
- package/dist/targets/ArchiveTarget.d.ts.map +1 -1
- package/dist/targets/ArchiveTarget.js +7 -1
- package/dist/targets/ArchiveTarget.js.map +1 -1
- package/dist/targets/archive.d.ts +12 -0
- package/dist/targets/archive.d.ts.map +1 -1
- package/dist/targets/archive.js +17 -3
- package/dist/targets/archive.js.map +1 -1
- package/dist/targets/blockmap/blockmap.d.ts +3 -2
- package/dist/targets/blockmap/blockmap.d.ts.map +1 -1
- package/dist/targets/blockmap/blockmap.js +3 -2
- package/dist/targets/blockmap/blockmap.js.map +1 -1
- package/dist/targets/differentialUpdateInfoBuilder.d.ts.map +1 -1
- package/dist/targets/differentialUpdateInfoBuilder.js +4 -0
- package/dist/targets/differentialUpdateInfoBuilder.js.map +1 -1
- package/dist/targets/linux/FlatpakTarget.d.ts +17 -0
- package/dist/targets/linux/FlatpakTarget.d.ts.map +1 -1
- package/dist/targets/linux/FlatpakTarget.js +238 -48
- package/dist/targets/linux/FlatpakTarget.js.map +1 -1
- package/dist/targets/linux/FpmTarget.d.ts.map +1 -1
- package/dist/targets/linux/FpmTarget.js +10 -14
- package/dist/targets/linux/FpmTarget.js.map +1 -1
- package/dist/targets/linux/LinuxTargetHelper.d.ts +1 -3
- package/dist/targets/linux/LinuxTargetHelper.d.ts.map +1 -1
- package/dist/targets/linux/LinuxTargetHelper.js +45 -20
- package/dist/targets/linux/LinuxTargetHelper.js.map +1 -1
- package/dist/targets/linux/appimage/AppImageTarget.d.ts.map +1 -1
- package/dist/targets/linux/appimage/AppImageTarget.js +5 -1
- package/dist/targets/linux/appimage/AppImageTarget.js.map +1 -1
- package/dist/targets/linux/appimage/appImageUtil.d.ts +3 -1
- package/dist/targets/linux/appimage/appImageUtil.d.ts.map +1 -1
- package/dist/targets/linux/appimage/appImageUtil.js +2 -2
- package/dist/targets/linux/appimage/appImageUtil.js.map +1 -1
- package/dist/targets/linux/appimage/appLauncher.d.ts +6 -0
- package/dist/targets/linux/appimage/appLauncher.d.ts.map +1 -1
- package/dist/targets/linux/appimage/appLauncher.js +13 -9
- package/dist/targets/linux/appimage/appLauncher.js.map +1 -1
- package/dist/targets/linux/flatpakBundle.d.ts +43 -0
- package/dist/targets/linux/flatpakBundle.d.ts.map +1 -0
- package/dist/targets/linux/flatpakBundle.js +210 -0
- package/dist/targets/linux/flatpakBundle.js.map +1 -0
- package/dist/targets/linux/snap/core24.d.ts +0 -18
- package/dist/targets/linux/snap/core24.d.ts.map +1 -1
- package/dist/targets/linux/snap/core24.js +29 -100
- package/dist/targets/linux/snap/core24.js.map +1 -1
- package/dist/targets/linux/snap/coreLegacy.d.ts +7 -0
- package/dist/targets/linux/snap/coreLegacy.d.ts.map +1 -1
- package/dist/targets/linux/snap/coreLegacy.js +25 -6
- package/dist/targets/linux/snap/coreLegacy.js.map +1 -1
- package/dist/targets/linux/snap/snapPlugs.d.ts +76 -0
- package/dist/targets/linux/snap/snapPlugs.d.ts.map +1 -0
- package/dist/targets/linux/snap/snapPlugs.js +242 -0
- package/dist/targets/linux/snap/snapPlugs.js.map +1 -0
- package/dist/targets/mac/MacTargetHelper.d.ts +6 -0
- package/dist/targets/mac/MacTargetHelper.d.ts.map +1 -1
- package/dist/targets/mac/MacTargetHelper.js +47 -3
- package/dist/targets/mac/MacTargetHelper.js.map +1 -1
- package/dist/targets/mac/pkg.d.ts.map +1 -1
- package/dist/targets/mac/pkg.js +1 -0
- package/dist/targets/mac/pkg.js.map +1 -1
- package/dist/targets/win/nsis/Defines.d.ts +1 -0
- package/dist/targets/win/nsis/Defines.d.ts.map +1 -1
- package/dist/targets/win/nsis/Defines.js.map +1 -1
- package/dist/targets/win/nsis/NsisTarget.d.ts +8 -1
- package/dist/targets/win/nsis/NsisTarget.d.ts.map +1 -1
- package/dist/targets/win/nsis/NsisTarget.js +36 -5
- package/dist/targets/win/nsis/NsisTarget.js.map +1 -1
- package/dist/targets/win/nsis/nsisOptions.d.ts +6 -4
- package/dist/targets/win/nsis/nsisOptions.d.ts.map +1 -1
- package/dist/targets/win/nsis/nsisOptions.js.map +1 -1
- package/dist/targets/win/nsis/nsisUtil.d.ts.map +1 -1
- package/dist/targets/win/nsis/nsisUtil.js +7 -2
- package/dist/targets/win/nsis/nsisUtil.js.map +1 -1
- package/dist/targets/win/winAppUtil.d.ts +2 -2
- package/dist/targets/win/winAppUtil.d.ts.map +1 -1
- package/dist/targets/win/winAppUtil.js +5 -3
- package/dist/targets/win/winAppUtil.js.map +1 -1
- package/dist/toolsets/appimage.d.ts.map +1 -1
- package/dist/toolsets/appimage.js +19 -19
- package/dist/toolsets/appimage.js.map +1 -1
- package/dist/toolsets/nsis.js +1 -1
- package/dist/toolsets/nsis.js.map +1 -1
- package/dist/toolsets/winCodeSign.d.ts +14 -1
- package/dist/toolsets/winCodeSign.d.ts.map +1 -1
- package/dist/toolsets/winCodeSign.js +14 -1
- package/dist/toolsets/winCodeSign.js.map +1 -1
- package/dist/util/AppFileWalker.js +9 -1
- package/dist/util/AppFileWalker.js.map +1 -1
- package/dist/util/appFileCopier.d.ts +15 -2
- package/dist/util/appFileCopier.d.ts.map +1 -1
- package/dist/util/appFileCopier.js +30 -20
- package/dist/util/appFileCopier.js.map +1 -1
- package/dist/util/config/config.d.ts +1 -1
- package/dist/util/config/config.d.ts.map +1 -1
- package/dist/util/config/config.js +42 -19
- package/dist/util/config/config.js.map +1 -1
- package/dist/util/config/fileOptions.d.ts +52 -0
- package/dist/util/config/fileOptions.d.ts.map +1 -0
- package/dist/util/config/fileOptions.js +210 -0
- package/dist/util/config/fileOptions.js.map +1 -0
- package/dist/util/config/legacyConfigGuard.d.ts.map +1 -1
- package/dist/util/config/legacyConfigGuard.js +31 -4
- package/dist/util/config/legacyConfigGuard.js.map +1 -1
- package/dist/util/config/legacyOptions.d.ts +11 -0
- package/dist/util/config/legacyOptions.d.ts.map +1 -1
- package/dist/util/config/legacyOptions.js +36 -10
- package/dist/util/config/legacyOptions.js.map +1 -1
- package/dist/util/electronGet.d.ts +13 -0
- package/dist/util/electronGet.d.ts.map +1 -1
- package/dist/util/electronGet.js +40 -17
- package/dist/util/electronGet.js.map +1 -1
- package/dist/util/removedEnvVars.d.ts +25 -0
- package/dist/util/removedEnvVars.d.ts.map +1 -0
- package/dist/util/removedEnvVars.js +54 -0
- package/dist/util/removedEnvVars.js.map +1 -0
- package/dist/util/trustedSourceRoots.d.ts +59 -0
- package/dist/util/trustedSourceRoots.d.ts.map +1 -0
- package/dist/util/trustedSourceRoots.js +127 -0
- package/dist/util/trustedSourceRoots.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +18 -17
- package/scheme.json +421 -436
- package/templates/nsis/include/installer.nsh +11 -8
- package/templates/nsis/installSection.nsh +5 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as pkijs from "pkijs";
|
|
2
|
+
/**
|
|
3
|
+
* Values of `System.Management.Automation.SignatureStatus`. `ConvertTo-Json` serializes the enum as its numeric
|
|
4
|
+
* value, which is the representation {@link AuthenticodeSignerInfo} carries.
|
|
5
|
+
*/
|
|
6
|
+
export declare const AuthenticodeSignatureStatus: {
|
|
7
|
+
readonly Valid: 0;
|
|
8
|
+
readonly UnknownError: 1;
|
|
9
|
+
readonly NotSigned: 2;
|
|
10
|
+
readonly HashMismatch: 3;
|
|
11
|
+
readonly NotTrusted: 4;
|
|
12
|
+
readonly NotSupportedFileFormat: 5;
|
|
13
|
+
readonly Incompatible: 6;
|
|
14
|
+
};
|
|
15
|
+
/** Returns the `SignatureStatus` name of a numeric status (e.g. `HashMismatch` for 3), or the number itself when unknown. */
|
|
16
|
+
export declare function authenticodeSignatureStatusName(status: number | null): string;
|
|
17
|
+
/**
|
|
18
|
+
* The embedded Authenticode signature of a Windows executable, as far as the update signature check needs it:
|
|
19
|
+
* - `signed` — the subject of the certificate that made the (primary) signature, in the format Windows reports it
|
|
20
|
+
* (`X509Certificate2.Subject`), plus the numeric `SignatureStatus` (see {@link AuthenticodeSignatureStatus}) when
|
|
21
|
+
* the host can verify it (Windows only)
|
|
22
|
+
* - `unsigned` — the file has no embedded signature
|
|
23
|
+
* - `unreadable` — the signature could not be read (`reason` says why)
|
|
24
|
+
*/
|
|
25
|
+
export type AuthenticodeSignerInfo = {
|
|
26
|
+
readonly type: "signed";
|
|
27
|
+
readonly subject: string;
|
|
28
|
+
readonly status: number | null;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "unsigned";
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "unreadable";
|
|
34
|
+
readonly reason: string;
|
|
35
|
+
};
|
|
36
|
+
export type AuthenticodeSignerReader = (file: string) => Promise<AuthenticodeSignerInfo>;
|
|
37
|
+
/**
|
|
38
|
+
* Reads the signer of a Windows executable's embedded Authenticode signature: on Windows with
|
|
39
|
+
* `Get-AuthenticodeSignature`, the very API electron-updater verifies downloaded updates with; elsewhere by parsing
|
|
40
|
+
* the PE certificate table and its PKCS#7 signature directly (no external tool needed).
|
|
41
|
+
*/
|
|
42
|
+
export declare function readAuthenticodeSigner(file: string): Promise<AuthenticodeSignerInfo>;
|
|
43
|
+
/**
|
|
44
|
+
* 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.
|
|
47
|
+
*/
|
|
48
|
+
export declare function readAuthenticodeSignerWithPowerShell(file: string): Promise<AuthenticodeSignerInfo>;
|
|
49
|
+
/**
|
|
50
|
+
* Formats a certificate name the way Windows reports a certificate subject (`X509Certificate2.Subject`, which
|
|
51
|
+
* electron-updater compares the configured publisher names against): RDNs in reverse encoding order separated by
|
|
52
|
+
* `, `, with the Windows X.500 attribute names (e.g. `S` for the state, not `ST`).
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatWindowsSubjectDn(name: pkijs.RelativeDistinguishedNames): string;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the first `WIN_CERTIFICATE` entry of a PE file's certificate table (the primary Authenticode signature,
|
|
57
|
+
* which is the one Windows reports), or null when the file has no certificate table. Only the headers and the table
|
|
58
|
+
* itself are read, never the whole (possibly huge) installer.
|
|
59
|
+
*/
|
|
60
|
+
export declare function readPeSignatureBlob(file: string): Promise<{
|
|
61
|
+
certificateType: number;
|
|
62
|
+
data: Buffer;
|
|
63
|
+
} | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the subject of the certificate that made the first signer's signature in a DER-encoded PKCS#7 SignedData
|
|
66
|
+
* (`ContentInfo`), formatted the way Windows reports it.
|
|
67
|
+
*/
|
|
68
|
+
export declare function readPkcs7SignerSubject(der: Buffer): string;
|
|
69
|
+
/** Reads the embedded Authenticode signer of a PE file without external tools (works on any host). */
|
|
70
|
+
export declare function readEmbeddedAuthenticodeSigner(file: string): Promise<AuthenticodeSignerInfo>;
|
|
71
|
+
//# sourceMappingURL=authenticodeSignature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticodeSignature.d.ts","sourceRoot":"","sources":["../../../src/codeSign/win/authenticodeSignature.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,C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,wBAAsB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAalG"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import * as asn1js from "asn1js";
|
|
2
|
+
import { escapePowerShellSingleQuotes, parseAuthenticodeSignatureOutput, preparePowerShellExec } from "builder-util-runtime";
|
|
3
|
+
import { execFile } from "child_process";
|
|
4
|
+
import { open } from "fs/promises";
|
|
5
|
+
import * as pkijs from "pkijs";
|
|
6
|
+
/**
|
|
7
|
+
* Values of `System.Management.Automation.SignatureStatus`. `ConvertTo-Json` serializes the enum as its numeric
|
|
8
|
+
* value, which is the representation {@link AuthenticodeSignerInfo} carries.
|
|
9
|
+
*/
|
|
10
|
+
export const AuthenticodeSignatureStatus = {
|
|
11
|
+
Valid: 0,
|
|
12
|
+
UnknownError: 1,
|
|
13
|
+
NotSigned: 2,
|
|
14
|
+
HashMismatch: 3,
|
|
15
|
+
NotTrusted: 4,
|
|
16
|
+
NotSupportedFileFormat: 5,
|
|
17
|
+
Incompatible: 6,
|
|
18
|
+
};
|
|
19
|
+
/** Returns the `SignatureStatus` name of a numeric status (e.g. `HashMismatch` for 3), or the number itself when unknown. */
|
|
20
|
+
export function authenticodeSignatureStatusName(status) {
|
|
21
|
+
if (status == null) {
|
|
22
|
+
return "unknown";
|
|
23
|
+
}
|
|
24
|
+
for (const [name, value] of Object.entries(AuthenticodeSignatureStatus)) {
|
|
25
|
+
if (value === status) {
|
|
26
|
+
return name;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return String(status);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Reads the signer of a Windows executable's embedded Authenticode signature: on Windows with
|
|
33
|
+
* `Get-AuthenticodeSignature`, the very API electron-updater verifies downloaded updates with; elsewhere by parsing
|
|
34
|
+
* the PE certificate table and its PKCS#7 signature directly (no external tool needed).
|
|
35
|
+
*/
|
|
36
|
+
export function readAuthenticodeSigner(file) {
|
|
37
|
+
return process.platform === "win32" ? readAuthenticodeSignerWithPowerShell(file) : readEmbeddedAuthenticodeSigner(file);
|
|
38
|
+
}
|
|
39
|
+
// ─── Windows: Get-AuthenticodeSignature ──────────────────────────────────────
|
|
40
|
+
/**
|
|
41
|
+
* 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.
|
|
44
|
+
*/
|
|
45
|
+
export function readAuthenticodeSignerWithPowerShell(file) {
|
|
46
|
+
const escapedFile = escapePowerShellSingleQuotes(file);
|
|
47
|
+
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
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function getProperty(value, name) {
|
|
76
|
+
return value != null && typeof value === "object" && name in value ? Reflect.get(value, name) : undefined;
|
|
77
|
+
}
|
|
78
|
+
// ─── Windows subject format ─────────────────────────────────────────────────
|
|
79
|
+
// Maps certificate attribute OIDs to the X.500 names Windows uses when it formats a certificate subject
|
|
80
|
+
// (CertNameToStr with CERT_X500_NAME_STR, i.e. `X509Certificate2.Subject` as Get-AuthenticodeSignature reports it).
|
|
81
|
+
// Other OIDs are written as `OID.<dotted oid>`, as Windows does (e.g. `OID.2.5.4.15` in EV certificates).
|
|
82
|
+
const WINDOWS_ATTRIBUTE_TYPE_NAMES = {
|
|
83
|
+
"2.5.4.3": "CN",
|
|
84
|
+
"2.5.4.4": "SN",
|
|
85
|
+
"2.5.4.5": "SERIALNUMBER",
|
|
86
|
+
"2.5.4.6": "C",
|
|
87
|
+
"2.5.4.7": "L",
|
|
88
|
+
"2.5.4.8": "S",
|
|
89
|
+
"2.5.4.9": "STREET",
|
|
90
|
+
"2.5.4.10": "O",
|
|
91
|
+
"2.5.4.11": "OU",
|
|
92
|
+
"2.5.4.12": "T",
|
|
93
|
+
"2.5.4.13": "Description",
|
|
94
|
+
"2.5.4.17": "PostalCode",
|
|
95
|
+
"2.5.4.18": "POBox",
|
|
96
|
+
"2.5.4.20": "Phone",
|
|
97
|
+
"2.5.4.24": "X21Address",
|
|
98
|
+
"2.5.4.42": "G",
|
|
99
|
+
"2.5.4.43": "I",
|
|
100
|
+
"2.5.4.46": "dnQualifier",
|
|
101
|
+
"1.2.840.113549.1.9.1": "E",
|
|
102
|
+
"0.9.2342.19200300.100.1.25": "DC",
|
|
103
|
+
};
|
|
104
|
+
// Windows quotes an RDN value that has leading/trailing white space or contains one of these characters,
|
|
105
|
+
// doubling embedded quotes.
|
|
106
|
+
const NEEDS_WINDOWS_DN_QUOTING = /[,+="\n<>#;]/;
|
|
107
|
+
function quoteWindowsDnValue(value) {
|
|
108
|
+
if (value.length === 0 || value !== value.trim() || NEEDS_WINDOWS_DN_QUOTING.test(value)) {
|
|
109
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Formats a certificate name the way Windows reports a certificate subject (`X509Certificate2.Subject`, which
|
|
115
|
+
* electron-updater compares the configured publisher names against): RDNs in reverse encoding order separated by
|
|
116
|
+
* `, `, with the Windows X.500 attribute names (e.g. `S` for the state, not `ST`).
|
|
117
|
+
*/
|
|
118
|
+
export function formatWindowsSubjectDn(name) {
|
|
119
|
+
return name.typesAndValues
|
|
120
|
+
.map(attribute => {
|
|
121
|
+
const typeName = WINDOWS_ATTRIBUTE_TYPE_NAMES[attribute.type] ?? `OID.${attribute.type}`;
|
|
122
|
+
return `${typeName}=${quoteWindowsDnValue(String(attribute.value.valueBlock.value))}`;
|
|
123
|
+
})
|
|
124
|
+
.reverse()
|
|
125
|
+
.join(", ");
|
|
126
|
+
}
|
|
127
|
+
// ─── Any host: PE certificate table + PKCS#7 ────────────────────────────────
|
|
128
|
+
const WIN_CERT_TYPE_PKCS_SIGNED_DATA = 0x0002;
|
|
129
|
+
// The certificate table of a signed installer is a few KB; anything this large is not a real signature.
|
|
130
|
+
const MAX_CERTIFICATE_TABLE_SIZE = 16 * 1024 * 1024;
|
|
131
|
+
async function readExactly(handle, position, length) {
|
|
132
|
+
const buffer = Buffer.alloc(length);
|
|
133
|
+
const { bytesRead } = await handle.read(buffer, 0, length, position);
|
|
134
|
+
if (bytesRead !== length) {
|
|
135
|
+
throw new Error(`unexpected end of file reading ${length} bytes at offset ${position}`);
|
|
136
|
+
}
|
|
137
|
+
return buffer;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns the first `WIN_CERTIFICATE` entry of a PE file's certificate table (the primary Authenticode signature,
|
|
141
|
+
* which is the one Windows reports), or null when the file has no certificate table. Only the headers and the table
|
|
142
|
+
* itself are read, never the whole (possibly huge) installer.
|
|
143
|
+
*/
|
|
144
|
+
export async function readPeSignatureBlob(file) {
|
|
145
|
+
const handle = await open(file, "r");
|
|
146
|
+
try {
|
|
147
|
+
const { size: fileSize } = await handle.stat();
|
|
148
|
+
const dosHeader = await readExactly(handle, 0, 64);
|
|
149
|
+
if (dosHeader.toString("latin1", 0, 2) !== "MZ") {
|
|
150
|
+
throw new Error("not a PE file (no MZ header)");
|
|
151
|
+
}
|
|
152
|
+
const peHeaderOffset = dosHeader.readUInt32LE(0x3c);
|
|
153
|
+
// PE signature (4) + COFF file header (20)
|
|
154
|
+
const peHeader = await readExactly(handle, peHeaderOffset, 24);
|
|
155
|
+
if (peHeader.toString("latin1", 0, 4) !== "PE\0\0") {
|
|
156
|
+
throw new Error("not a PE file (no PE signature)");
|
|
157
|
+
}
|
|
158
|
+
const optionalHeaderSize = peHeader.readUInt16LE(20);
|
|
159
|
+
const optionalHeader = await readExactly(handle, peHeaderOffset + 24, optionalHeaderSize);
|
|
160
|
+
const magic = optionalHeader.readUInt16LE(0);
|
|
161
|
+
// PE32 / PE32+: offset of NumberOfRvaAndSizes; the data directories follow it
|
|
162
|
+
const rvaCountOffset = magic === 0x10b ? 92 : magic === 0x20b ? 108 : -1;
|
|
163
|
+
if (rvaCountOffset === -1) {
|
|
164
|
+
throw new Error(`unknown optional header magic 0x${magic.toString(16)}`);
|
|
165
|
+
}
|
|
166
|
+
// the certificate table is data directory #4; each entry is VirtualAddress (u32) + Size (u32)
|
|
167
|
+
const securityDirectoryOffset = rvaCountOffset + 4 + 4 * 8;
|
|
168
|
+
if (optionalHeader.length < securityDirectoryOffset + 8 || optionalHeader.readUInt32LE(rvaCountOffset) <= 4) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
// for the certificate table, VirtualAddress is a file offset
|
|
172
|
+
const tableOffset = optionalHeader.readUInt32LE(securityDirectoryOffset);
|
|
173
|
+
const tableSize = optionalHeader.readUInt32LE(securityDirectoryOffset + 4);
|
|
174
|
+
if (tableOffset === 0 || tableSize === 0) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
if (tableSize < 8 || tableSize > MAX_CERTIFICATE_TABLE_SIZE || tableOffset + tableSize > fileSize) {
|
|
178
|
+
throw new Error(`invalid certificate table (offset ${tableOffset}, size ${tableSize}, file size ${fileSize})`);
|
|
179
|
+
}
|
|
180
|
+
const table = await readExactly(handle, tableOffset, tableSize);
|
|
181
|
+
// WIN_CERTIFICATE: dwLength (u32, includes this 8-byte header), wRevision (u16), wCertificateType (u16), bCertificate
|
|
182
|
+
const entryLength = table.readUInt32LE(0);
|
|
183
|
+
if (entryLength < 8 || entryLength > tableSize) {
|
|
184
|
+
throw new Error(`invalid WIN_CERTIFICATE length ${entryLength}`);
|
|
185
|
+
}
|
|
186
|
+
return { certificateType: table.readUInt16LE(6), data: table.subarray(8, entryLength) };
|
|
187
|
+
}
|
|
188
|
+
finally {
|
|
189
|
+
await handle.close();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function toArrayBuffer(buffer) {
|
|
193
|
+
const result = new ArrayBuffer(buffer.byteLength);
|
|
194
|
+
new Uint8Array(result).set(buffer);
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Returns the subject of the certificate that made the first signer's signature in a DER-encoded PKCS#7 SignedData
|
|
199
|
+
* (`ContentInfo`), formatted the way Windows reports it.
|
|
200
|
+
*/
|
|
201
|
+
export function readPkcs7SignerSubject(der) {
|
|
202
|
+
const asn1 = asn1js.fromBER(toArrayBuffer(der));
|
|
203
|
+
if (asn1.offset === -1) {
|
|
204
|
+
throw new Error("invalid PKCS#7 encoding");
|
|
205
|
+
}
|
|
206
|
+
const contentInfo = new pkijs.ContentInfo({ schema: asn1.result });
|
|
207
|
+
if (contentInfo.contentType !== pkijs.id_ContentType_SignedData) {
|
|
208
|
+
throw new Error(`unexpected PKCS#7 content type ${contentInfo.contentType}`);
|
|
209
|
+
}
|
|
210
|
+
const signedData = new pkijs.SignedData({ schema: contentInfo.content });
|
|
211
|
+
const signerInfo = signedData.signerInfos[0];
|
|
212
|
+
if (signerInfo == null) {
|
|
213
|
+
throw new Error("PKCS#7 signature has no signer");
|
|
214
|
+
}
|
|
215
|
+
const sid = signerInfo.sid;
|
|
216
|
+
if (!(sid instanceof pkijs.IssuerAndSerialNumber)) {
|
|
217
|
+
throw new Error("PKCS#7 signer is not identified by issuer and serial number");
|
|
218
|
+
}
|
|
219
|
+
const certificate = (signedData.certificates ?? []).find((it) => it instanceof pkijs.Certificate && it.issuer.isEqual(sid.issuer) && it.serialNumber.isEqual(sid.serialNumber));
|
|
220
|
+
if (certificate == null) {
|
|
221
|
+
throw new Error("the signer certificate is not embedded in the PKCS#7 signature");
|
|
222
|
+
}
|
|
223
|
+
return formatWindowsSubjectDn(certificate.subject);
|
|
224
|
+
}
|
|
225
|
+
/** Reads the embedded Authenticode signer of a PE file without external tools (works on any host). */
|
|
226
|
+
export async function readEmbeddedAuthenticodeSigner(file) {
|
|
227
|
+
try {
|
|
228
|
+
const blob = await readPeSignatureBlob(file);
|
|
229
|
+
if (blob == null) {
|
|
230
|
+
return { type: "unsigned", reason: "the file has no embedded Authenticode signature (empty PE certificate table)" };
|
|
231
|
+
}
|
|
232
|
+
if (blob.certificateType !== WIN_CERT_TYPE_PKCS_SIGNED_DATA) {
|
|
233
|
+
return { type: "unreadable", reason: `unsupported WIN_CERTIFICATE type 0x${blob.certificateType.toString(16)}` };
|
|
234
|
+
}
|
|
235
|
+
return { type: "signed", subject: readPkcs7SignerSubject(blob.data), status: null };
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
return { type: "unreadable", reason: e.message || String(e) };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=authenticodeSignature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticodeSignature.js","sourceRoot":"","sources":["../../../src/codeSign/win/authenticodeSignature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,4BAA4B,EAAE,gCAAgC,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5H,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,KAAK,EAAE,CAAC;IACR,YAAY,EAAE,CAAC;IACf,SAAS,EAAE,CAAC;IACZ,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,CAAC;IACb,sBAAsB,EAAE,CAAC;IACzB,YAAY,EAAE,CAAC;CACP,CAAA;AAEV,6HAA6H;AAC7H,MAAM,UAAU,+BAA+B,CAAC,MAAqB;IACnE,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,EAAE,CAAC;QACxE,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;YACrB,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;AACvB,CAAC;AAiBD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,oCAAoC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,8BAA8B,CAAC,IAAI,CAAC,CAAA;AACzH,CAAC;AAED,gFAAgF;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AC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;IACrF,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/D,CAAC;AACH,CAAC","sourcesContent":["import * as asn1js from \"asn1js\"\nimport { escapePowerShellSingleQuotes, parseAuthenticodeSignatureOutput, preparePowerShellExec } from \"builder-util-runtime\"\nimport { execFile } from \"child_process\"\nimport { open } from \"fs/promises\"\nimport * as pkijs from \"pkijs\"\n\n/**\n * Values of `System.Management.Automation.SignatureStatus`. `ConvertTo-Json` serializes the enum as its numeric\n * value, which is the representation {@link AuthenticodeSignerInfo} carries.\n */\nexport const AuthenticodeSignatureStatus = {\n Valid: 0,\n UnknownError: 1,\n NotSigned: 2,\n HashMismatch: 3,\n NotTrusted: 4,\n NotSupportedFileFormat: 5,\n Incompatible: 6,\n} as const\n\n/** Returns the `SignatureStatus` name of a numeric status (e.g. `HashMismatch` for 3), or the number itself when unknown. */\nexport function authenticodeSignatureStatusName(status: number | null): string {\n if (status == null) {\n return \"unknown\"\n }\n for (const [name, value] of Object.entries(AuthenticodeSignatureStatus)) {\n if (value === status) {\n return name\n }\n }\n return String(status)\n}\n\n/**\n * The embedded Authenticode signature of a Windows executable, as far as the update signature check needs it:\n * - `signed` — the subject of the certificate that made the (primary) signature, in the format Windows reports it\n * (`X509Certificate2.Subject`), plus the numeric `SignatureStatus` (see {@link AuthenticodeSignatureStatus}) when\n * the host can verify it (Windows only)\n * - `unsigned` — the file has no embedded signature\n * - `unreadable` — the signature could not be read (`reason` says why)\n */\nexport type AuthenticodeSignerInfo =\n | { readonly type: \"signed\"; readonly subject: string; readonly status: number | null }\n | { readonly type: \"unsigned\"; readonly reason: string }\n | { readonly type: \"unreadable\"; readonly reason: string }\n\nexport type AuthenticodeSignerReader = (file: string) => Promise<AuthenticodeSignerInfo>\n\n/**\n * Reads the signer of a Windows executable's embedded Authenticode signature: on Windows with\n * `Get-AuthenticodeSignature`, the very API electron-updater verifies downloaded updates with; elsewhere by parsing\n * the PE certificate table and its PKCS#7 signature directly (no external tool needed).\n */\nexport function readAuthenticodeSigner(file: string): Promise<AuthenticodeSignerInfo> {\n return process.platform === \"win32\" ? readAuthenticodeSignerWithPowerShell(file) : readEmbeddedAuthenticodeSigner(file)\n}\n\n// ─── Windows: Get-AuthenticodeSignature ──────────────────────────────────────\n\n/**\n * Reads the signer with `Get-AuthenticodeSignature`, with the helpers electron-updater verifies downloaded updates\n * with (builder-util-runtime: the same PowerShell invocation, path escaping and JSON parsing), so the build sees\n * exactly what the updater will see.\n */\nexport function readAuthenticodeSignerWithPowerShell(file: string): Promise<AuthenticodeSignerInfo> {\n const escapedFile = escapePowerShellSingleQuotes(file)\n return new Promise<AuthenticodeSignerInfo>(resolve => {\n // longer than the updater's 20s: a busy build machine may still be preparing the PowerShell modules on first use,\n // and a timeout here fails the build\n execFile(...preparePowerShellExec(`Get-AuthenticodeSignature -LiteralPath '${escapedFile}' | ConvertTo-Json -Compress`, 60 * 1000), (error, stdout, stderr) => {\n if (error != null) {\n const stderrText = String(stderr ?? \"\").trim()\n resolve({ type: \"unreadable\", reason: `Get-AuthenticodeSignature failed: ${error.message}${stderrText.length > 0 ? `\\n${stderrText}` : \"\"}` })\n return\n }\n let data: unknown\n try {\n data = parseAuthenticodeSignatureOutput(stdout)\n } catch (e: any) {\n resolve({ type: \"unreadable\", reason: `cannot parse Get-AuthenticodeSignature output (${e.message}): ${stdout}` })\n return\n }\n const status = getProperty(data, \"Status\")\n const numericStatus = typeof status === \"number\" ? status : null\n const subject = getProperty(getProperty(data, \"SignerCertificate\"), \"Subject\")\n if (typeof subject !== \"string\") {\n resolve({ type: \"unsigned\", reason: `Get-AuthenticodeSignature reports no signer certificate (status: ${authenticodeSignatureStatusName(numericStatus)})` })\n return\n }\n resolve({ type: \"signed\", subject, status: numericStatus })\n })\n })\n}\n\nfunction getProperty(value: unknown, name: string): unknown {\n return value != null && typeof value === \"object\" && name in value ? Reflect.get(value, name) : undefined\n}\n\n// ─── Windows subject format ─────────────────────────────────────────────────\n\n// Maps certificate attribute OIDs to the X.500 names Windows uses when it formats a certificate subject\n// (CertNameToStr with CERT_X500_NAME_STR, i.e. `X509Certificate2.Subject` as Get-AuthenticodeSignature reports it).\n// Other OIDs are written as `OID.<dotted oid>`, as Windows does (e.g. `OID.2.5.4.15` in EV certificates).\nconst WINDOWS_ATTRIBUTE_TYPE_NAMES: Record<string, string> = {\n \"2.5.4.3\": \"CN\",\n \"2.5.4.4\": \"SN\",\n \"2.5.4.5\": \"SERIALNUMBER\",\n \"2.5.4.6\": \"C\",\n \"2.5.4.7\": \"L\",\n \"2.5.4.8\": \"S\",\n \"2.5.4.9\": \"STREET\",\n \"2.5.4.10\": \"O\",\n \"2.5.4.11\": \"OU\",\n \"2.5.4.12\": \"T\",\n \"2.5.4.13\": \"Description\",\n \"2.5.4.17\": \"PostalCode\",\n \"2.5.4.18\": \"POBox\",\n \"2.5.4.20\": \"Phone\",\n \"2.5.4.24\": \"X21Address\",\n \"2.5.4.42\": \"G\",\n \"2.5.4.43\": \"I\",\n \"2.5.4.46\": \"dnQualifier\",\n \"1.2.840.113549.1.9.1\": \"E\",\n \"0.9.2342.19200300.100.1.25\": \"DC\",\n}\n\n// Windows quotes an RDN value that has leading/trailing white space or contains one of these characters,\n// doubling embedded quotes.\nconst NEEDS_WINDOWS_DN_QUOTING = /[,+=\"\\n<>#;]/\n\nfunction quoteWindowsDnValue(value: string): string {\n if (value.length === 0 || value !== value.trim() || NEEDS_WINDOWS_DN_QUOTING.test(value)) {\n return `\"${value.replace(/\"/g, '\"\"')}\"`\n }\n return value\n}\n\n/**\n * Formats a certificate name the way Windows reports a certificate subject (`X509Certificate2.Subject`, which\n * electron-updater compares the configured publisher names against): RDNs in reverse encoding order separated by\n * `, `, with the Windows X.500 attribute names (e.g. `S` for the state, not `ST`).\n */\nexport function formatWindowsSubjectDn(name: pkijs.RelativeDistinguishedNames): string {\n return name.typesAndValues\n .map(attribute => {\n const typeName = WINDOWS_ATTRIBUTE_TYPE_NAMES[attribute.type] ?? `OID.${attribute.type}`\n return `${typeName}=${quoteWindowsDnValue(String(attribute.value.valueBlock.value))}`\n })\n .reverse()\n .join(\", \")\n}\n\n// ─── Any host: PE certificate table + PKCS#7 ────────────────────────────────\n\nconst WIN_CERT_TYPE_PKCS_SIGNED_DATA = 0x0002\n// The certificate table of a signed installer is a few KB; anything this large is not a real signature.\nconst MAX_CERTIFICATE_TABLE_SIZE = 16 * 1024 * 1024\n\nasync function readExactly(handle: Awaited<ReturnType<typeof open>>, position: number, length: number): Promise<Buffer> {\n const buffer = Buffer.alloc(length)\n const { bytesRead } = await handle.read(buffer, 0, length, position)\n if (bytesRead !== length) {\n throw new Error(`unexpected end of file reading ${length} bytes at offset ${position}`)\n }\n return buffer\n}\n\n/**\n * Returns the first `WIN_CERTIFICATE` entry of a PE file's certificate table (the primary Authenticode signature,\n * which is the one Windows reports), or null when the file has no certificate table. Only the headers and the table\n * itself are read, never the whole (possibly huge) installer.\n */\nexport async function readPeSignatureBlob(file: string): Promise<{ certificateType: number; data: Buffer } | null> {\n const handle = await open(file, \"r\")\n try {\n const { size: fileSize } = await handle.stat()\n const dosHeader = await readExactly(handle, 0, 64)\n if (dosHeader.toString(\"latin1\", 0, 2) !== \"MZ\") {\n throw new Error(\"not a PE file (no MZ header)\")\n }\n const peHeaderOffset = dosHeader.readUInt32LE(0x3c)\n // PE signature (4) + COFF file header (20)\n const peHeader = await readExactly(handle, peHeaderOffset, 24)\n if (peHeader.toString(\"latin1\", 0, 4) !== \"PE\\0\\0\") {\n throw new Error(\"not a PE file (no PE signature)\")\n }\n const optionalHeaderSize = peHeader.readUInt16LE(20)\n const optionalHeader = await readExactly(handle, peHeaderOffset + 24, optionalHeaderSize)\n const magic = optionalHeader.readUInt16LE(0)\n // PE32 / PE32+: offset of NumberOfRvaAndSizes; the data directories follow it\n const rvaCountOffset = magic === 0x10b ? 92 : magic === 0x20b ? 108 : -1\n if (rvaCountOffset === -1) {\n throw new Error(`unknown optional header magic 0x${magic.toString(16)}`)\n }\n // the certificate table is data directory #4; each entry is VirtualAddress (u32) + Size (u32)\n const securityDirectoryOffset = rvaCountOffset + 4 + 4 * 8\n if (optionalHeader.length < securityDirectoryOffset + 8 || optionalHeader.readUInt32LE(rvaCountOffset) <= 4) {\n return null\n }\n // for the certificate table, VirtualAddress is a file offset\n const tableOffset = optionalHeader.readUInt32LE(securityDirectoryOffset)\n const tableSize = optionalHeader.readUInt32LE(securityDirectoryOffset + 4)\n if (tableOffset === 0 || tableSize === 0) {\n return null\n }\n if (tableSize < 8 || tableSize > MAX_CERTIFICATE_TABLE_SIZE || tableOffset + tableSize > fileSize) {\n throw new Error(`invalid certificate table (offset ${tableOffset}, size ${tableSize}, file size ${fileSize})`)\n }\n const table = await readExactly(handle, tableOffset, tableSize)\n // WIN_CERTIFICATE: dwLength (u32, includes this 8-byte header), wRevision (u16), wCertificateType (u16), bCertificate\n const entryLength = table.readUInt32LE(0)\n if (entryLength < 8 || entryLength > tableSize) {\n throw new Error(`invalid WIN_CERTIFICATE length ${entryLength}`)\n }\n return { certificateType: table.readUInt16LE(6), data: table.subarray(8, entryLength) }\n } finally {\n await handle.close()\n }\n}\n\nfunction toArrayBuffer(buffer: Buffer): ArrayBuffer {\n const result = new ArrayBuffer(buffer.byteLength)\n new Uint8Array(result).set(buffer)\n return result\n}\n\n/**\n * Returns the subject of the certificate that made the first signer's signature in a DER-encoded PKCS#7 SignedData\n * (`ContentInfo`), formatted the way Windows reports it.\n */\nexport function readPkcs7SignerSubject(der: Buffer): string {\n const asn1 = asn1js.fromBER(toArrayBuffer(der))\n if (asn1.offset === -1) {\n throw new Error(\"invalid PKCS#7 encoding\")\n }\n const contentInfo = new pkijs.ContentInfo({ schema: asn1.result })\n if (contentInfo.contentType !== pkijs.id_ContentType_SignedData) {\n throw new Error(`unexpected PKCS#7 content type ${contentInfo.contentType}`)\n }\n const signedData = new pkijs.SignedData({ schema: contentInfo.content })\n const signerInfo = signedData.signerInfos[0]\n if (signerInfo == null) {\n throw new Error(\"PKCS#7 signature has no signer\")\n }\n const sid: unknown = signerInfo.sid\n if (!(sid instanceof pkijs.IssuerAndSerialNumber)) {\n throw new Error(\"PKCS#7 signer is not identified by issuer and serial number\")\n }\n const certificate = (signedData.certificates ?? []).find(\n (it): it is pkijs.Certificate => it instanceof pkijs.Certificate && it.issuer.isEqual(sid.issuer) && it.serialNumber.isEqual(sid.serialNumber)\n )\n if (certificate == null) {\n throw new Error(\"the signer certificate is not embedded in the PKCS#7 signature\")\n }\n return formatWindowsSubjectDn(certificate.subject)\n}\n\n/** Reads the embedded Authenticode signer of a PE file without external tools (works on any host). */\nexport async function readEmbeddedAuthenticodeSigner(file: string): Promise<AuthenticodeSignerInfo> {\n try {\n const blob = await readPeSignatureBlob(file)\n if (blob == null) {\n return { type: \"unsigned\", reason: \"the file has no embedded Authenticode signature (empty PE certificate table)\" }\n }\n if (blob.certificateType !== WIN_CERT_TYPE_PKCS_SIGNED_DATA) {\n return { type: \"unreadable\", reason: `unsupported WIN_CERTIFICATE type 0x${blob.certificateType.toString(16)}` }\n }\n return { type: \"signed\", subject: readPkcs7SignerSubject(blob.data), status: null }\n } catch (e: any) {\n return { type: \"unreadable\", reason: e.message || String(e) }\n }\n}\n"]}
|
|
@@ -92,4 +92,15 @@ export declare class SigntoolSignManager extends SigntoolBaseSignManager {
|
|
|
92
92
|
protected computeWindowsSignArgs(options: WindowsSignTaskConfiguration, vm: VmManager): Array<string>;
|
|
93
93
|
protected computeOsslsigncodeArgs(options: WindowsSignTaskConfiguration, vm: VmManager): Array<string>;
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* The hash algorithms to sign `filePath` with, one signing pass each.
|
|
97
|
+
*
|
|
98
|
+
* - `.msi` holds a single signature, so it is signed once: with `sha256` unless `sha1` is the only algorithm requested.
|
|
99
|
+
* - `.appx`, `.msix` and `.msixbundle` are always `sha256`.
|
|
100
|
+
* - Everything else uses the configured list, defaulting to dual signing with `sha1` then `sha256`.
|
|
101
|
+
*
|
|
102
|
+
* Extensions are matched case-insensitively (`app.MSI` is an MSI). An empty list is a configuration error: it would
|
|
103
|
+
* run no signing pass while the file is still reported as signed.
|
|
104
|
+
*/
|
|
105
|
+
export declare function resolveSigningHashAlgorithms(filePath: string, configured: Array<"sha1" | "sha256"> | "sha1" | "sha256" | null | undefined): Array<"sha1" | "sha256">;
|
|
95
106
|
//# sourceMappingURL=signtoolBaseSignManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signtoolBaseSignManager.d.ts","sourceRoot":"","sources":["../../../src/codeSign/win/signtoolBaseSignManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAW,MAAM,sBAAsB,CAAA;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAGL,oBAAoB,EAEpB,2BAA2B,EAE5B,MAAM,6BAA6B,CAAA;AAIpC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAIpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD,MAAM,MAAM,iBAAiB,GAAG,CAAC,aAAa,EAAE,kCAAkC,EAAE,QAAQ,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAE3H,MAAM,WAAW,sBAAuB,SAAQ,kB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C,QAAQ,CAAC;IAIpE,MAAM,CAAC,aAAa,EAAE,kCAAkC,EAAE,QAAQ,EAAE,WAAW;CA2CtF;AAED,qBAAa,mBAAoB,SAAQ,uBAAuB;IAC9D,SAAS,CAAC,sBAAsB,CAAC,OAAO,EAAE,4BAA4B,EAAE,EAAE,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;IA6CrG,SAAS,CAAC,uBAAuB,CAAC,OAAO,EAAE,4BAA4B,EAAE,EAAE,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;CAgCvG;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,GAAG,MAAM,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAepK"}
|
|
@@ -43,6 +43,10 @@ export class SigntoolBaseSignManager {
|
|
|
43
43
|
constructor(packager) {
|
|
44
44
|
this.packager = packager;
|
|
45
45
|
this.computedPublisherName = new Lazy(async () => {
|
|
46
|
+
// `win.sign: false` / `null` signs nothing, so no publisherName is derived or written to app-update.yml.
|
|
47
|
+
if (isWindowsSigningDisabled(this.platformSpecificBuildOptions)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
46
50
|
const signing = getSigntoolFamilyConfig(this.platformSpecificBuildOptions);
|
|
47
51
|
const publisherName = signing?.publisherName;
|
|
48
52
|
if (publisherName === null) {
|
|
@@ -65,8 +69,8 @@ export class SigntoolBaseSignManager {
|
|
|
65
69
|
return [certInfo.commonName];
|
|
66
70
|
}
|
|
67
71
|
// Signed with a certificate without a CN: electron-updater verifies downloaded updates against the publisherName in app-update.yml, so
|
|
68
|
-
// the build needs one.
|
|
69
|
-
if (
|
|
72
|
+
// the build needs one.
|
|
73
|
+
if ((await this.cscInfo.value) != null) {
|
|
70
74
|
throw new InvalidConfigurationError("Windows code signing is configured, but the publisher name cannot be determined at build time (the signing certificate has no Common Name). " +
|
|
71
75
|
"electron-updater verifies the signature of downloaded updates against the publisherName in app-update.yml. " +
|
|
72
76
|
'Set `win.sign.publisherName` to the subject of the certificate that signs your app (e.g. "CN=My Company, O=My Company, C=US"), ' +
|
|
@@ -102,6 +106,11 @@ export class SigntoolBaseSignManager {
|
|
|
102
106
|
// Memoized so the check runs once per build even though signFile is invoked once per file.
|
|
103
107
|
this.explicitPublisherNameValidation = new Lazy(() => this.validateExplicitPublisherName());
|
|
104
108
|
this.cscInfo = new MemoLazy(() => this.platformSpecificBuildOptions, platformSpecificBuildOptions => {
|
|
109
|
+
// `win.sign: false` / `null` signs nothing: no certificate is read (not even from CSC_LINK / WIN_CSC_LINK), so none
|
|
110
|
+
// supplies an AppX/MSIX publisher, a publisherName for app-update.yml or a build-cache digest.
|
|
111
|
+
if (isWindowsSigningDisabled(platformSpecificBuildOptions)) {
|
|
112
|
+
return Promise.resolve(null);
|
|
113
|
+
}
|
|
105
114
|
const signing = getSigntoolFamilyConfig(platformSpecificBuildOptions);
|
|
106
115
|
// signtool is the implicit default when win.sign is unset, so an absent config still
|
|
107
116
|
// honours the WIN_CSC_LINK/cscLink fallback below (hsm/pkcs11 set signing.type explicitly).
|
|
@@ -232,20 +241,7 @@ export class SigntoolBaseSignManager {
|
|
|
232
241
|
}
|
|
233
242
|
async signFile(options) {
|
|
234
243
|
const signing = getSigntoolFamilyConfig(options.options);
|
|
235
|
-
|
|
236
|
-
// msi does not support dual-signing
|
|
237
|
-
if (options.path.endsWith(".msi")) {
|
|
238
|
-
hashes = [hashes != null && !hashes.includes("sha1") ? "sha256" : "sha1"];
|
|
239
|
-
}
|
|
240
|
-
else if (options.path.endsWith(".appx") || options.path.endsWith(".msix") || options.path.endsWith(".msixbundle")) {
|
|
241
|
-
hashes = ["sha256"];
|
|
242
|
-
}
|
|
243
|
-
else if (hashes == null) {
|
|
244
|
-
hashes = ["sha1", "sha256"];
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
hashes = Array.isArray(hashes) ? hashes : [hashes];
|
|
248
|
-
}
|
|
244
|
+
const hashes = resolveSigningHashAlgorithms(options.path, signing?.signingHashAlgorithms);
|
|
249
245
|
const name = this.packager.appInfo.productName;
|
|
250
246
|
const site = await this.packager.appInfo.computePackageUrl();
|
|
251
247
|
const customSign = await resolveFunction(this.packager.appInfo.type, signing?.sign, "sign", await this.packager.getWorkspaceRoot());
|
|
@@ -504,4 +500,28 @@ export class SigntoolSignManager extends SigntoolBaseSignManager {
|
|
|
504
500
|
return args;
|
|
505
501
|
}
|
|
506
502
|
}
|
|
503
|
+
/**
|
|
504
|
+
* The hash algorithms to sign `filePath` with, one signing pass each.
|
|
505
|
+
*
|
|
506
|
+
* - `.msi` holds a single signature, so it is signed once: with `sha256` unless `sha1` is the only algorithm requested.
|
|
507
|
+
* - `.appx`, `.msix` and `.msixbundle` are always `sha256`.
|
|
508
|
+
* - Everything else uses the configured list, defaulting to dual signing with `sha1` then `sha256`.
|
|
509
|
+
*
|
|
510
|
+
* Extensions are matched case-insensitively (`app.MSI` is an MSI). An empty list is a configuration error: it would
|
|
511
|
+
* run no signing pass while the file is still reported as signed.
|
|
512
|
+
*/
|
|
513
|
+
export function resolveSigningHashAlgorithms(filePath, configured) {
|
|
514
|
+
const requested = configured == null ? null : asArray(configured);
|
|
515
|
+
if (requested != null && requested.length === 0) {
|
|
516
|
+
throw new InvalidConfigurationError(`win.sign.signingHashAlgorithms is an empty list, so no signing pass would run. List at least one of "sha1" or "sha256", remove the option to use the default ["sha1", "sha256"], or set win.sign to false to disable Windows signing.`);
|
|
517
|
+
}
|
|
518
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
519
|
+
if (ext === ".msi") {
|
|
520
|
+
return [requested != null && !requested.includes("sha256") ? "sha1" : "sha256"];
|
|
521
|
+
}
|
|
522
|
+
if (ext === ".appx" || ext === ".msix" || ext === ".msixbundle") {
|
|
523
|
+
return ["sha256"];
|
|
524
|
+
}
|
|
525
|
+
return requested ?? ["sha1", "sha256"];
|
|
526
|
+
}
|
|
507
527
|
//# sourceMappingURL=signtoolBaseSignManager.js.map
|