feat(updates): verify and install launcher releases
Check the versioned release channel, verify the signed manifest and installer digest, and open the installer only after confirmation. Verified type checks, the Windows package, and an upgrade handoff from a local release fixture, including tampering and interrupted downloads.
This commit is contained in:
1 parent
31b38518f8
commit
746b74c564
24 files changed
+638
-28
No files matched your search
@@ -2,6 +2,7 @@ import { cp, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/p
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname, join, relative, resolve, sep } from 'node:path';
|
||||
import { Arch, build, Platform } from 'electron-builder';
|
||||
import { launcherReleaseFiles } from '../apps/launcher/src/shared/schemas/app-update.ts';
|
||||
|
||||
const repository = resolve(import.meta.dirname, '..');
|
||||
const launcher = join(repository, 'apps', 'launcher');
|
||||
@@ -46,9 +47,10 @@ async function stageWorkspacePackage(folder: string, resources: string, runtimeM
|
||||
await writeFile(join(bridge, 'index.js'), 'export * from ' + JSON.stringify(entry) + ';\n');
|
||||
}
|
||||
|
||||
async function stageInstaller(stage: string): Promise<void> {
|
||||
async function stageInstaller(stage: string): Promise<string> {
|
||||
const manifest = JSON.parse(await readFile(join(launcher, 'package.json'), 'utf8')) as LauncherManifest;
|
||||
const { productName, version, description, main, type } = manifest;
|
||||
const artifactName = launcherReleaseFiles(version).installer;
|
||||
await writeFile(join(stage, 'package.json'), JSON.stringify({
|
||||
name: 'wtoffline-launcher', productName, version, description, main, type, license: 'AGPL-3.0-or-later',
|
||||
}));
|
||||
@@ -66,6 +68,7 @@ async function stageInstaller(stage: string): Promise<void> {
|
||||
for (const name of ['fflate', 'zod']) {
|
||||
await cp(join(modules, name), join(runtimeModules, name), { recursive: true });
|
||||
}
|
||||
return artifactName;
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
@@ -75,7 +78,7 @@ async function main(): Promise<void> {
|
||||
try {
|
||||
const electron = join(modules, 'electron');
|
||||
const { version: electronVersion } = JSON.parse(await readFile(join(electron, 'package.json'), 'utf8')) as { version: string };
|
||||
await stageInstaller(stage);
|
||||
const artifactName = await stageInstaller(stage);
|
||||
const artifacts = await build({
|
||||
projectDir: stage,
|
||||
targets: Platform.WINDOWS.createTarget('nsis', Arch.x64),
|
||||
@@ -92,7 +95,10 @@ async function main(): Promise<void> {
|
||||
{ from: 'installer-resources', to: '.', filter: ['**/*'] },
|
||||
{ from: 'installer-modules', to: 'node_modules', filter: ['**/*'] },
|
||||
],
|
||||
win: { signExecutable: false },
|
||||
win: {
|
||||
artifactName,
|
||||
signExecutable: false,
|
||||
},
|
||||
nsis: { oneClick: false, perMachine: false, allowToChangeInstallationDirectory: true, runAfterFinish: false },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { readFile, writeFile } from 'node:fs/promises';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { packSigningPublicKey, signEd25519, verifyEd25519 } from '@wto/patcher';
|
||||
import { installerDigest, launcherSignaturePayload } from '../apps/launcher/src/main/services/app-update/installer-integrity.ts';
|
||||
import { launcherReleaseFiles, LauncherReleaseManifest } from '../apps/launcher/src/shared/schemas/app-update.ts';
|
||||
|
||||
const repository = resolve(import.meta.dirname, '..');
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const { version } = JSON.parse(await readFile(join(repository, 'apps', 'launcher', 'package.json'), 'utf8')) as { version: string };
|
||||
const files = launcherReleaseFiles(version);
|
||||
const installer = join(repository, 'build', 'windows-installer', files.installer);
|
||||
const privateKey = process.env['PATCH_SIGNING_KEY'];
|
||||
const publicKey = packSigningPublicKey();
|
||||
if (!privateKey || !publicKey) throw new Error('The project signing key pair is required.');
|
||||
const manifest = LauncherReleaseManifest.parse({
|
||||
kind: 'wto-launcher-release',
|
||||
format: 1,
|
||||
platform: 'win32-x64',
|
||||
version,
|
||||
...await installerDigest(installer),
|
||||
});
|
||||
const bytes = Buffer.from(JSON.stringify(manifest, null, 2) + '\n', 'utf8');
|
||||
const payload = launcherSignaturePayload(bytes);
|
||||
const signature = signEd25519(payload, privateKey);
|
||||
if (!verifyEd25519(payload, signature, publicKey)) throw new Error('The release key does not match the bundled public key.');
|
||||
|
||||
const folder = dirname(installer);
|
||||
await writeFile(join(folder, files.manifest), bytes);
|
||||
await writeFile(join(folder, files.signature), signature, 'utf8');
|
||||
for (const file of Object.values(files)) console.info(join(folder, file));
|
||||
}
|
||||
|
||||
await main();
|
||||
Reference in new issue
Block a user