feat(release): one-command desktop release with Ed25519-signed update metadata

The installer is unsigned, so latest.yml is now signed with an Ed25519 key and the
app verifies the downloaded installer against it before installing.
npm run release -- patch|minor bumps, gates, tags, builds, signs, publishes,
re-verifies the public feed and pushes; --resume continues after a failure.
The retired GitLab registry publisher is removed.
This commit is contained in:
Yun Chan 2026-10-18 07:06:55 +09:00
parent f5ae4c8c04
commit fd9c97b7cc
21 changed files with 986 additions and 144 deletions

View file

@ -7,6 +7,10 @@
// - latest 경로: /api/packages/<owner>/generic/d3ro-voice/latest/<file> (electron-updater feed)
// 2) release/update-policy.json을 latest feed에 게시 (원격 정책/킬 스위치)
// 3) Forgejo Release 생성/갱신 + 설치 자산 첨부 (admin·site 다운로드 허브)
// 4) 공개 URL 에서 서명된 latest.yml 을 다시 받아 서명·설치본 해시를 검증 (기존 앱이 받을 그대로)
//
// latest.yml 은 Ed25519 로 서명해 latest.yml.sig 를 함께 올린다 (D3RO_UPDATE_SIGNING_KEY 필수).
// 무서명 설치본이라도 앱이 이 서명으로 설치 파일을 검증한다 — apps/desktop/src/main/update-signature.ts.
//
// 배포 순서 보장: 설치파일/blockmap을 먼저 올리고 update metadata(latest.yml)를
// 마지막에 게시한다. 기존 설치본이 배포 도중 404를 받지 않는다.
@ -19,7 +23,7 @@
import { createHash } from "node:crypto";
import { createReadStream, readFileSync } from "node:fs";
import { readFile, readdir, stat } from "node:fs/promises";
import { readFile, readdir, stat, writeFile } from "node:fs/promises";
import { basename, join } from "node:path";
import process from "node:process";
import { fileURLToPath, URL } from "node:url";
@ -38,6 +42,13 @@ import {
parseRuntimeMinVersions,
} from "./lib/runtime-feed-gate.mjs";
import { assertValidUpdatePolicy } from "./lib/update-policy-schema.mjs";
import {
SIGNATURE_SUFFIX,
loadSigningKey,
publicPemOf,
signManifest,
verifyManifest,
} from "./lib/update-manifest-signature.mjs";
const { forgejoAuthorization } = credentialHelpers;
@ -81,7 +92,25 @@ assertValidUpdatePolicy(readFileSync(policyPath), "release/update-policy.json");
const releaseDirectory = process.env.FORGEJO_RELEASE_DIR?.trim()
? process.env.FORGEJO_RELEASE_DIR.trim()
: fileURLToPath(new URL(`../../apps/desktop/release/${version}/`, import.meta.url));
const ASSET_PATTERN = /(\.exe|\.dmg|\.zip|\.blockmap|^(latest|beta|alpha)(-mac|-linux)?\.yml)$/;
// 같은 폴더에 휴대용 zip/7z·__uninstaller exe 가 섞일 수 있다 — 업데이트 자산만 고른다.
const ASSET_PATTERN = /(-Setup-[^/]*\.exe(\.blockmap)?|\.dmg|-mac\.zip(\.blockmap)?|^(latest|beta|alpha)(-mac|-linux)?\.yml(\.sig)?)$/;
// latest.yml 서명 — 키가 저장소 공개키와 짝이 아니면 앱이 거부할 릴리스이므로 아무것도 올리지 않는다.
const repoPublicKeyPem = readFileSync(
fileURLToPath(new URL("../../release/desktop-update-public.pem", import.meta.url)),
"utf8",
);
if (!dryRun || process.env.D3RO_UPDATE_SIGNING_KEY) {
const signingKey = loadSigningKey();
if (publicPemOf(signingKey).trim() !== repoPublicKeyPem.trim()) {
throw new Error("D3RO_UPDATE_SIGNING_KEY 가 release/desktop-update-public.pem 과 짝이 아닙니다.");
}
for (const name of await readdir(releaseDirectory)) {
if (!/^(latest|beta|alpha)(-mac|-linux)?\.yml$/.test(name)) continue;
const manifest = await readFile(join(releaseDirectory, name));
await writeFile(join(releaseDirectory, `${name}${SIGNATURE_SUFFIX}`), signManifest(manifest, signingKey));
}
}
const files = [];
for (const name of await readdir(releaseDirectory)) {
@ -96,6 +125,9 @@ if (!files.some((file) => file.name.endsWith(".exe"))) {
if (!files.some((file) => file.name === "latest.yml")) {
throw new Error(`latest.yml is missing for ${tag} — check electron-builder.yml publish config.`);
}
if (!dryRun && !files.some((file) => file.name === `latest.yml${SIGNATURE_SUFFIX}`)) {
throw new Error(`latest.yml${SIGNATURE_SUFFIX} is missing for ${tag}.`);
}
if (!files.some((file) => file.name.endsWith(".dmg"))) {
process.stdout.write(`WARNING: macOS artifacts missing for ${tag} — Windows-only release.\n`);
}
@ -195,7 +227,10 @@ if (latestFeed.update) {
await verifyPublicFile(`${packageVersionedUrl}/latest.yml`);
}
// 4) Forgejo Release 생성/갱신 + 자산 첨부
// 4) 기존 앱이 받을 그대로 검증 — 공개(무인증) 버전별 경로의 latest.yml + 서명 + 설치본 해시
await verifySignedPublicManifest();
// 5) Forgejo Release 생성/갱신 + 자산 첨부
const description = await buildReleaseDescription();
const releaseId = await upsertRelease(description);
for (const file of sorted) {
@ -236,7 +271,7 @@ function safeAssetName(name) {
}
function isUpdateMetadata(name) {
return /(?:\.blockmap$|^(?:latest|beta|alpha)(?:-mac|-linux)?\.yml$|^update-policy\.json$)/.test(name);
return /(?:\.blockmap$|^(?:latest|beta|alpha)(?:-mac|-linux)?\.yml(?:\.sig)?$|^update-policy\.json$)/.test(name);
}
function isYamlUpdateMetadata(name) {
@ -333,6 +368,31 @@ async function verifyPublicFile(url) {
if (!body.trim()) throw new Error(`Public updater file is empty: ${url}`);
}
async function verifySignedPublicManifest() {
const url = `${packageVersionedUrl}/latest.yml`;
const [manifestResponse, signatureResponse] = await Promise.all([
fetch(url, { cache: "no-store" }),
fetch(`${url}${SIGNATURE_SUFFIX}`, { cache: "no-store" }),
]);
if (!manifestResponse.ok || !signatureResponse.ok) {
throw new Error(
`Public signed manifest unreachable: latest.yml HTTP ${manifestResponse.status}, .sig HTTP ${signatureResponse.status}`,
);
}
const manifest = await manifestResponse.text();
if (!verifyManifest(manifest, await signatureResponse.text(), repoPublicKeyPem)) {
throw new Error(`Public ${url} signature does not verify with release/desktop-update-public.pem.`);
}
const signedSha512 = manifest.match(/^sha512:\s*(\S+)\s*$/m)?.[1];
const installer = sorted.find((file) => /-Setup-.*\.exe$/.test(file.name));
const localSha512 = createHash("sha512").update(await readFile(installer.path)).digest("base64");
if (signedSha512 !== localSha512) {
throw new Error(`Signed latest.yml sha512 does not match ${installer.name}.`);
}
process.stdout.write(` verified public signed manifest ${url}
`);
}
async function buildReleaseDescription() {
const changelog = await readFile(
fileURLToPath(new URL("../../CHANGELOG.md", import.meta.url)),