Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(update): stop signing the Windows installer with the macOS certificate

yhha46ef09e08b1
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index 7b5507de3..6a9223c70 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -18,6 +18,13 @@ on:
# instead of updating in place (electron/autoUpdate.ts settles that by reading the
# running bundle's own signature). Windows needs no certificate to auto-update; one
# would buy a quiet SmartScreen, not the capability.
+#
+# Those secrets are macOS's alone, and the packager step scopes them to that leg on
+# purpose. `CSC_LINK` is electron-builder's PLATFORM-NEUTRAL certificate variable:
+# exported to the Windows leg it signs the installer with the Apple certificate,
+# which Windows cannot chain to a trusted root — and electron-updater refuses to
+# install any update whose signature is not Valid. v0.36.0 shipped that way, so every
+# Windows install from it is stuck on the download link until it is reinstalled once.
# Read by default; the two jobs that touch the release raise it to contents:write.
permissions:
@@ -264,12 +271,22 @@ jobs:
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- CSC_LINK: ${{ secrets.MAC_CSC_LINK }}
- CSC_KEY_PASSWORD: ${{ secrets.MAC_CSC_KEY_PASSWORD }}
+ # macOS ONLY. CSC_LINK is electron-builder's platform-NEUTRAL certificate
+ # variable: handed to the Windows leg it signs the NSIS installer with the
+ # Apple Developer ID .p12 (windowsSignToolManager falls back to CSC_LINK
+ # when WIN_CSC_LINK is unset), producing an installer whose chain Windows
+ # cannot build to a trusted root — and stamping that identity into
+ # app-update.yml as `publisherName`. electron-updater then demands an
+ # Authenticode status of Valid before installing, so every Windows
+ # auto-update is refused AFTER downloading the whole installer. An empty
+ # value reads as absent (getCscLink treats "" as null), so the Windows leg
+ # ships unsigned, which is what this project intends.
+ CSC_LINK: ${{ matrix.platform == 'macos-latest' && secrets.MAC_CSC_LINK || '' }}
+ CSC_KEY_PASSWORD: ${{ matrix.platform == 'macos-latest' && secrets.MAC_CSC_KEY_PASSWORD || '' }}
# An app-specific password, NOT the Apple ID's own.
- APPLE_ID: ${{ secrets.APPLE_ID }}
- APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
- APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
+ APPLE_ID: ${{ matrix.platform == 'macos-latest' && secrets.APPLE_ID || '' }}
+ APPLE_APP_SPECIFIC_PASSWORD: ${{ matrix.platform == 'macos-latest' && secrets.APPLE_APP_SPECIFIC_PASSWORD || '' }}
+ APPLE_TEAM_ID: ${{ matrix.platform == 'macos-latest' && secrets.APPLE_TEAM_ID || '' }}
# electron-builder's GitHub publisher dedups assets on re-upload, so the
# whole command is idempotent — retry it to ride out GitHub API 5xx
# blips (a 503 on GET /releases has failed an otherwise-finished build
@@ -293,13 +310,43 @@ jobs:
- name: Package desktop app (dry run, no publish)
if: github.event_name != 'push'
env:
- CSC_LINK: ${{ secrets.MAC_CSC_LINK }}
- CSC_KEY_PASSWORD: ${{ secrets.MAC_CSC_KEY_PASSWORD }}
- APPLE_ID: ${{ secrets.APPLE_ID }}
- APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
- APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
+ # macOS only — see the publish step above for why the Windows leg must
+ # never see a certificate meant for the other platform.
+ CSC_LINK: ${{ matrix.platform == 'macos-latest' && secrets.MAC_CSC_LINK || '' }}
+ CSC_KEY_PASSWORD: ${{ matrix.platform == 'macos-latest' && secrets.MAC_CSC_KEY_PASSWORD || '' }}
+ APPLE_ID: ${{ matrix.platform == 'macos-latest' && secrets.APPLE_ID || '' }}
+ APPLE_APP_SPECIFIC_PASSWORD: ${{ matrix.platform == 'macos-latest' && secrets.APPLE_APP_SPECIFIC_PASSWORD || '' }}
+ APPLE_TEAM_ID: ${{ matrix.platform == 'macos-latest' && secrets.APPLE_TEAM_ID || '' }}
run: pnpm --filter ./desktop exec electron-builder --publish never
+ # The invariant an update depends on, checked where it is cheap to check.
+ # electron-updater installs a Windows update only when Get-AuthenticodeSignature
+ # reports Valid, so an installer carrying a signature Windows will not accept is
+ # strictly worse than an unsigned one: it poisons `publisherName` in
+ # app-update.yml and every future update from that install is refused. Unsigned
+ # is fine (nothing to verify) and properly signed is fine; the state between
+ # them is the one that has already shipped once, so fail the release on it.
+ #
+ # It runs after publish rather than before because electron-builder packages and
+ # uploads in one command — which is enough, since releases are created as DRAFTS
+ # and a maintainer publishes them: a red job is seen before anyone can download.
+ - name: Windows installer must be unsigned or validly signed
+ if: runner.os == 'Windows'
+ shell: pwsh
+ run: |
+ $bad = @()
+ foreach ($exe in Get-ChildItem desktop/release/*.exe) {
+ $sig = Get-AuthenticodeSignature -LiteralPath $exe.FullName
+ Write-Host "$($exe.Name): $($sig.Status)"
+ if ($sig.Status -ne 'NotSigned' -and $sig.Status -ne 'Valid') {
+ $bad += "$($exe.Name) is signed but Windows reports '$($sig.Status)' ($($sig.StatusMessage)); signer: $($sig.SignerCertificate.Subject)"
+ }
+ }
+ if ($bad) {
+ Write-Error ("Windows auto-update would be refused by every installed editor:`n" + ($bad -join "`n"))
+ exit 1
+ }
+
- name: Upload installer artifact (dry run)
if: github.event_name != 'push'
uses: actions/upload-artifact@v7
diff --git a/desktop/electron/autoUpdate.ts b/desktop/electron/autoUpdate.ts
index 8b8179417..6ae9b16bf 100644
--- a/desktop/electron/autoUpdate.ts
+++ b/desktop/electron/autoUpdate.ts
@@ -7,11 +7,14 @@
* and the handover to the installer; updateCheck.ts remains the fallback.
* The two never both decide — `findUpdate` picks one and reports which.
*
- * Two builds cannot install an update. An unpackaged one has no
- * app-update.yml to read. An UNSIGNED macOS bundle reads one, downloads
- * the entire update, and only then does Squirrel.Mac refuse it for want of
- * a signature — so the signature is settled up front, and a build that
- * would fail at the end never starts.
+ * Three builds cannot install an update, and two of them only find out at
+ * the very end. An unpackaged one has no app-update.yml to read. An
+ * UNSIGNED macOS bundle reads one, downloads the entire update, and only
+ * then does Squirrel.Mac refuse it for want of a signature. A Windows
+ * install whose app-update.yml names a publisher its own executable cannot
+ * satisfy is refused the same way, by electron-updater, after the same
+ * full download. So the signature is settled up front on both, and a build
+ * that would fail at the end never starts.
*
* The feed is the mirror before the origin, for the reason the update
* check and the runtime templates already ask a mirror first: the origin
@@ -20,9 +23,11 @@
* so pointing at one is a base swap and nothing else.
*/
import path from 'node:path';
+import { readFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { app } from 'electron';
import { checkForUpdate, updateFeeds, type LatestRelease } from './updateCheck';
+import { publisherNameIn, signatureSatisfies, type AuthenticodeProbe } from './updateSignature';
/** Where a self-installing update sends anyone who would rather read about it first. */
const RELEASE_PAGE = 'https://github.com/esengine/estella/releases/latest';
@@ -92,11 +97,60 @@ function macBundleIsSigned(): boolean {
return macSignature;
}
+let winVerifiable: boolean | null = null;
+
+/** `Get-AuthenticodeSignature` on a file, or null when Windows could not be asked. */
+function probeAuthenticode(file: string): AuthenticodeProbe | null {
+ try {
+ const ps = spawnSync(
+ 'powershell.exe',
+ ['-NoProfile', '-NonInteractive', '-Command',
+ `Get-AuthenticodeSignature -LiteralPath '${file.replace(/'/g, "''")}' | ConvertTo-Json -Compress -Depth 3`],
+ { encoding: 'utf8', timeout: 20_000, windowsHide: true },
+ );
+ // Strip a leading BOM: a console whose code page PowerShell switches emits one,
+ // and JSON.parse rejects it — which would read as "could not ask Windows" and
+ // quietly promise a self-install that the updater then refuses.
+ const out = ps.stdout?.replace(/^/, '');
+ return ps.status === 0 && out ? (JSON.parse(out) as AuthenticodeProbe) : null;
+ } catch {
+ return null;
+ }
+}
+
+/**
+ * Whether an update could clear electron-updater's Windows signature check here.
+ *
+ * The running executable came off the same signing pipeline the update will, so
+ * Windows's verdict on it is the verdict the update will get — and asking now is
+ * the difference between a link and a download that is refused at 100%. Cached:
+ * neither the pin nor the executable changes while the editor runs.
+ */
+function winUpdateCanVerify(): boolean {
+ if (winVerifiable === null) {
+ let publisher: string | null = null;
+ try {
+ publisher = publisherNameIn(readFileSync(path.join(process.resourcesPath, 'app-update.yml'), 'utf8'));
+ } catch {
+ publisher = null; // no app-update.yml ⇒ the updater verifies nothing
+ }
+ winVerifiable = publisher === null || signatureSatisfies(publisher, probeAuthenticode(process.execPath));
+ if (!winVerifiable) {
+ console.warn(
+ `[update] this install pins publisher "${publisher}", which Windows will not vouch for on its own ` +
+ `executable — in-place updates cannot be verified here, so the editor links to the download instead. ` +
+ `Reinstalling from the release page clears it.`,
+ );
+ }
+ }
+ return winVerifiable;
+}
+
/** Whether this build can download and install an update in place. */
export function canSelfInstall(): boolean {
if (!app.isPackaged) return false;
if (process.platform === 'darwin') return macBundleIsSigned();
- return process.platform === 'win32';
+ return process.platform === 'win32' && winUpdateCanVerify();
}
/** Reached a feed and got an answer, or reached none at all. */
diff --git a/desktop/electron/updateSignature.ts b/desktop/electron/updateSignature.ts
new file mode 100644
index 000000000..b61011de9
--- /dev/null
+++ b/desktop/electron/updateSignature.ts
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file updateSignature.ts — can a Windows update from this pipeline install here?
+ *
+ * electron-updater checks a downloaded installer's Authenticode signature ONLY
+ * when the INSTALLED app-update.yml names a `publisherName`, and it then demands
+ * a status of Valid — a matching name is not enough. Both conditions come from
+ * the running install, so both can be read before anything is downloaded, which
+ * is the point: the refusal otherwise lands after the whole installer is on disk.
+ *
+ * That is not hypothetical. A release signed the Windows installer with the
+ * project's macOS Developer ID certificate (electron-builder's CSC_LINK is
+ * platform-neutral and the Windows CI leg saw it), so those installs carry a
+ * publisherName Windows can never report Valid — no certificate chain to a
+ * trusted root. They can never update in place again and must be reinstalled
+ * once; what this decides is whether the editor says so before or after a
+ * hundred-megabyte download.
+ *
+ * The rules mirror electron-updater's own verifier exactly, including its
+ * forgiving edges — no publisher pinned passes, and a probe that could not run
+ * passes — so this never refuses an update the updater would have accepted.
+ *
+ * Pure (parsing + comparison only) → unit-testable; the fs/PowerShell half lives
+ * in autoUpdate.ts.
+ */
+
+/** The subset of `Get-AuthenticodeSignature | ConvertTo-Json` this needs. */
+export interface AuthenticodeProbe {
+ /** 0 is `Valid`; every other value is a reason Windows will not vouch for it. */
+ Status?: number;
+ StatusMessage?: string;
+ SignerCertificate?: { Subject?: string } | null;
+}
+
+/**
+ * The `publisherName` an installed `app-update.yml` pins, or null when it pins
+ * none (an unsigned build — nothing to verify, so nothing to fail).
+ *
+ * Read with a line scan rather than a YAML parser: this runs in the main process
+ * on the update path, the file is machine-written by electron-builder, and the one
+ * key needed is a plain scalar. A list-valued `publisherName` (electron-builder
+ * allows several) yields its first entry — enough to answer "is verification on".
+ */
+export function publisherNameIn(appUpdateYml: string): string | null {
+ const lines = appUpdateYml.split(/\r?\n/);
+ for (let i = 0; i < lines.length; i++) {
+ const m = /^publisherName:\s*(.*)$/.exec(lines[i]);
+ if (!m) continue;
+ const inline = unquote(m[1]);
+ if (inline) return inline;
+ // `publisherName:` followed by a `- name` block.
+ const item = /^\s*-\s*(.+)$/.exec(lines[i + 1] ?? '');
+ return item ? unquote(item[1]) || null : null;
+ }
+ return null;
+}
+
+function unquote(raw: string): string {
+ const s = raw.trim();
+ if (s.length >= 2 && ((s.startsWith("'") && s.endsWith("'")) || (s.startsWith('"') && s.endsWith('"')))) {
+ return s.slice(1, -1);
+ }
+ return s;
+}
+
+/** `CN=a, O=b` → Map. Mirrors builder-util-runtime's parseDn (used by the verifier). */
+function parseDn(seq: string): Map<string, string> {
+ const out = new Map<string, string>();
+ for (const part of seq.split(',')) {
+ const eq = part.indexOf('=');
+ if (eq <= 0) continue;
+ out.set(part.slice(0, eq).trim(), part.slice(eq + 1).trim());
+ }
+ return out;
+}
+
+/**
+ * Whether an update signed like `probe` would satisfy a `publisher` pin.
+ *
+ * - No pin ⇒ true. electron-updater skips verification entirely.
+ * - No probe ⇒ true. Its verifier treats a PowerShell failure as "no objection",
+ * and this must never be stricter than the check it stands in for.
+ * - Otherwise the status must be Valid AND the subject must match, the same two
+ * tests, in the same order, as windowsExecutableCodeSignatureVerifier.
+ */
+export function signatureSatisfies(publisher: string | null, probe: AuthenticodeProbe | null): boolean {
+ if (publisher === null) return true;
+ if (probe === null) return true;
+ if (probe.Status !== 0) return false;
+ const subject = parseDn(probe.SignerCertificate?.Subject ?? '');
+ const pinned = parseDn(publisher);
+ // A full DN pin compares every field it names; a bare name is a common-name pin.
+ return pinned.size > 0
+ ? [...pinned.keys()].every((k) => pinned.get(k) === subject.get(k))
+ : subject.get('CN') === publisher;
+}
diff --git a/desktop/tests/update-signature.test.ts b/desktop/tests/update-signature.test.ts
new file mode 100644
index 000000000..982f57112
--- /dev/null
+++ b/desktop/tests/update-signature.test.ts
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file Whether a Windows update can install here, decided BEFORE the download.
+ *
+ * The case that forced this: a release signed the Windows installer with the
+ * project's macOS Developer ID certificate, so those installs pin a publisher
+ * Windows can never report Valid ("a certificate chain could not be built to a
+ * trusted root authority"). electron-updater refuses such an update only after
+ * downloading it in full, and every one of those installs is refused forever.
+ */
+import { describe, it, expect } from 'vitest';
+import { publisherNameIn, signatureSatisfies } from '../electron/updateSignature';
+
+const APPLE_DN =
+ 'C=CN, O=huahui yu, OU=2S2W4BZFKM, CN=Developer ID Application: huahui yu (2S2W4BZFKM), OID.0.9.2342.19200300.100.1.1=2S2W4BZFKM';
+
+// Verbatim from the 0.35.0 Windows install that could not update: electron-builder
+// writes the pin as a LIST, from the certificate the Windows CI leg was handed.
+const SHIPPED_YML = [
+ 'owner: esengine',
+ 'repo: estella',
+ 'provider: github',
+ 'releaseType: draft',
+ "updaterCacheDirName: '@estellaeditor-updater'",
+ 'publisherName:',
+ " - 'Developer ID Application: huahui yu (2S2W4BZFKM)'",
+ '',
+].join('\n');
+
+describe('publisherNameIn', () => {
+ it('reads the pin electron-builder wrote into the build that could not update', () => {
+ expect(publisherNameIn(SHIPPED_YML)).toBe('Developer ID Application: huahui yu (2S2W4BZFKM)');
+ });
+
+ it('reads a scalar pin too (electron-builder writes either shape)', () => {
+ expect(publisherNameIn('provider: github\npublisherName: Acme Inc\n')).toBe('Acme Inc');
+ });
+
+ it('is null for an unsigned build — nothing pinned, nothing to verify', () => {
+ expect(publisherNameIn('provider: github\nowner: esengine\nrepo: estella\n')).toBeNull();
+ });
+
+ it('reads a quoted scalar and a list pin', () => {
+ expect(publisherNameIn("publisherName: 'Acme, Inc.'\n")).toBe('Acme, Inc.');
+ expect(publisherNameIn('publisherName:\n - Acme Inc\n - Acme Ltd\n')).toBe('Acme Inc');
+ });
+});
+
+describe('signatureSatisfies', () => {
+ it('passes when nothing is pinned (the updater skips verification entirely)', () => {
+ expect(signatureSatisfies(null, { Status: 2 })).toBe(true);
+ expect(signatureSatisfies(null, null)).toBe(true);
+ });
+
+ it('passes when Windows could not be asked — never stricter than the check it stands in for', () => {
+ expect(signatureSatisfies('Acme Inc', null)).toBe(true);
+ });
+
+ // Measured on the 0.35.0 install: the pinned name matches the signer exactly, and
+ // Windows still refuses to vouch for the chain — which is the whole failure. A
+ // check that compared only names would have called this install updatable.
+ it('REFUSES an untrusted chain even though the name matches — the shipped bug', () => {
+ expect(signatureSatisfies(publisherNameIn(SHIPPED_YML), {
+ Status: 1,
+ StatusMessage: 'A certificate chain could not be built to a trusted root authority',
+ SignerCertificate: { Subject: APPLE_DN },
+ })).toBe(false);
+ });
+
+ it('refuses an unsigned executable against a pin', () => {
+ expect(signatureSatisfies('Acme Inc', { Status: 2, SignerCertificate: null })).toBe(false);
+ });
+
+ it('passes a valid signature whose common name matches the pin', () => {
+ expect(signatureSatisfies('Acme Inc', {
+ Status: 0,
+ SignerCertificate: { Subject: 'C=US, O=Acme Inc, CN=Acme Inc' },
+ })).toBe(true);
+ });
+
+ it('refuses a valid signature by someone else', () => {
+ expect(signatureSatisfies('Acme Inc', {
+ Status: 0,
+ SignerCertificate: { Subject: 'C=US, O=Other, CN=Other Corp' },
+ })).toBe(false);
+ });
+
+ it('compares every field a full-DN pin names', () => {
+ const probe = { Status: 0, SignerCertificate: { Subject: 'C=US, O=Acme Inc, CN=Acme Inc' } };
+ expect(signatureSatisfies('CN=Acme Inc, O=Acme Inc', probe)).toBe(true);
+ expect(signatureSatisfies('CN=Acme Inc, O=Other', probe)).toBe(false);
+ });
+});