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
@@ -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