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
@@ -12,6 +12,12 @@
|
||||
export const APP_ERROR_CODES = [
|
||||
/** A bug of ours: a handler returned something its contract does not allow. */
|
||||
'internal_error',
|
||||
'app_update_unavailable',
|
||||
'app_update_busy',
|
||||
'app_update_launcher_busy',
|
||||
'app_update_download_failed',
|
||||
'app_update_installer_invalid',
|
||||
'app_update_install_failed',
|
||||
/** The launcher's own settings file could not be written. */
|
||||
'settings_write_failed',
|
||||
'logs_folder_open_failed',
|
||||
|
||||
@@ -24,6 +24,8 @@ export const IPC_CHANNEL_PREFIXES = [
|
||||
'settings:',
|
||||
/** Adaptation packs: the active patch set, update checks, installing a newer pack. */
|
||||
'patches:',
|
||||
/** Checking, downloading and installing a launcher release. */
|
||||
'updates:',
|
||||
/** The launcher window itself (it draws its own title bar). */
|
||||
'window:',
|
||||
] as const;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { AppReleaseVersionSchema, AppUpdateCheckSchema, AppUpdateProgressSchema } from '../schemas/app-update.ts';
|
||||
import { BackgroundPictureSchema } from '../schemas/background.ts';
|
||||
import {
|
||||
CopiesSchema,
|
||||
@@ -34,6 +35,7 @@ export const ipcContract = {
|
||||
version: z.string(),
|
||||
electron: z.string(),
|
||||
development: z.boolean(),
|
||||
appUpdatesSupported: z.boolean(),
|
||||
/** The operating system's preferred language, as Electron reports it (e.g. "zh-CN"). */
|
||||
systemLocale: z.string(),
|
||||
userDataPath: z.string(),
|
||||
@@ -270,6 +272,18 @@ export const ipcContract = {
|
||||
input: z.void(),
|
||||
output: ActivePatchSetSchema,
|
||||
},
|
||||
'updates:check': {
|
||||
input: z.void(),
|
||||
output: AppUpdateCheckSchema,
|
||||
},
|
||||
'updates:download': {
|
||||
input: z.object({ version: AppReleaseVersionSchema }),
|
||||
output: AppUpdateCheckSchema,
|
||||
},
|
||||
'updates:install': {
|
||||
input: z.object({ version: AppReleaseVersionSchema }),
|
||||
output: z.void(),
|
||||
},
|
||||
'window:minimize': {
|
||||
input: z.void(),
|
||||
output: z.void(),
|
||||
@@ -283,6 +297,7 @@ export const ipcContract = {
|
||||
export const ipcEvents = {
|
||||
'event:settings-changed': SettingsSchema,
|
||||
'event:install-progress': InstallProgressSchema,
|
||||
'event:app-update-progress': AppUpdateProgressSchema,
|
||||
'event:launch-state': LaunchStateSchema,
|
||||
'event:copies-changed': CopiesSchema,
|
||||
'event:copy-maintenance': MaintenanceProgressSchema,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const STABLE_VERSION = /^(0|[1-9][0-9]{0,4})\.(0|[1-9][0-9]{0,4})\.(0|[1-9][0-9]{0,4})$/;
|
||||
export const AppReleaseVersionSchema = z.string().regex(STABLE_VERSION);
|
||||
export const MAX_INSTALLER_BYTES = 2 ** 31 - 1;
|
||||
|
||||
export function launcherReleaseFiles(version: string) {
|
||||
const base = `wtoffline-launcher-${AppReleaseVersionSchema.parse(version)}-win-x64`;
|
||||
return { installer: `${base}.exe`, manifest: `${base}.manifest.json`, signature: `${base}.manifest.json.sig` };
|
||||
}
|
||||
|
||||
export const LauncherReleaseManifest = z.strictObject({
|
||||
kind: z.literal('wto-launcher-release'),
|
||||
format: z.literal(1),
|
||||
version: AppReleaseVersionSchema,
|
||||
platform: z.literal('win32-x64'),
|
||||
size: z.number().int().positive().max(MAX_INSTALLER_BYTES),
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
||||
});
|
||||
export type LauncherReleaseManifest = z.output<typeof LauncherReleaseManifest>;
|
||||
|
||||
const AppUpdateReleaseSchema = z.object({
|
||||
version: AppReleaseVersionSchema,
|
||||
size: z.number().int().positive().max(MAX_INSTALLER_BYTES),
|
||||
notes: z.string(),
|
||||
});
|
||||
const AppUpdateProblemSchema = z.enum(['network', 'contents', 'signature', 'no_signing_key']);
|
||||
|
||||
export const AppUpdateCheckSchema = z.discriminatedUnion('status', [
|
||||
z.object({ status: z.literal('current') }),
|
||||
z.object({ status: z.literal('available'), release: AppUpdateReleaseSchema, ready: z.boolean() }),
|
||||
z.object({ status: z.literal('failed'), problem: AppUpdateProblemSchema }),
|
||||
]);
|
||||
export type AppUpdateCheck = z.output<typeof AppUpdateCheckSchema>;
|
||||
|
||||
export const AppUpdateProgressSchema = z.object({
|
||||
received: z.number().int().nonnegative(),
|
||||
total: z.number().int().positive(),
|
||||
});
|
||||
export type AppUpdateProgress = z.output<typeof AppUpdateProgressSchema>;
|
||||
@@ -21,6 +21,7 @@ export const SettingsSchema = z.object({
|
||||
officialWallpapers: z.boolean().default(true),
|
||||
/** Ask GitHub for a newer adaptation pack when the launcher starts. */
|
||||
checkPatchPacksOnStart: z.boolean().default(true),
|
||||
checkLauncherUpdatesOnStart: z.boolean().default(true),
|
||||
windowClose: WindowCloseSchema.default('quit'),
|
||||
afterGameStarts: AfterGameStartsSchema.default('minimize'),
|
||||
autoSaveBackups: z.boolean().default(true),
|
||||
@@ -41,6 +42,7 @@ export const SettingsPatchSchema = z.object({
|
||||
background: BackgroundChoiceSchema.optional(),
|
||||
officialWallpapers: z.boolean().optional(),
|
||||
checkPatchPacksOnStart: z.boolean().optional(),
|
||||
checkLauncherUpdatesOnStart: z.boolean().optional(),
|
||||
windowClose: WindowCloseSchema.optional(),
|
||||
afterGameStarts: AfterGameStartsSchema.optional(),
|
||||
autoSaveBackups: z.boolean().optional(),
|
||||
|
||||
Reference in new issue
Block a user