From e6c2c7adcd4b08f8c26a22a76c801b0bf01e0365 Mon Sep 17 00:00:00 2001 From: Jamie Ruderman Date: Fri, 25 Sep 2026 11:09:04 -0700 Subject: [PATCH 1/7] feat(build): choose the Windows signer from the environment and verify every signature after the build --- .github/workflows/build-electron.yml | 27 ++++-- RELEASE.md | 44 ++++++++++ electron/electron-builder.config.js | 5 ++ electron/package.json | 2 +- electron/scripts/verify-win-installers.js | 53 +++++++++++- electron/scripts/win-signing.js | 73 ++++++++++++++++ electron/src/backend/winSigning.test.ts | 100 ++++++++++++++++++++++ 7 files changed, 295 insertions(+), 9 deletions(-) create mode 100644 electron/electron-builder.config.js create mode 100644 electron/scripts/win-signing.js create mode 100644 electron/src/backend/winSigning.test.ts diff --git a/.github/workflows/build-electron.yml b/.github/workflows/build-electron.yml index 4bcdc0578..1af77c6ae 100644 --- a/.github/workflows/build-electron.yml +++ b/.github/workflows/build-electron.yml @@ -19,6 +19,7 @@ on: permissions: contents: write + id-token: write # azure/login (Windows signing) authenticates with an OIDC token, no client secret defaults: run: @@ -97,10 +98,17 @@ jobs: release: needs: prepare runs-on: ${{ matrix.os }} + # Azure's federated credential is keyed on this environment name; a tag ref changes every release. + environment: signing env: GH_TOKEN: ${{ needs.prepare.outputs.release_repo != github.repository && secrets.RELEASE_TOKEN || secrets.github_token }} VERSION: ${{ needs.prepare.outputs.version }} RELEASE_REPO: ${{ needs.prepare.outputs.release_repo }} + # Set all four to sign Windows builds with Microsoft Artifact Signing; unset, SSL.com signs. See RELEASE.md. + AZURE_SIGN_ENDPOINT: ${{ vars.AZURE_SIGN_ENDPOINT }} + AZURE_SIGN_ACCOUNT: ${{ vars.AZURE_SIGN_ACCOUNT }} + AZURE_SIGN_PROFILE: ${{ vars.AZURE_SIGN_PROFILE }} + AZURE_SIGN_PUBLISHER: ${{ vars.AZURE_SIGN_PUBLISHER }} strategy: # One platform failing should not cancel the others - a Linux packaging @@ -132,11 +140,19 @@ jobs: - name: Install SSL.com Sign Tool on Windows shell: bash - if: matrix.os == 'windows-latest' && !inputs.skip_signing + if: matrix.os == 'windows-latest' && !inputs.skip_signing && vars.AZURE_SIGN_ENDPOINT == '' run: | curl https://www.ssl.com/download/codesigntool-for-windows/ --output ~/Downloads/CodeSignTool.zip unzip ~/Downloads/CodeSignTool.zip -d ~/CodeSignTool + - name: Sign in to Azure for Windows signing + if: matrix.os == 'windows-latest' && !inputs.skip_signing && vars.AZURE_SIGN_ENDPOINT != '' + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - name: Install dependencies and build web assets run: | npm install @@ -165,9 +181,10 @@ jobs: cd electron npm run build - # nsis7z silently skips payload entries it cannot decode (3.47.1/3.48.1 ARM64). electron-builder - # has already attached the installers to the draft, so a failure pulls them back out. - - name: Verify Windows installers extract with nsis7z + # nsis7z silently skips payload entries it cannot decode (3.47.1/3.48.1 ARM64), and a signed build + # must be signed by the expected publisher throughout. electron-builder has already attached the + # installers to the draft, so a failure pulls them back out. + - name: Verify Windows installers (payload, signatures) if: matrix.os == 'windows-latest' run: | cd electron @@ -176,7 +193,7 @@ jobs: for f in dist/*-Installer-*.exe dist/*-Installer-*.exe.blockmap dist/latest.yml; do [ -e "$f" ] && gh release delete-asset "$VERSION" "$(basename "$f")" --repo "$RELEASE_REPO" --yes 2>/dev/null || true done - echo "::error::Windows installers removed from draft $VERSION in $RELEASE_REPO - their payload cannot be extracted by nsis7z (see above)" + echo "::error::Windows installers removed from draft $VERSION in $RELEASE_REPO - they failed verification (see above)" fi exit 1 fi diff --git a/RELEASE.md b/RELEASE.md index a83f0f411..ff3b0c72a 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -87,6 +87,8 @@ defaults to `remoteit`; **uncheck `skip_signing`** for a real release, since it defaults to `true`. Only a tag build creates the draft and publishes into it; a branch build compiles and discards everything, so with `skip_signing` off the `prepare` job refuses to start rather than pay for signatures nobody receives. +Which certificate signs a Windows build, and how the result is checked, is under +[Windows code signing](#windows-code-signing). A `prepare` job first resolves the release repository for the selected brand (`brands//config.ts` — `cachengo` publishes to `cachengo/desktop`) and @@ -219,6 +221,48 @@ back into `main` first. Amplify builds the branch. Its build settings live in the Amplify console, not in this repo, so there is no `amplify.yml` here to change. +## Windows code signing + +electron-builder reads a config file _instead of_ package.json's `build`, never +both, so `electron/electron-builder.config.js` spreads the branded `build` and +adds only the signing part, chosen from the environment by +`electron/scripts/win-signing.js`: + +- **`SKIP_SIGNING=true`** (the `skip_signing` input): no signing configuration + at all. Nothing is signed and nothing is verified. +- **`AZURE_SIGN_*` set**: `win.azureSignOptions` — Microsoft Artifact Signing — + plus `forceCodeSigning`, so an artifact the service did not sign fails the build. +- **Otherwise**: the SSL.com eSigner hook in `scripts/sign.js`, as before, plus + `forceCodeSigning`. + +The Azure side is four repository **variables** — `AZURE_SIGN_ENDPOINT` (the +per-region URL, e.g. `https://wus2.codesigning.azure.net`), `AZURE_SIGN_ACCOUNT`, +`AZURE_SIGN_PROFILE`, and `AZURE_SIGN_PUBLISHER` (the certificate subject, +verbatim) — and three **secrets** for `azure/login`: `AZURE_CLIENT_ID`, +`AZURE_TENANT_ID`, `AZURE_SUBSCRIPTION_ID`. Login is OIDC through the `signing` +environment the `release` job runs in, so there is no client secret anywhere. +Setting all four variables is the switch; unset, SSL.com keeps signing; set only +some of them and the build fails rather than guess. + +An Azure-signed build also writes `publisherName` into the app's +`app-update.yml`: the new subject and the SSL.com name `remot3.it, Inc.`. From +that build on, the updater verifies the **next** installer's signature against +that list before running it. Nothing shipped since 3.15 verifies anything today +(the eSigner hook gave electron-builder no certificate to derive a name from), so +the first Azure-signed release installs everywhere and the second is the one that +proves the list. Keep the SSL.com name in the list until that certificate is +retired, so a hotfix signed with it still installs over an Azure-signed release. + +After every signed Windows build, `verify-win-installers.js` runs +`Get-AuthenticodeSignature` — the same call electron-updater makes — on each +installer and on the executables inside its payload (`Remote.It.exe`, +`remoteit.exe`, `connectd.exe`, `muxer.exe`, `demuxer.exe`; electron-builder +signs all of them) and fails the build, removing the installers from the draft, +unless every signature is valid, timestamped, and from an expected publisher. +The expected publisher is `AZURE_SIGN_PUBLISHER` when set and the SSL.com name +otherwise, matched by electron-updater's rule: a full distinguished name must +agree on every attribute it lists, a bare name must equal the certificate's CN. + ## Windows installer payloads The app payload inside each NSIS installer is a 7z archive that NSIS extracts with diff --git a/electron/electron-builder.config.js b/electron/electron-builder.config.js new file mode 100644 index 000000000..70de2f6da --- /dev/null +++ b/electron/electron-builder.config.js @@ -0,0 +1,5 @@ +// electron-builder reads either a config file or package.json's `build`, never both, so this +// spreads the branded package.json config and adds only what depends on the environment. +const { withSigning } = require('./scripts/win-signing') + +module.exports = withSigning(require('./package.json').build, process.env) diff --git a/electron/package.json b/electron/package.json index a412c3718..98590f371 100644 --- a/electron/package.json +++ b/electron/package.json @@ -14,7 +14,7 @@ "build": "cross-env NODE_ENV=production run-s build-frontend brand copy-install copy-entitlements compile verify-binaries build-electron", "build-local": "cross-env NODE_ENV=production run-s copy-env clean build-frontend brand copy-install copy-entitlements compile verify-binaries build-electron", "build-frontend": "cd ../ && npm run build-frontend", - "build-electron": "cross-env NODE_ARCH=$npm_config_arch ELECTRON_BUILDER_7Z_FILTER=BCJ2 electron-builder", + "build-electron": "cross-env NODE_ARCH=$npm_config_arch ELECTRON_BUILDER_7Z_FILTER=BCJ2 electron-builder --config electron-builder.config.js", "clean": "rimraf build/* dist/*", "compile": "run-s typecheck-common typecheck sync-assets", "verify-binaries": "node ./scripts/verify-binaries.js", diff --git a/electron/scripts/verify-win-installers.js b/electron/scripts/verify-win-installers.js index 2f92fbadd..1cad7048a 100755 --- a/electron/scripts/verify-win-installers.js +++ b/electron/scripts/verify-win-installers.js @@ -2,12 +2,15 @@ // nsis7z (built 2019) silently skips payload entries it cannot decode; 3.47.1 and 3.48.1 lost // every executable on Windows ARM64 that way. See RELEASE.md, "Windows installer payloads". +// On a signed build, every executable's signature is also checked the way electron-updater checks +// an installer before running it. See RELEASE.md, "Windows code signing". const fs = require('fs') const os = require('os') const path = require('path') const { spawnSync } = require('child_process') const { archsOf, binaryNames } = require('./verify-binaries') +const { signingMode, expectedPublishers, publisherMatches } = require('./win-signing') const NSIS7Z_CODERS = new Set([ 'LZMA', @@ -30,8 +33,11 @@ const PRODUCT_NAME = process.env.PRODUCT_NAME || require(path.join(__dirname, '. const INSTALLER = new RegExp( `^${PRODUCT_NAME.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}-Installer-(${archsOf('win').join('|')})\\.exe$` ) -const REQUIRED = [`${PRODUCT_NAME}.exe`, 'resources/app.asar', ...binaryNames.map(name => `resources/${name}.exe`)] +const EXECUTABLES = [`${PRODUCT_NAME}.exe`, ...binaryNames.map(name => `resources/${name}.exe`)] +const REQUIRED = [...EXECUTABLES, 'resources/app.asar'] const SEVEN_Z_MAGIC = Buffer.from([0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c]) +const CHECK_SIGNATURES = signingMode(process.env) !== 'skip' +const PUBLISHERS = expectedPublishers(process.env) function sevenZip() { if (process.env.SEVEN_ZIP) return process.env.SEVEN_ZIP @@ -72,8 +78,41 @@ function listEntries(tool, archive) { return entries } +// The command electron-updater runs on a downloaded installer (windowsExecutableCodeSignatureVerifier). +function authenticode(file) { + const command = `Get-AuthenticodeSignature -LiteralPath '${file.replace(/'/g, "''")}' | ConvertTo-Json -Compress` + const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', command], { + encoding: 'utf8', + maxBuffer: 16 * 1024 * 1024, + }) + if (result.status !== 0) + throw new Error(`Get-AuthenticodeSignature failed for ${file}: ${result.stderr || result.stdout}`) + return JSON.parse(result.stdout) +} + +function signatureProblem(file, label) { + const signature = authenticode(file) + const subject = signature.SignerCertificate && signature.SignerCertificate.Subject + if (signature.Status !== 0) return `${label}: signature ${signature.StatusMessage || signature.Status}` + if (!publisherMatches(subject, PUBLISHERS)) { + return `${label}: signed by "${subject}", expected ${PUBLISHERS.map(p => `"${p}"`).join(' or ')}` + } + if (!signature.TimeStamperCertificate) return `${label}: no timestamp countersignature` + return null +} + +function signatureProblems(tool, installer, payload, dir) { + const out = path.join(dir, path.basename(installer, '.exe')) + const names = EXECUTABLES.map(f => f.split('/').join(path.sep)) + const result = spawnSync(tool, ['e', '-y', `-o${out}`, payload, ...names], { encoding: 'utf8' }) + if (result.status !== 0) throw new Error(`${tool} e failed for ${payload}: ${result.stderr || result.stdout}`) + const files = [[installer, path.basename(installer)], ...EXECUTABLES.map(f => [path.join(out, path.basename(f)), f])] + return files.map(([file, label]) => signatureProblem(file, label)).filter(Boolean) +} + function verify(tool, installer, dir) { - const entries = listEntries(tool, extractPayload(installer, dir)) + const payload = extractPayload(installer, dir) + const entries = listEntries(tool, payload) const problems = [] for (const e of entries) { const bad = e.method @@ -84,6 +123,8 @@ function verify(tool, installer, dir) { } const present = new Set(entries.map(e => e.path)) for (const f of REQUIRED) if (!present.has(f)) problems.push(`${f}: missing from payload`) + if (CHECK_SIGNATURES && process.platform === 'win32') + problems.push(...signatureProblems(tool, installer, payload, dir)) const coders = [...new Set(entries.flatMap(e => e.method.split(' ').map(t => t.split(':')[0])))].sort().join(' ') return { entries: entries.length, coders, problems } } @@ -94,6 +135,11 @@ if (installers.length === 0) { console.error(`[verify-win-installers] no ${PRODUCT_NAME}-Installer-*.exe in ${distDir}`) process.exit(1) } +if (CHECK_SIGNATURES && process.platform !== 'win32') { + console.log( + '[verify-win-installers] signatures are checked on Windows only (Get-AuthenticodeSignature); skipping that part' + ) +} const tool = sevenZip() const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'win-installers-')) @@ -106,7 +152,8 @@ try { console.error(`[verify-win-installers] ${name}: ${entries} entries, coders: ${coders}`) for (const p of problems) console.error(` - ${p}`) } else { - console.log(`[verify-win-installers] ${name}: OK (${entries} entries, coders: ${coders})`) + const signed = CHECK_SIGNATURES && process.platform === 'win32' ? `, signed by ${PUBLISHERS[0]}` : '' + console.log(`[verify-win-installers] ${name}: OK (${entries} entries, coders: ${coders}${signed})`) } } } finally { diff --git a/electron/scripts/win-signing.js b/electron/scripts/win-signing.js new file mode 100644 index 000000000..888c2bab3 --- /dev/null +++ b/electron/scripts/win-signing.js @@ -0,0 +1,73 @@ +// Windows signer selection, shared by electron-builder.config.js and verify-win-installers.js. +// See RELEASE.md, "Windows code signing". + +const { parseDn } = require('builder-util-runtime') + +// CN of the SSL.com certificate; desktop <= 3.13.4 accepts an update only from exactly this name. +const LEGACY_PUBLISHER = 'remot3.it, Inc.' + +const AZURE_VARS = { + endpoint: 'AZURE_SIGN_ENDPOINT', + codeSigningAccountName: 'AZURE_SIGN_ACCOUNT', + certificateProfileName: 'AZURE_SIGN_PROFILE', + publisherName: 'AZURE_SIGN_PUBLISHER', +} + +function azureSignOptions(env) { + const given = Object.entries(AZURE_VARS).filter(([, name]) => env[name]) + if (given.length === 0) return null + const missing = Object.values(AZURE_VARS).filter(name => !env[name]) + if (missing.length) throw new Error(`Azure signing is configured but ${missing.join(', ')} not set`) + return { + ...Object.fromEntries(given.map(([key, name]) => [key, env[name]])), + fileDigest: 'SHA256', + timestampRfc3161: 'http://timestamp.acs.microsoft.com', + timestampDigest: 'SHA256', + } +} + +/** 'skip' | 'azure' | 'signtool' */ +function signingMode(env) { + if (env.SKIP_SIGNING === 'true') return 'skip' + return azureSignOptions(env) ? 'azure' : 'signtool' +} + +/** Publisher names a build under `env` must be signed by. */ +function expectedPublishers(env) { + const azure = azureSignOptions(env) + return azure ? [azure.publisherName, LEGACY_PUBLISHER] : [LEGACY_PUBLISHER] +} + +// electron-updater's rule (windowsExecutableCodeSignatureVerifier): a full DN matches when every +// attribute it names equals the signer's; a bare name matches the signer's CN. +function publisherMatches(subject, names) { + const signer = parseDn(subject || '') + return names.some(name => { + const dn = parseDn(name) + return dn.size ? [...dn].every(([key, value]) => signer.get(key) === value) : name === signer.get('CN') + }) +} + +/** The electron-builder config for this build; `base` is package.json's `build` after branding. */ +function withSigning(base, env) { + const { signtoolOptions, ...win } = base.win + switch (signingMode(env)) { + case 'skip': + return { ...base, win } + case 'azure': { + const azure = azureSignOptions(env) + return { + ...base, + forceCodeSigning: true, + win: { ...win, azureSignOptions: azure }, + // Lands in app-update.yml as the list an installed app verifies its NEXT update against. The + // SSL.com name stays until that certificate is retired so a hotfix signed with it still installs. + publish: { provider: 'github', publisherName: [azure.publisherName, LEGACY_PUBLISHER] }, + } + } + default: + return { ...base, forceCodeSigning: true, win: { ...win, signtoolOptions } } + } +} + +module.exports = { LEGACY_PUBLISHER, signingMode, expectedPublishers, publisherMatches, withSigning } diff --git a/electron/src/backend/winSigning.test.ts b/electron/src/backend/winSigning.test.ts new file mode 100644 index 000000000..30ebb3cf7 --- /dev/null +++ b/electron/src/backend/winSigning.test.ts @@ -0,0 +1,100 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { + LEGACY_PUBLISHER, + signingMode, + expectedPublishers, + publisherMatches, + withSigning, +} = require('../../scripts/win-signing') + +const SSL_SUBJECT = + 'CN="remot3.it, Inc.", O="remot3.it, Inc.", L=Palo Alto, S=California, C=US, SERIALNUMBER=4797542, OID.2.5.4.15=Private Organization' +const AZURE_PUBLISHER = 'CN="remot3.it, Inc.", O="remot3.it, Inc.", L=Palo Alto, S=California, C=US' +const AZURE = { + AZURE_SIGN_ENDPOINT: 'https://wus2.codesigning.azure.net', + AZURE_SIGN_ACCOUNT: 'remoteit', + AZURE_SIGN_PROFILE: 'remoteit-public', + AZURE_SIGN_PUBLISHER: AZURE_PUBLISHER, +} +const BASE = { + productName: 'Remote.It', + win: { signtoolOptions: { sign: './scripts/sign.js', signingHashAlgorithms: ['sha256'] }, target: ['nsis'] }, +} + +describe('signingMode', () => { + test('skip wins over everything', () => { + expect(signingMode({ SKIP_SIGNING: 'true', ...AZURE })).toBe('skip') + }) + + test('azure when all four variables are set, signtool when none are', () => { + expect(signingMode(AZURE)).toBe('azure') + expect(signingMode({})).toBe('signtool') + expect(signingMode({ SKIP_SIGNING: 'false' })).toBe('signtool') + }) + + test('a partial Azure configuration is an error, not a silent fallback', () => { + const { AZURE_SIGN_PUBLISHER, ...partial } = AZURE + expect(() => signingMode(partial)).toThrow('AZURE_SIGN_PUBLISHER') + }) +}) + +describe('withSigning', () => { + test('skip removes the signing hook and does not force signing', () => { + const config = withSigning(BASE, { SKIP_SIGNING: 'true' }) + expect(config.win.signtoolOptions).toBeUndefined() + expect(config.win.azureSignOptions).toBeUndefined() + expect(config.forceCodeSigning).toBeUndefined() + expect(config.win.target).toEqual(['nsis']) + }) + + test('signtool keeps the hook and forces signing', () => { + const config = withSigning(BASE, {}) + expect(config.win.signtoolOptions).toEqual(BASE.win.signtoolOptions) + expect(config.forceCodeSigning).toBe(true) + expect(config.publish).toBeUndefined() + }) + + test('azure replaces the hook, forces signing and lists both publishers, new one first', () => { + const config = withSigning(BASE, AZURE) + expect(config.win.signtoolOptions).toBeUndefined() + expect(config.win.azureSignOptions).toEqual({ + endpoint: AZURE.AZURE_SIGN_ENDPOINT, + codeSigningAccountName: 'remoteit', + certificateProfileName: 'remoteit-public', + publisherName: AZURE_PUBLISHER, + fileDigest: 'SHA256', + timestampRfc3161: 'http://timestamp.acs.microsoft.com', + timestampDigest: 'SHA256', + }) + expect(config.forceCodeSigning).toBe(true) + expect(config.publish).toEqual({ provider: 'github', publisherName: [AZURE_PUBLISHER, LEGACY_PUBLISHER] }) + expect(config.productName).toBe('Remote.It') + }) +}) + +describe('expectedPublishers', () => { + test('the SSL.com name alone, or the Azure subject first', () => { + expect(expectedPublishers({})).toEqual([LEGACY_PUBLISHER]) + expect(expectedPublishers(AZURE)).toEqual([AZURE_PUBLISHER, LEGACY_PUBLISHER]) + }) +}) + +describe('publisherMatches', () => { + test('a bare name matches the CN only', () => { + expect(publisherMatches(SSL_SUBJECT, ['remot3.it, Inc.'])).toBe(true) + expect(publisherMatches(SSL_SUBJECT, ['remot3.it, Inc'])).toBe(false) + expect(publisherMatches(SSL_SUBJECT, ['Remot3.it, Inc.'])).toBe(false) + }) + + test('a distinguished name must agree on every attribute it lists', () => { + expect(publisherMatches(SSL_SUBJECT, [AZURE_PUBLISHER])).toBe(true) + expect(publisherMatches(SSL_SUBJECT, ['CN="remot3.it, Inc.", L=Houston'])).toBe(false) + expect(publisherMatches(SSL_SUBJECT, ['CN="remot3.it, Inc.", OU=Desktop'])).toBe(false) + }) + + test('any listed publisher is enough, and no subject matches nothing', () => { + expect(publisherMatches(SSL_SUBJECT, ['CN=Someone Else', LEGACY_PUBLISHER])).toBe(true) + expect(publisherMatches(undefined, [LEGACY_PUBLISHER])).toBe(false) + expect(publisherMatches(SSL_SUBJECT, [])).toBe(false) + }) +}) From e59764cfaa29067c1253e6755aed57db8cdf71c8 Mon Sep 17 00:00:00 2001 From: Jamie Ruderman Date: Fri, 25 Sep 2026 11:09:04 -0700 Subject: [PATCH 2/7] fix(scripts): match an unquoted publisherName block in the upgrade recovery script --- electron/scripts/windows-upgrade-recover.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/electron/scripts/windows-upgrade-recover.ps1 b/electron/scripts/windows-upgrade-recover.ps1 index 865f5de80..10bdcc11e 100644 --- a/electron/scripts/windows-upgrade-recover.ps1 +++ b/electron/scripts/windows-upgrade-recover.ps1 @@ -50,7 +50,8 @@ try { $content = Get-Content $yamlPath -Raw # REMOVE EXACT BLOCK - $pattern = "(?ms)^publisherName:\s*\n\s*-\s*'.*'\r?\n?" + # electron-builder 23 wrote the entry unquoted (`- remot3.it, Inc.`); the block is the header plus every list line under it. + $pattern = "(?m)^publisherName:[ \t]*\r?\n(?:[ \t]+-[^\r\n]*\r?\n?)+" $contentModified = [Regex]::Replace($content, $pattern, "") if ($content -ne $contentModified) { From c449df672409391b659785d5e44ba924a694ceda Mon Sep 17 00:00:00 2001 From: Jamie Ruderman Date: Fri, 25 Sep 2026 11:21:53 -0700 Subject: [PATCH 3/7] refactor(build): apply review findings to the Windows signing config and verifier --- .github/workflows/build-electron.yml | 6 ++- RELEASE.md | 25 +++++----- electron/electron-builder.config.js | 3 ++ electron/scripts/verify-win-installers.js | 57 ++++++++++++----------- electron/scripts/win-signing.js | 42 ++++++----------- electron/src/backend/winSigning.test.ts | 45 +++++++++--------- package-lock.json | 1 + package.json | 1 + 8 files changed, 92 insertions(+), 88 deletions(-) diff --git a/.github/workflows/build-electron.yml b/.github/workflows/build-electron.yml index 1af77c6ae..20f214ed0 100644 --- a/.github/workflows/build-electron.yml +++ b/.github/workflows/build-electron.yml @@ -19,7 +19,6 @@ on: permissions: contents: write - id-token: write # azure/login (Windows signing) authenticates with an OIDC token, no client secret defaults: run: @@ -100,11 +99,14 @@ jobs: runs-on: ${{ matrix.os }} # Azure's federated credential is keyed on this environment name; a tag ref changes every release. environment: signing + permissions: + contents: write + id-token: write env: GH_TOKEN: ${{ needs.prepare.outputs.release_repo != github.repository && secrets.RELEASE_TOKEN || secrets.github_token }} VERSION: ${{ needs.prepare.outputs.version }} RELEASE_REPO: ${{ needs.prepare.outputs.release_repo }} - # Set all four to sign Windows builds with Microsoft Artifact Signing; unset, SSL.com signs. See RELEASE.md. + # See RELEASE.md, "Windows code signing". AZURE_SIGN_ENDPOINT: ${{ vars.AZURE_SIGN_ENDPOINT }} AZURE_SIGN_ACCOUNT: ${{ vars.AZURE_SIGN_ACCOUNT }} AZURE_SIGN_PROFILE: ${{ vars.AZURE_SIGN_PROFILE }} diff --git a/RELEASE.md b/RELEASE.md index ff3b0c72a..274554085 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -229,11 +229,12 @@ adds only the signing part, chosen from the environment by `electron/scripts/win-signing.js`: - **`SKIP_SIGNING=true`** (the `skip_signing` input): no signing configuration - at all. Nothing is signed and nothing is verified. -- **`AZURE_SIGN_*` set**: `win.azureSignOptions` — Microsoft Artifact Signing — - plus `forceCodeSigning`, so an artifact the service did not sign fails the build. -- **Otherwise**: the SSL.com eSigner hook in `scripts/sign.js`, as before, plus - `forceCodeSigning`. + at all. Nothing is signed and nothing is verified. The config file also loads + `electron/.env`, which electron-builder itself would not, so a local build + that sets it there is unsigned too. +- **`AZURE_SIGN_*` set**: `win.azureSignOptions` — Microsoft Artifact Signing. +- **Otherwise**: package.json's `build` untouched, i.e. the SSL.com eSigner hook + in `scripts/sign.js`. The Azure side is four repository **variables** — `AZURE_SIGN_ENDPOINT` (the per-region URL, e.g. `https://wus2.codesigning.azure.net`), `AZURE_SIGN_ACCOUNT`, @@ -254,12 +255,14 @@ proves the list. Keep the SSL.com name in the list until that certificate is retired, so a hotfix signed with it still installs over an Azure-signed release. After every signed Windows build, `verify-win-installers.js` runs -`Get-AuthenticodeSignature` — the same call electron-updater makes — on each -installer and on the executables inside its payload (`Remote.It.exe`, -`remoteit.exe`, `connectd.exe`, `muxer.exe`, `demuxer.exe`; electron-builder -signs all of them) and fails the build, removing the installers from the draft, -unless every signature is valid, timestamped, and from an expected publisher. -The expected publisher is `AZURE_SIGN_PUBLISHER` when set and the SSL.com name +`Get-AuthenticodeSignature` — the cmdlet electron-updater's own check is built +on — over each installer and the executables inside its payload +(`Remote.It.exe`, `remoteit.exe`, `connectd.exe`, `muxer.exe`, `demuxer.exe`; +electron-builder signs all of them) and fails the build, removing the installers +from the draft, unless every signature is valid, timestamped, and from an +expected publisher. This is the guard; electron-builder's `forceCodeSigning` +cannot be, since it only fires when no signing configuration exists at all. The +expected publisher is `AZURE_SIGN_PUBLISHER` when set and the SSL.com name otherwise, matched by electron-updater's rule: a full distinguished name must agree on every attribute it lists, a bare name must equal the certificate's CN. diff --git a/electron/electron-builder.config.js b/electron/electron-builder.config.js index 70de2f6da..08f705081 100644 --- a/electron/electron-builder.config.js +++ b/electron/electron-builder.config.js @@ -1,3 +1,6 @@ +// electron-builder loads electron-builder.env, not the .env that sign.js reads; without this a local +// SKIP_SIGNING=true build would be configured to sign while the hook skips. +require('dotenv').config() // electron-builder reads either a config file or package.json's `build`, never both, so this // spreads the branded package.json config and adds only what depends on the environment. const { withSigning } = require('./scripts/win-signing') diff --git a/electron/scripts/verify-win-installers.js b/electron/scripts/verify-win-installers.js index 1cad7048a..e88f6480a 100755 --- a/electron/scripts/verify-win-installers.js +++ b/electron/scripts/verify-win-installers.js @@ -1,9 +1,8 @@ #!/usr/bin/env node // nsis7z (built 2019) silently skips payload entries it cannot decode; 3.47.1 and 3.48.1 lost -// every executable on Windows ARM64 that way. See RELEASE.md, "Windows installer payloads". -// On a signed build, every executable's signature is also checked the way electron-updater checks -// an installer before running it. See RELEASE.md, "Windows code signing". +// every executable on Windows ARM64 that way. See RELEASE.md, "Windows installer payloads" and +// "Windows code signing". const fs = require('fs') const os = require('os') @@ -36,7 +35,8 @@ const INSTALLER = new RegExp( const EXECUTABLES = [`${PRODUCT_NAME}.exe`, ...binaryNames.map(name => `resources/${name}.exe`)] const REQUIRED = [...EXECUTABLES, 'resources/app.asar'] const SEVEN_Z_MAGIC = Buffer.from([0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c]) -const CHECK_SIGNATURES = signingMode(process.env) !== 'skip' +const SIGNED = signingMode(process.env) !== 'skip' +const CHECK_SIGNATURES = SIGNED && process.platform === 'win32' const PUBLISHERS = expectedPublishers(process.env) function sevenZip() { @@ -78,27 +78,21 @@ function listEntries(tool, archive) { return entries } -// The command electron-updater runs on a downloaded installer (windowsExecutableCodeSignatureVerifier). -function authenticode(file) { - const command = `Get-AuthenticodeSignature -LiteralPath '${file.replace(/'/g, "''")}' | ConvertTo-Json -Compress` +// The cmdlet electron-updater's own check is built on (windowsExecutableCodeSignatureVerifier); +// one PowerShell start covers every file of an installer. +function authenticode(files) { + const list = files.map(f => `'${f.replace(/'/g, "''")}'`).join(',') + const command = + '[Console]::OutputEncoding = [Text.Encoding]::UTF8; ' + + `ConvertTo-Json -Compress -InputObject @(Get-AuthenticodeSignature -LiteralPath ${list} | ` + + "Select-Object Path, Status, StatusMessage, @{n='Subject';e={$_.SignerCertificate.Subject}}, " + + "@{n='TimeStamped';e={$null -ne $_.TimeStamperCertificate}})" const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', command], { encoding: 'utf8', - maxBuffer: 16 * 1024 * 1024, + timeout: 120000, }) - if (result.status !== 0) - throw new Error(`Get-AuthenticodeSignature failed for ${file}: ${result.stderr || result.stdout}`) - return JSON.parse(result.stdout) -} - -function signatureProblem(file, label) { - const signature = authenticode(file) - const subject = signature.SignerCertificate && signature.SignerCertificate.Subject - if (signature.Status !== 0) return `${label}: signature ${signature.StatusMessage || signature.Status}` - if (!publisherMatches(subject, PUBLISHERS)) { - return `${label}: signed by "${subject}", expected ${PUBLISHERS.map(p => `"${p}"`).join(' or ')}` - } - if (!signature.TimeStamperCertificate) return `${label}: no timestamp countersignature` - return null + if (result.status !== 0) throw new Error(`Get-AuthenticodeSignature failed: ${result.stderr || result.stdout}`) + return new Map(JSON.parse(result.stdout).map(s => [s.Path.toLowerCase(), s])) } function signatureProblems(tool, installer, payload, dir) { @@ -107,7 +101,17 @@ function signatureProblems(tool, installer, payload, dir) { const result = spawnSync(tool, ['e', '-y', `-o${out}`, payload, ...names], { encoding: 'utf8' }) if (result.status !== 0) throw new Error(`${tool} e failed for ${payload}: ${result.stderr || result.stdout}`) const files = [[installer, path.basename(installer)], ...EXECUTABLES.map(f => [path.join(out, path.basename(f)), f])] - return files.map(([file, label]) => signatureProblem(file, label)).filter(Boolean) + const signatures = authenticode(files.map(([file]) => file)) + return files.flatMap(([file, label]) => { + const s = signatures.get(path.resolve(file).toLowerCase()) + if (!s) return [`${label}: no signature result`] + if (s.Status !== 0) return [`${label}: signature ${s.StatusMessage || s.Status}`] + if (!publisherMatches(s.Subject, PUBLISHERS)) { + return [`${label}: signed by "${s.Subject}", expected ${PUBLISHERS.map(p => `"${p}"`).join(' or ')}`] + } + if (!s.TimeStamped) return [`${label}: no timestamp countersignature`] + return [] + }) } function verify(tool, installer, dir) { @@ -123,8 +127,7 @@ function verify(tool, installer, dir) { } const present = new Set(entries.map(e => e.path)) for (const f of REQUIRED) if (!present.has(f)) problems.push(`${f}: missing from payload`) - if (CHECK_SIGNATURES && process.platform === 'win32') - problems.push(...signatureProblems(tool, installer, payload, dir)) + if (CHECK_SIGNATURES) problems.push(...signatureProblems(tool, installer, payload, dir)) const coders = [...new Set(entries.flatMap(e => e.method.split(' ').map(t => t.split(':')[0])))].sort().join(' ') return { entries: entries.length, coders, problems } } @@ -135,7 +138,7 @@ if (installers.length === 0) { console.error(`[verify-win-installers] no ${PRODUCT_NAME}-Installer-*.exe in ${distDir}`) process.exit(1) } -if (CHECK_SIGNATURES && process.platform !== 'win32') { +if (SIGNED && !CHECK_SIGNATURES) { console.log( '[verify-win-installers] signatures are checked on Windows only (Get-AuthenticodeSignature); skipping that part' ) @@ -152,7 +155,7 @@ try { console.error(`[verify-win-installers] ${name}: ${entries} entries, coders: ${coders}`) for (const p of problems) console.error(` - ${p}`) } else { - const signed = CHECK_SIGNATURES && process.platform === 'win32' ? `, signed by ${PUBLISHERS[0]}` : '' + const signed = CHECK_SIGNATURES ? `, signed by ${PUBLISHERS[0]}` : '' console.log(`[verify-win-installers] ${name}: OK (${entries} entries, coders: ${coders}${signed})`) } } diff --git a/electron/scripts/win-signing.js b/electron/scripts/win-signing.js index 888c2bab3..9bc8ad7b5 100644 --- a/electron/scripts/win-signing.js +++ b/electron/scripts/win-signing.js @@ -1,4 +1,3 @@ -// Windows signer selection, shared by electron-builder.config.js and verify-win-installers.js. // See RELEASE.md, "Windows code signing". const { parseDn } = require('builder-util-runtime') @@ -14,16 +13,11 @@ const AZURE_VARS = { } function azureSignOptions(env) { - const given = Object.entries(AZURE_VARS).filter(([, name]) => env[name]) - if (given.length === 0) return null - const missing = Object.values(AZURE_VARS).filter(name => !env[name]) + const options = Object.entries(AZURE_VARS).map(([key, name]) => [key, env[name]]) + const missing = options.filter(([, value]) => !value).map(([key]) => AZURE_VARS[key]) + if (missing.length === options.length) return null if (missing.length) throw new Error(`Azure signing is configured but ${missing.join(', ')} not set`) - return { - ...Object.fromEntries(given.map(([key, name]) => [key, env[name]])), - fileDigest: 'SHA256', - timestampRfc3161: 'http://timestamp.acs.microsoft.com', - timestampDigest: 'SHA256', - } + return Object.fromEntries(options) } /** 'skip' | 'azure' | 'signtool' */ @@ -50,23 +44,17 @@ function publisherMatches(subject, names) { /** The electron-builder config for this build; `base` is package.json's `build` after branding. */ function withSigning(base, env) { - const { signtoolOptions, ...win } = base.win - switch (signingMode(env)) { - case 'skip': - return { ...base, win } - case 'azure': { - const azure = azureSignOptions(env) - return { - ...base, - forceCodeSigning: true, - win: { ...win, azureSignOptions: azure }, - // Lands in app-update.yml as the list an installed app verifies its NEXT update against. The - // SSL.com name stays until that certificate is retired so a hotfix signed with it still installs. - publish: { provider: 'github', publisherName: [azure.publisherName, LEGACY_PUBLISHER] }, - } - } - default: - return { ...base, forceCodeSigning: true, win: { ...win, signtoolOptions } } + const win = { ...base.win } + delete win.signtoolOptions + if (env.SKIP_SIGNING === 'true') return { ...base, win } + const azure = azureSignOptions(env) + if (!azure) return base + return { + ...base, + win: { ...win, azureSignOptions: azure }, + // Lands in app-update.yml as the list an installed app verifies its NEXT update against. The + // SSL.com name stays until that certificate is retired so a hotfix signed with it still installs. + publish: { provider: 'github', ...base.publish, publisherName: expectedPublishers(env) }, } } diff --git a/electron/src/backend/winSigning.test.ts b/electron/src/backend/winSigning.test.ts index 30ebb3cf7..a200916aa 100644 --- a/electron/src/backend/winSigning.test.ts +++ b/electron/src/backend/winSigning.test.ts @@ -39,37 +39,40 @@ describe('signingMode', () => { }) describe('withSigning', () => { - test('skip removes the signing hook and does not force signing', () => { + test('skip removes the signing hook and nothing else', () => { const config = withSigning(BASE, { SKIP_SIGNING: 'true' }) - expect(config.win.signtoolOptions).toBeUndefined() - expect(config.win.azureSignOptions).toBeUndefined() - expect(config.forceCodeSigning).toBeUndefined() - expect(config.win.target).toEqual(['nsis']) + expect(config.win).toEqual({ target: ['nsis'] }) + expect(config.productName).toBe('Remote.It') }) - test('signtool keeps the hook and forces signing', () => { - const config = withSigning(BASE, {}) - expect(config.win.signtoolOptions).toEqual(BASE.win.signtoolOptions) - expect(config.forceCodeSigning).toBe(true) - expect(config.publish).toBeUndefined() + test('signtool is the package.json config untouched', () => { + expect(withSigning(BASE, {})).toBe(BASE) }) - test('azure replaces the hook, forces signing and lists both publishers, new one first', () => { + test('azure replaces the hook and lists both publishers, new one first', () => { const config = withSigning(BASE, AZURE) - expect(config.win.signtoolOptions).toBeUndefined() - expect(config.win.azureSignOptions).toEqual({ - endpoint: AZURE.AZURE_SIGN_ENDPOINT, - codeSigningAccountName: 'remoteit', - certificateProfileName: 'remoteit-public', - publisherName: AZURE_PUBLISHER, - fileDigest: 'SHA256', - timestampRfc3161: 'http://timestamp.acs.microsoft.com', - timestampDigest: 'SHA256', + expect(config.win).toEqual({ + target: ['nsis'], + azureSignOptions: { + endpoint: AZURE.AZURE_SIGN_ENDPOINT, + codeSigningAccountName: 'remoteit', + certificateProfileName: 'remoteit-public', + publisherName: AZURE_PUBLISHER, + }, }) - expect(config.forceCodeSigning).toBe(true) expect(config.publish).toEqual({ provider: 'github', publisherName: [AZURE_PUBLISHER, LEGACY_PUBLISHER] }) expect(config.productName).toBe('Remote.It') }) + + test('azure keeps a publish block a brand may have set', () => { + const config = withSigning({ ...BASE, publish: { provider: 'github', owner: 'cachengo', repo: 'desktop' } }, AZURE) + expect(config.publish).toEqual({ + provider: 'github', + owner: 'cachengo', + repo: 'desktop', + publisherName: [AZURE_PUBLISHER, LEGACY_PUBLISHER], + }) + }) }) describe('expectedPublishers', () => { diff --git a/package-lock.json b/package-lock.json index 4a6677309..007cb86a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "capacitor-plugin-safe-area": "^4.0.0" }, "devDependencies": { + "builder-util-runtime": "^9.7.0", "color": "^5.0.0", "cross-env": "^7.0.3", "dotenv": "^17.2.0", diff --git a/package.json b/package.json index 3e50e9e59..1032ee08a 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "capacitor-plugin-safe-area": "^4.0.0" }, "devDependencies": { + "builder-util-runtime": "^9.7.0", "color": "^5.0.0", "cross-env": "^7.0.3", "dotenv": "^17.2.0", From 351ba5fb2680edd22f978a704bffcf4274a7109c Mon Sep 17 00:00:00 2001 From: Jamie Ruderman Date: Fri, 25 Sep 2026 11:26:52 -0700 Subject: [PATCH 4/7] fix(scripts): match signature results by order, ignore Azure vars on unsigned builds and skip signing checks on a broken payload --- electron/scripts/verify-win-installers.js | 41 ++++++++++++++--------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/electron/scripts/verify-win-installers.js b/electron/scripts/verify-win-installers.js index e88f6480a..5ecdd98ee 100755 --- a/electron/scripts/verify-win-installers.js +++ b/electron/scripts/verify-win-installers.js @@ -37,7 +37,7 @@ const REQUIRED = [...EXECUTABLES, 'resources/app.asar'] const SEVEN_Z_MAGIC = Buffer.from([0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c]) const SIGNED = signingMode(process.env) !== 'skip' const CHECK_SIGNATURES = SIGNED && process.platform === 'win32' -const PUBLISHERS = expectedPublishers(process.env) +const PUBLISHERS = SIGNED ? expectedPublishers(process.env) : [] function sevenZip() { if (process.env.SEVEN_ZIP) return process.env.SEVEN_ZIP @@ -78,21 +78,31 @@ function listEntries(tool, archive) { return entries } -// The cmdlet electron-updater's own check is built on (windowsExecutableCodeSignatureVerifier); -// one PowerShell start covers every file of an installer. +// The cmdlet electron-updater's own check is built on (windowsExecutableCodeSignatureVerifier); one +// PowerShell start covers every file of an installer, and the results come back in input order. function authenticode(files) { const list = files.map(f => `'${f.replace(/'/g, "''")}'`).join(',') const command = - '[Console]::OutputEncoding = [Text.Encoding]::UTF8; ' + + '[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false; ' + `ConvertTo-Json -Compress -InputObject @(Get-AuthenticodeSignature -LiteralPath ${list} | ` + - "Select-Object Path, Status, StatusMessage, @{n='Subject';e={$_.SignerCertificate.Subject}}, " + + "Select-Object Status, StatusMessage, @{n='Subject';e={$_.SignerCertificate.Subject}}, " + "@{n='TimeStamped';e={$null -ne $_.TimeStamperCertificate}})" - const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', command], { - encoding: 'utf8', - timeout: 120000, - }) - if (result.status !== 0) throw new Error(`Get-AuthenticodeSignature failed: ${result.stderr || result.stdout}`) - return new Map(JSON.parse(result.stdout).map(s => [s.Path.toLowerCase(), s])) + const result = spawnSync( + 'powershell.exe', + ['-NoProfile', '-NonInteractive', '-InputFormat', 'None', '-Command', command], + { + encoding: 'utf8', + timeout: 120000, + } + ) + if (result.status !== 0) { + throw new Error(`Get-AuthenticodeSignature failed: ${result.error || result.stderr || result.stdout}`) + } + const signatures = JSON.parse(result.stdout.replace(/^\uFEFF/, '')) + if (signatures.length !== files.length) { + throw new Error(`Get-AuthenticodeSignature returned ${signatures.length} results for ${files.length} files`) + } + return signatures } function signatureProblems(tool, installer, payload, dir) { @@ -102,9 +112,8 @@ function signatureProblems(tool, installer, payload, dir) { if (result.status !== 0) throw new Error(`${tool} e failed for ${payload}: ${result.stderr || result.stdout}`) const files = [[installer, path.basename(installer)], ...EXECUTABLES.map(f => [path.join(out, path.basename(f)), f])] const signatures = authenticode(files.map(([file]) => file)) - return files.flatMap(([file, label]) => { - const s = signatures.get(path.resolve(file).toLowerCase()) - if (!s) return [`${label}: no signature result`] + return files.flatMap(([, label], i) => { + const s = signatures[i] if (s.Status !== 0) return [`${label}: signature ${s.StatusMessage || s.Status}`] if (!publisherMatches(s.Subject, PUBLISHERS)) { return [`${label}: signed by "${s.Subject}", expected ${PUBLISHERS.map(p => `"${p}"`).join(' or ')}`] @@ -127,7 +136,7 @@ function verify(tool, installer, dir) { } const present = new Set(entries.map(e => e.path)) for (const f of REQUIRED) if (!present.has(f)) problems.push(`${f}: missing from payload`) - if (CHECK_SIGNATURES) problems.push(...signatureProblems(tool, installer, payload, dir)) + if (CHECK_SIGNATURES && problems.length === 0) problems.push(...signatureProblems(tool, installer, payload, dir)) const coders = [...new Set(entries.flatMap(e => e.method.split(' ').map(t => t.split(':')[0])))].sort().join(' ') return { entries: entries.length, coders, problems } } @@ -155,7 +164,7 @@ try { console.error(`[verify-win-installers] ${name}: ${entries} entries, coders: ${coders}`) for (const p of problems) console.error(` - ${p}`) } else { - const signed = CHECK_SIGNATURES ? `, signed by ${PUBLISHERS[0]}` : '' + const signed = CHECK_SIGNATURES ? ', signatures verified' : '' console.log(`[verify-win-installers] ${name}: OK (${entries} entries, coders: ${coders}${signed})`) } } From 026ef94e4820f9c24485abb62e46930b80ea7548 Mon Sep 17 00:00:00 2001 From: Jamie Ruderman Date: Fri, 25 Sep 2026 12:31:05 -0700 Subject: [PATCH 5/7] feat(scripts): report SSL.com signature findings as warnings and enforce them only under Azure signing --- RELEASE.md | 10 ++++++---- electron/scripts/verify-win-installers.js | 22 ++++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 274554085..24212708d 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -258,10 +258,12 @@ After every signed Windows build, `verify-win-installers.js` runs `Get-AuthenticodeSignature` — the cmdlet electron-updater's own check is built on — over each installer and the executables inside its payload (`Remote.It.exe`, `remoteit.exe`, `connectd.exe`, `muxer.exe`, `demuxer.exe`; -electron-builder signs all of them) and fails the build, removing the installers -from the draft, unless every signature is valid, timestamped, and from an -expected publisher. This is the guard; electron-builder's `forceCodeSigning` -cannot be, since it only fires when no signing configuration exists at all. The +electron-builder signs all of them) and reports any signature that is not valid, +timestamped, and from an expected publisher. Under Azure that fails the build +and removes the installers from the draft; under SSL.com it is a `::warning::` +annotation only, because eSigner bills per signature and a finding must never +force a re-sign. This is the guard; electron-builder's `forceCodeSigning` cannot +be, since it only fires when no signing configuration exists at all. The expected publisher is `AZURE_SIGN_PUBLISHER` when set and the SSL.com name otherwise, matched by electron-updater's rule: a full distinguished name must agree on every attribute it lists, a bare name must equal the certificate's CN. diff --git a/electron/scripts/verify-win-installers.js b/electron/scripts/verify-win-installers.js index 5ecdd98ee..a0efea4b2 100755 --- a/electron/scripts/verify-win-installers.js +++ b/electron/scripts/verify-win-installers.js @@ -35,9 +35,11 @@ const INSTALLER = new RegExp( const EXECUTABLES = [`${PRODUCT_NAME}.exe`, ...binaryNames.map(name => `resources/${name}.exe`)] const REQUIRED = [...EXECUTABLES, 'resources/app.asar'] const SEVEN_Z_MAGIC = Buffer.from([0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c]) -const SIGNED = signingMode(process.env) !== 'skip' -const CHECK_SIGNATURES = SIGNED && process.platform === 'win32' -const PUBLISHERS = SIGNED ? expectedPublishers(process.env) : [] +const MODE = signingMode(process.env) +const CHECK_SIGNATURES = MODE !== 'skip' && process.platform === 'win32' +// eSigner bills per signature: under SSL.com a signature finding is reported, never a reason to re-sign. +const ENFORCE_SIGNATURES = MODE === 'azure' +const PUBLISHERS = MODE === 'skip' ? [] : expectedPublishers(process.env) function sevenZip() { if (process.env.SEVEN_ZIP) return process.env.SEVEN_ZIP @@ -136,9 +138,12 @@ function verify(tool, installer, dir) { } const present = new Set(entries.map(e => e.path)) for (const f of REQUIRED) if (!present.has(f)) problems.push(`${f}: missing from payload`) - if (CHECK_SIGNATURES && problems.length === 0) problems.push(...signatureProblems(tool, installer, payload, dir)) + const warnings = [] + if (CHECK_SIGNATURES && problems.length === 0) { + ;(ENFORCE_SIGNATURES ? problems : warnings).push(...signatureProblems(tool, installer, payload, dir)) + } const coders = [...new Set(entries.flatMap(e => e.method.split(' ').map(t => t.split(':')[0])))].sort().join(' ') - return { entries: entries.length, coders, problems } + return { entries: entries.length, coders, problems, warnings } } const distDir = path.resolve(process.argv[2] || 'dist') @@ -147,7 +152,7 @@ if (installers.length === 0) { console.error(`[verify-win-installers] no ${PRODUCT_NAME}-Installer-*.exe in ${distDir}`) process.exit(1) } -if (SIGNED && !CHECK_SIGNATURES) { +if (MODE !== 'skip' && !CHECK_SIGNATURES) { console.log( '[verify-win-installers] signatures are checked on Windows only (Get-AuthenticodeSignature); skipping that part' ) @@ -158,13 +163,14 @@ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'win-installers-')) let failed = false try { for (const name of installers) { - const { entries, coders, problems } = verify(tool, path.join(distDir, name), tmp) + const { entries, coders, problems, warnings } = verify(tool, path.join(distDir, name), tmp) + for (const w of warnings) console.log(`::warning::[verify-win-installers] ${name}: ${w}`) if (problems.length) { failed = true console.error(`[verify-win-installers] ${name}: ${entries} entries, coders: ${coders}`) for (const p of problems) console.error(` - ${p}`) } else { - const signed = CHECK_SIGNATURES ? ', signatures verified' : '' + const signed = !CHECK_SIGNATURES ? '' : warnings.length ? ', signature warnings above' : ', signatures verified' console.log(`[verify-win-installers] ${name}: OK (${entries} entries, coders: ${coders}${signed})`) } } From 152f15579fc5eaa431a31a60f6d6cf3fc235f7ac Mon Sep 17 00:00:00 2001 From: Jamie Ruderman Date: Fri, 25 Sep 2026 12:37:19 -0700 Subject: [PATCH 6/7] fix(scripts): extract payload executables with their paths so same-named files cannot shadow each other --- electron/scripts/verify-win-installers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/electron/scripts/verify-win-installers.js b/electron/scripts/verify-win-installers.js index a0efea4b2..c6bc6afc5 100755 --- a/electron/scripts/verify-win-installers.js +++ b/electron/scripts/verify-win-installers.js @@ -110,9 +110,9 @@ function authenticode(files) { function signatureProblems(tool, installer, payload, dir) { const out = path.join(dir, path.basename(installer, '.exe')) const names = EXECUTABLES.map(f => f.split('/').join(path.sep)) - const result = spawnSync(tool, ['e', '-y', `-o${out}`, payload, ...names], { encoding: 'utf8' }) - if (result.status !== 0) throw new Error(`${tool} e failed for ${payload}: ${result.stderr || result.stdout}`) - const files = [[installer, path.basename(installer)], ...EXECUTABLES.map(f => [path.join(out, path.basename(f)), f])] + const result = spawnSync(tool, ['x', '-y', `-o${out}`, payload, ...names], { encoding: 'utf8' }) + if (result.status !== 0) throw new Error(`${tool} x failed for ${payload}: ${result.stderr || result.stdout}`) + const files = [[installer, path.basename(installer)], ...EXECUTABLES.map(f => [path.join(out, ...f.split('/')), f])] const signatures = authenticode(files.map(([file]) => file)) return files.flatMap(([, label], i) => { const s = signatures[i] From 4126ac24eb94e1ea2dd546160e27ca88b9bde634 Mon Sep 17 00:00:00 2001 From: Jamie Ruderman Date: Fri, 25 Sep 2026 12:44:17 -0700 Subject: [PATCH 7/7] fix(ci): run only the Azure-signed Windows leg in the signing environment and verify Azure builds against the Azure publisher alone --- .github/workflows/build-electron.yml | 5 +++-- RELEASE.md | 6 ++++-- electron/scripts/verify-win-installers.js | 9 ++++----- electron/scripts/win-signing.js | 10 +++++----- electron/src/backend/winSigning.test.ts | 18 +++++++++++++----- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-electron.yml b/.github/workflows/build-electron.yml index 20f214ed0..7883255f7 100644 --- a/.github/workflows/build-electron.yml +++ b/.github/workflows/build-electron.yml @@ -97,8 +97,9 @@ jobs: release: needs: prepare runs-on: ${{ matrix.os }} - # Azure's federated credential is keyed on this environment name; a tag ref changes every release. - environment: signing + # Azure's federated credential trusts OIDC tokens whose subject names the `signing` environment (a tag ref + # changes every release), so only the leg that signs with Azure runs there; the others cannot mint such a token. + environment: ${{ matrix.os == 'windows-latest' && !inputs.skip_signing && vars.AZURE_SIGN_ENDPOINT != '' && 'signing' || 'build' }} permissions: contents: write id-token: write diff --git a/RELEASE.md b/RELEASE.md index 24212708d..cc2d92638 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -265,8 +265,10 @@ annotation only, because eSigner bills per signature and a finding must never force a re-sign. This is the guard; electron-builder's `forceCodeSigning` cannot be, since it only fires when no signing configuration exists at all. The expected publisher is `AZURE_SIGN_PUBLISHER` when set and the SSL.com name -otherwise, matched by electron-updater's rule: a full distinguished name must -agree on every attribute it lists, a bare name must equal the certificate's CN. +otherwise — under Azure the SSL.com name is *not* accepted, so a build that was +still signed by eSigner cannot pass as migrated — matched by electron-updater's +rule: a full distinguished name must agree on every attribute it lists, a bare +name must equal the certificate's CN. ## Windows installer payloads diff --git a/electron/scripts/verify-win-installers.js b/electron/scripts/verify-win-installers.js index c6bc6afc5..3a533b23c 100755 --- a/electron/scripts/verify-win-installers.js +++ b/electron/scripts/verify-win-installers.js @@ -9,7 +9,7 @@ const os = require('os') const path = require('path') const { spawnSync } = require('child_process') const { archsOf, binaryNames } = require('./verify-binaries') -const { signingMode, expectedPublishers, publisherMatches } = require('./win-signing') +const { signingMode, expectedPublisher, publisherMatches } = require('./win-signing') const NSIS7Z_CODERS = new Set([ 'LZMA', @@ -39,7 +39,7 @@ const MODE = signingMode(process.env) const CHECK_SIGNATURES = MODE !== 'skip' && process.platform === 'win32' // eSigner bills per signature: under SSL.com a signature finding is reported, never a reason to re-sign. const ENFORCE_SIGNATURES = MODE === 'azure' -const PUBLISHERS = MODE === 'skip' ? [] : expectedPublishers(process.env) +const PUBLISHER = MODE === 'skip' ? null : expectedPublisher(process.env) function sevenZip() { if (process.env.SEVEN_ZIP) return process.env.SEVEN_ZIP @@ -117,9 +117,8 @@ function signatureProblems(tool, installer, payload, dir) { return files.flatMap(([, label], i) => { const s = signatures[i] if (s.Status !== 0) return [`${label}: signature ${s.StatusMessage || s.Status}`] - if (!publisherMatches(s.Subject, PUBLISHERS)) { - return [`${label}: signed by "${s.Subject}", expected ${PUBLISHERS.map(p => `"${p}"`).join(' or ')}`] - } + if (!publisherMatches(s.Subject, [PUBLISHER])) + return [`${label}: signed by "${s.Subject}", expected "${PUBLISHER}"`] if (!s.TimeStamped) return [`${label}: no timestamp countersignature`] return [] }) diff --git a/electron/scripts/win-signing.js b/electron/scripts/win-signing.js index 9bc8ad7b5..9edc2225b 100644 --- a/electron/scripts/win-signing.js +++ b/electron/scripts/win-signing.js @@ -26,10 +26,10 @@ function signingMode(env) { return azureSignOptions(env) ? 'azure' : 'signtool' } -/** Publisher names a build under `env` must be signed by. */ -function expectedPublishers(env) { +/** The one publisher a build under `env` must be signed by. */ +function expectedPublisher(env) { const azure = azureSignOptions(env) - return azure ? [azure.publisherName, LEGACY_PUBLISHER] : [LEGACY_PUBLISHER] + return azure ? azure.publisherName : LEGACY_PUBLISHER } // electron-updater's rule (windowsExecutableCodeSignatureVerifier): a full DN matches when every @@ -54,8 +54,8 @@ function withSigning(base, env) { win: { ...win, azureSignOptions: azure }, // Lands in app-update.yml as the list an installed app verifies its NEXT update against. The // SSL.com name stays until that certificate is retired so a hotfix signed with it still installs. - publish: { provider: 'github', ...base.publish, publisherName: expectedPublishers(env) }, + publish: { provider: 'github', ...base.publish, publisherName: [azure.publisherName, LEGACY_PUBLISHER] }, } } -module.exports = { LEGACY_PUBLISHER, signingMode, expectedPublishers, publisherMatches, withSigning } +module.exports = { LEGACY_PUBLISHER, signingMode, expectedPublisher, publisherMatches, withSigning } diff --git a/electron/src/backend/winSigning.test.ts b/electron/src/backend/winSigning.test.ts index a200916aa..3ae4fa474 100644 --- a/electron/src/backend/winSigning.test.ts +++ b/electron/src/backend/winSigning.test.ts @@ -2,7 +2,7 @@ const { LEGACY_PUBLISHER, signingMode, - expectedPublishers, + expectedPublisher, publisherMatches, withSigning, } = require('../../scripts/win-signing') @@ -75,14 +75,22 @@ describe('withSigning', () => { }) }) -describe('expectedPublishers', () => { - test('the SSL.com name alone, or the Azure subject first', () => { - expect(expectedPublishers({})).toEqual([LEGACY_PUBLISHER]) - expect(expectedPublishers(AZURE)).toEqual([AZURE_PUBLISHER, LEGACY_PUBLISHER]) +describe('expectedPublisher', () => { + test('the SSL.com name, or under Azure the Azure subject alone', () => { + expect(expectedPublisher({})).toBe(LEGACY_PUBLISHER) + expect(expectedPublisher(AZURE)).toBe(AZURE_PUBLISHER) }) }) describe('publisherMatches', () => { + test('the subject as Windows PowerShell renders it, OID attributes first', () => { + const windows = + 'OID.1.3.6.1.4.1.311.60.2.1.3=US, OID.1.3.6.1.4.1.311.60.2.1.2=Delaware, OID.2.5.4.15=Private Organization, CN="remot3.it, Inc.", SERIALNUMBER=4797542, O="remot3.it, Inc.", L=Palo Alto, S=California, C=US' + expect(publisherMatches(windows, [LEGACY_PUBLISHER])).toBe(true) + expect(publisherMatches(windows, [AZURE_PUBLISHER])).toBe(true) + expect(publisherMatches(windows, ['CN=Someone Else'])).toBe(false) + }) + test('a bare name matches the CN only', () => { expect(publisherMatches(SSL_SUBJECT, ['remot3.it, Inc.'])).toBe(true) expect(publisherMatches(SSL_SUBJECT, ['remot3.it, Inc'])).toBe(false)