release: iriz 0.2.3
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
// Anonymous, read-only verification. Downloaded content is never executed or saved.
|
||||
// Anonymous live checks stream bytes only; draft checks mount read-only and run one isolated UI export.
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFile } from 'node:child_process';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { readFile, realpath, stat } from 'node:fs/promises';
|
||||
import { dirname, resolve, sep } from 'node:path';
|
||||
import { createReadStream } from 'node:fs';
|
||||
import { lstat, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rm, stat } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { basename, dirname, join, resolve, sep } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { crc32, inflateSync } from 'node:zlib';
|
||||
|
||||
@@ -16,6 +19,20 @@ const META_LIMIT = 1024 * 1024;
|
||||
const DMG_LIMIT = 512 * 1024 * 1024;
|
||||
const HASH = /^[a-f0-9]{64}$/;
|
||||
const SHA = /^[a-f0-9]{40}$/;
|
||||
const MEETING_TEMPLATE_SHA = '8b4ffde7a7d09c6f3450b2de8667334fe79f544157553c3e81d77456b43807ff';
|
||||
const MEETING_FILES = [
|
||||
'README.md', 'data.schema.json', 'docs/filler-usage.md', 'docs/filling-rules.md',
|
||||
'docs/formatting.md', 'docs/owner-changes.md', 'docs/verification.md',
|
||||
'examples/data.example.json', 'examples/filled.example.docx', 'fields.json',
|
||||
'fonts/OFL.txt', 'fonts/PT_Serif-Web-Bold.ttf', 'fonts/PT_Serif-Web-Regular.ttf',
|
||||
'scripts/fill_template.py', 'scripts/verify_package.py', 'template.docx', 'template.md',
|
||||
'tests/test_fill_template.py',
|
||||
];
|
||||
export const UI_SHOT_NAMES = [
|
||||
'menu-normal', 'menu-alarm', 'menu-paused', 'menu-tap-dead',
|
||||
'settings', 'history-list', 'history-empty', 'history-rescue',
|
||||
].flatMap(surface => ['light', 'dark'].flatMap(theme => [1, 2]
|
||||
.map(scale => `${surface}-${theme}@${scale}x.png`)));
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const LOCALES = [['README.md', 'What This Is', 'Contents'], ['README.ru.md', 'Что это', 'Оглавление'], ['README.zh.md', '这是什么', '目录']];
|
||||
export const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
|
||||
@@ -25,6 +42,41 @@ const sameNames = (actual, expected, label) => {
|
||||
new Set(actual).size === actual.length && expected.every(name => actual.includes(name)), `${label}: wrong or duplicate filenames`);
|
||||
};
|
||||
|
||||
async function hashFile(path) {
|
||||
const hash = createHash('sha256');
|
||||
for await (const chunk of createReadStream(path)) hash.update(chunk);
|
||||
return hash.digest('hex');
|
||||
}
|
||||
|
||||
async function sameFileBytes(left, right) {
|
||||
const [a, b] = await Promise.all([open(left, 'r'), open(right, 'r')]);
|
||||
const leftBuffer = Buffer.allocUnsafe(1024 * 1024), rightBuffer = Buffer.allocUnsafe(1024 * 1024);
|
||||
try {
|
||||
while (true) {
|
||||
const [leftRead, rightRead] = await Promise.all([a.read(leftBuffer), b.read(rightBuffer)]);
|
||||
if (leftRead.bytesRead !== rightRead.bytesRead) return false;
|
||||
if (!leftBuffer.subarray(0, leftRead.bytesRead).equals(rightBuffer.subarray(0, rightRead.bytesRead))) return false;
|
||||
if (leftRead.bytesRead === 0) return true;
|
||||
}
|
||||
} finally { await Promise.all([a.close(), b.close()]); }
|
||||
}
|
||||
|
||||
async function regularFile(path, label, maxBytes = DMG_LIMIT) {
|
||||
const info = await lstat(path).catch(() => null);
|
||||
requireThat(info?.isFile() && !info.isSymbolicLink() && info.size > 0 && info.size <= maxBytes,
|
||||
`${label}: missing, symlinked, empty or oversized`);
|
||||
return info;
|
||||
}
|
||||
|
||||
function nativeCommand(command, args, { cwd, env, timeout = 120_000 } = {}) {
|
||||
return new Promise((resolvePromise, rejectPromise) => execFile(command, args, {
|
||||
cwd, env, timeout, maxBuffer: 8 * META_LIMIT, windowsHide: true,
|
||||
}, (error, stdout, stderr) => {
|
||||
if (error) return rejectPromise(new Error(`${basename(command)} failed: ${String(stderr || stdout || error.message).trim()}`));
|
||||
resolvePromise({ stdout, stderr });
|
||||
}));
|
||||
}
|
||||
|
||||
export function trustedURL(value) {
|
||||
let url;
|
||||
try { url = new URL(value); } catch { throw new Error('Invalid download URL'); }
|
||||
@@ -179,6 +231,185 @@ export function validateManifest(manifest, snapshot, downloaded) {
|
||||
}
|
||||
}
|
||||
|
||||
export function validateDownloadedManifest(manifest, { version, source, images, files }) {
|
||||
requireThat(manifest?.version === version && manifest.source_sha === source && manifest.source_dirty === false,
|
||||
'Downloaded manifest version/source is invalid');
|
||||
requireThat(manifest.notarized === false && manifest.signing?.mode === 'ad-hoc' && manifest.signing.identity === '-',
|
||||
'Downloaded manifest signing is not the required ad-hoc identity');
|
||||
sameNames(manifest.artifacts?.map(item => item.file), images, 'Downloaded manifest artifacts');
|
||||
for (const name of images) {
|
||||
const item = manifest.artifacts.find(value => value.file === name), file = files.get(name);
|
||||
requireThat(item.bytes === file.bytes && item.sha256 === file.sha256 &&
|
||||
Array.isArray(item.architectures) && item.architectures.length === 1 && item.architectures[0] === 'arm64',
|
||||
`Downloaded manifest artifact differs: ${name}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyMeetingPackage(packagePath) {
|
||||
const packageInfo = await lstat(packagePath).catch(() => null);
|
||||
requireThat(packageInfo?.isDirectory() && !packageInfo.isSymbolicLink(), 'Meeting package directory is invalid');
|
||||
const packageRoot = await realpath(packagePath);
|
||||
const manifestPath = join(packagePath, 'manifest.json');
|
||||
await regularFile(manifestPath, 'Meeting package manifest', META_LIMIT);
|
||||
const manifest = json(await readFile(manifestPath), 'Meeting package manifest');
|
||||
requireThat(manifest?.version === 1 && HASH.test(manifest.template_sha256) &&
|
||||
manifest.files && typeof manifest.files === 'object' && !Array.isArray(manifest.files),
|
||||
'Meeting package manifest is invalid');
|
||||
requireThat(manifest.files['template.docx'] === manifest.template_sha256,
|
||||
'Meeting template is not bound to its package manifest');
|
||||
requireThat(manifest.template_sha256 === MEETING_TEMPLATE_SHA,
|
||||
'Meeting template checksum differs from the shipped template');
|
||||
sameNames(Object.keys(manifest.files), MEETING_FILES, 'Meeting package files');
|
||||
for (const [relative, expected] of Object.entries(manifest.files)) {
|
||||
requireThat(/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[a-zA-Z0-9._/-]+$/.test(relative) && HASH.test(expected),
|
||||
'Meeting package manifest contains an unsafe file');
|
||||
const path = resolve(packagePath, relative);
|
||||
requireThat(path.startsWith(`${resolve(packagePath)}${sep}`) &&
|
||||
(await realpath(path)).startsWith(`${packageRoot}${sep}`), 'Meeting package file escapes its bundle');
|
||||
await regularFile(path, `Meeting package file ${relative}`, 64 * META_LIMIT);
|
||||
requireThat(await hashFile(path) === expected, `Meeting package checksum differs: ${relative}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function verifyDownloadedNative({ images, version, environment, run = nativeCommand }) {
|
||||
const tempBase = await realpath(environment.TMPDIR || tmpdir());
|
||||
const scratch = await mkdtemp(join(tempBase, 'iriz-release-verify-'));
|
||||
const mount = join(scratch, 'mount'), copiedApp = join(scratch, 'iriz.app'), home = join(scratch, 'home');
|
||||
const launchTemp = join(scratch, 'tmp'), shots = join(scratch, 'shots');
|
||||
await Promise.all([mkdir(mount), mkdir(home, { mode: 0o700 }), mkdir(launchTemp, { mode: 0o700 }), mkdir(shots)]);
|
||||
const cleanEnvironment = {
|
||||
HOME: home, CFFIXED_USER_HOME: home, TMPDIR: launchTemp,
|
||||
PATH: '/usr/bin:/bin:/usr/sbin:/sbin', LANG: 'en_US.UTF-8', LC_ALL: 'en_US.UTF-8',
|
||||
};
|
||||
let mounted = false, failure;
|
||||
try {
|
||||
for (const image of images)
|
||||
await run('/usr/bin/hdiutil', ['verify', image], { env: cleanEnvironment, timeout: 120_000 });
|
||||
await run('/usr/bin/hdiutil', ['attach', '-readonly', '-nobrowse', '-noautoopen', '-mountpoint', mount, images[0]],
|
||||
{ env: cleanEnvironment, timeout: 120_000 });
|
||||
mounted = true;
|
||||
const app = join(mount, 'iriz.app'), executable = join(app, 'Contents', 'MacOS', 'iriz');
|
||||
const appInfo = await lstat(app).catch(() => null);
|
||||
requireThat(appInfo?.isDirectory() && !appInfo.isSymbolicLink(), 'Mounted DMG has no regular iriz.app bundle');
|
||||
const appRoot = await realpath(app);
|
||||
requireThat(appRoot.startsWith(`${await realpath(mount)}${sep}`) &&
|
||||
(await realpath(executable)).startsWith(`${appRoot}${sep}`), 'Mounted app paths escape the DMG');
|
||||
const executableInfo = await regularFile(executable, 'Mounted app executable');
|
||||
requireThat((executableInfo.mode & 0o111) !== 0, 'Mounted app executable is not executable');
|
||||
const applications = join(mount, 'Applications'), applicationsInfo = await lstat(applications).catch(() => null);
|
||||
requireThat(applicationsInfo?.isSymbolicLink() && await readlink(applications) === '/Applications',
|
||||
'Mounted DMG Applications link is invalid');
|
||||
const resources = join(app, 'Contents', 'Resources');
|
||||
for (const bundle of ['IrizApp_IrizCore.bundle', 'IrizApp_IrizDictate.bundle']) {
|
||||
const info = await lstat(join(resources, bundle)).catch(() => null);
|
||||
requireThat(info?.isDirectory() && !info.isSymbolicLink(), `Mounted app resource bundle missing: ${bundle}`);
|
||||
}
|
||||
await verifyMeetingPackage(join(resources, 'IrizApp_IrizDictate.bundle', 'MeetingMinutes'));
|
||||
await regularFile(join(app, 'Contents', 'Info.plist'), 'Mounted app Info.plist', META_LIMIT);
|
||||
const plistVersion = await run('/usr/bin/plutil', ['-extract', 'CFBundleShortVersionString', 'raw',
|
||||
'-o', '-', join(app, 'Contents', 'Info.plist')], { env: cleanEnvironment });
|
||||
requireThat(String(plistVersion.stdout).trim() === version, 'Mounted app bundle version differs');
|
||||
const minimumOS = await run('/usr/bin/plutil', ['-extract', 'LSMinimumSystemVersion', 'raw',
|
||||
'-o', '-', join(app, 'Contents', 'Info.plist')], { env: cleanEnvironment });
|
||||
requireThat(String(minimumOS.stdout).trim() === '14.0', 'Mounted app minimum macOS version differs');
|
||||
const architecture = await run('/usr/bin/lipo', ['-archs', executable], { env: cleanEnvironment });
|
||||
requireThat(String(architecture.stdout).trim() === 'arm64', 'Mounted app executable is not exact arm64');
|
||||
await run('/usr/bin/codesign', ['--verify', '--deep', '--strict', '--verbose=2', app], { env: cleanEnvironment });
|
||||
const signature = await run('/usr/bin/codesign', ['-dv', '--verbose=4', app], { env: cleanEnvironment });
|
||||
requireThat(/(?:^|\n)Signature=adhoc(?:\n|$)/.test(`${signature.stdout}\n${signature.stderr}`),
|
||||
'Mounted app signature is not ad-hoc');
|
||||
await run('/usr/bin/ditto', [app, copiedApp], { env: cleanEnvironment, timeout: 120_000 });
|
||||
const copiedInfo = await lstat(copiedApp).catch(() => null);
|
||||
requireThat(copiedInfo?.isDirectory() && !copiedInfo.isSymbolicLink() &&
|
||||
(await realpath(copiedApp)).startsWith(`${await realpath(scratch)}${sep}`),
|
||||
'Copied app bundle is invalid');
|
||||
await run('/usr/bin/codesign', ['--verify', '--deep', '--strict', '--verbose=2', copiedApp],
|
||||
{ env: cleanEnvironment });
|
||||
await run('/usr/bin/hdiutil', ['detach', mount], { env: cleanEnvironment, timeout: 30_000 });
|
||||
mounted = false;
|
||||
const copiedExecutable = join(copiedApp, 'Contents', 'MacOS', 'iriz');
|
||||
await run(copiedExecutable, ['--export-ui-shots', shots],
|
||||
{ cwd: home, env: cleanEnvironment, timeout: 120_000 });
|
||||
const shotEntries = await readdir(shots, { withFileTypes: true });
|
||||
const shotFiles = shotEntries.filter(entry => entry.isFile()).map(entry => entry.name);
|
||||
sameNames(shotFiles, UI_SHOT_NAMES, 'Copied app UI shots');
|
||||
for (const name of UI_SHOT_NAMES) {
|
||||
await regularFile(join(shots, name), `UI shot ${name}`, 32 * META_LIMIT);
|
||||
const handle = await open(join(shots, name), 'r');
|
||||
const signature = Buffer.alloc(8);
|
||||
try { requireThat((await handle.read(signature)).bytesRead === 8 &&
|
||||
signature.equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])), `UI shot is not PNG: ${name}`); }
|
||||
finally { await handle.close(); }
|
||||
}
|
||||
} catch (error) { failure = error; }
|
||||
finally {
|
||||
if (mounted) {
|
||||
try {
|
||||
await run('/usr/bin/hdiutil', ['detach', mount], { env: cleanEnvironment, timeout: 30_000 });
|
||||
mounted = false;
|
||||
}
|
||||
catch (error) { if (!failure) failure = error; }
|
||||
}
|
||||
if (!mounted) {
|
||||
try { await rm(scratch, { recursive: true, force: true }); }
|
||||
catch (error) { if (!failure) failure = error; }
|
||||
}
|
||||
}
|
||||
if (failure) throw failure;
|
||||
}
|
||||
|
||||
export async function verifyDownloadedRelease({
|
||||
environment = process.env, nativeProbe = verifyDownloadedNative,
|
||||
} = {}) {
|
||||
const assetInput = environment.PRODUCT_RELEASE_ASSET_DIR;
|
||||
const version = environment.PRODUCT_RELEASE_VERSION;
|
||||
const tag = environment.PRODUCT_RELEASE_TAG;
|
||||
const source = environment.PRODUCT_RELEASE_SOURCE_SHA;
|
||||
const token = environment.PRODUCT_RELEASE_VERIFY_TOKEN;
|
||||
requireThat(typeof assetInput === 'string' && assetInput.length > 0, 'PRODUCT_RELEASE_ASSET_DIR is required');
|
||||
requireThat(/^\d+\.\d+\.\d+$/.test(version || '') && tag === `v${version}`,
|
||||
'Downloaded release version/tag is invalid');
|
||||
requireThat(SHA.test(source || ''), 'Downloaded release source SHA is invalid');
|
||||
requireThat(typeof token === 'string' && /^[a-zA-Z0-9._-]{16,256}$/.test(token),
|
||||
'Downloaded release verify token is invalid');
|
||||
requireThat(['draft', 'published-assets'].includes(environment.PRODUCT_RELEASE_STAGE),
|
||||
'Downloaded release stage is invalid');
|
||||
requireThat(resolve(assetInput) === assetInput, 'Downloaded release asset path must be absolute');
|
||||
const inputInfo = await lstat(assetInput).catch(() => null);
|
||||
requireThat(inputInfo?.isDirectory() && !inputInfo.isSymbolicLink(),
|
||||
'Downloaded release asset path is not a regular directory');
|
||||
const assetDir = await realpath(assetInput);
|
||||
const rootInfo = await lstat(assetDir);
|
||||
requireThat(rootInfo.isDirectory() && !rootInfo.isSymbolicLink(), 'Downloaded release asset path is not a directory');
|
||||
const images = [`iriz-${version}-arm64.dmg`, 'iriz-macos-arm64.dmg'];
|
||||
const expected = [...images, 'release-manifest.json', 'SHA256SUMS.txt'];
|
||||
const entries = await readdir(assetDir, { withFileTypes: true });
|
||||
const rootFiles = entries.filter(entry => entry.isFile()).map(entry => entry.name);
|
||||
sameNames(rootFiles, expected, 'Downloaded release root files');
|
||||
for (const entry of entries) {
|
||||
requireThat(expected.includes(entry.name) ||
|
||||
(entry.isDirectory() && ['verifier-home', 'verifier-tmp'].includes(entry.name)),
|
||||
`Downloaded release has unexpected root entry: ${entry.name}`);
|
||||
}
|
||||
const files = new Map();
|
||||
for (const name of expected) {
|
||||
const path = join(assetDir, name);
|
||||
const info = await regularFile(path, `Downloaded release file ${name}`,
|
||||
name.endsWith('.dmg') ? DMG_LIMIT : META_LIMIT);
|
||||
files.set(name, { path, bytes: info.size, sha256: await hashFile(path) });
|
||||
}
|
||||
requireThat(await sameFileBytes(files.get(images[0]).path, files.get(images[1]).path),
|
||||
'Downloaded stable and versioned DMGs differ byte-for-byte');
|
||||
const expectedSums = expected.filter(name => name !== 'SHA256SUMS.txt');
|
||||
const sums = checksums(await readFile(files.get('SHA256SUMS.txt').path), expectedSums);
|
||||
for (const [name, digest] of sums)
|
||||
requireThat(files.get(name).sha256 === digest, `Downloaded SHA256SUMS mismatch: ${name}`);
|
||||
const manifest = json(await readFile(files.get('release-manifest.json').path), 'Downloaded manifest');
|
||||
validateDownloadedManifest(manifest, { version, source, images, files });
|
||||
await nativeProbe({ images: images.map(name => files.get(name).path), version, environment });
|
||||
return `PRODUCT_RELEASE_VERIFIED=${token}`;
|
||||
}
|
||||
|
||||
export async function verifyRelease(options = {}) {
|
||||
const deadline = Date.now() + 600_000;
|
||||
const get = (url, extra = {}) => request(url, { ...options, deadline, ...extra });
|
||||
@@ -319,6 +550,11 @@ async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
assert(args.length <= 1 && (!args.length || ['--selftest', '--local'].includes(args[0])), 'Usage: node scripts/check_app_download.mjs [--selftest|--local]');
|
||||
if (args[0] === '--selftest') return (await import('./check_app_download_test.mjs')).selftest();
|
||||
if (process.env.PRODUCT_RELEASE_ASSET_DIR) {
|
||||
assert(args.length === 0, 'Downloaded release verification takes no arguments');
|
||||
console.log(await verifyDownloadedRelease());
|
||||
return;
|
||||
}
|
||||
const readmes = await verifyReadmes();
|
||||
console.log(`PASS: application download CTA in ${readmes.join(', ')}`);
|
||||
if (args[0] === '--local') return;
|
||||
|
||||
@@ -1,8 +1,92 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { chmod, cp, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { crc32, deflateSync } from 'node:zlib';
|
||||
import { API, DOWNLOAD, STABLE, sha256, trustedURL, request, releaseSnapshot,
|
||||
checksums, validateManifest, validateReadme, validateBadgePNG, verifyRelease } from './check_app_download.mjs';
|
||||
checksums, validateManifest, validateReadme, validateBadgePNG, verifyRelease,
|
||||
verifyDownloadedNative, verifyDownloadedRelease, UI_SHOT_NAMES } from './check_app_download.mjs';
|
||||
|
||||
const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
|
||||
async function downloadedFixture(work) {
|
||||
const root = await mkdtemp(join(tmpdir(), 'iriz-downloaded-release-test-'));
|
||||
const version = '9.8.7', source = 'a'.repeat(40), token = 'receipt-token-123456';
|
||||
const images = [`iriz-${version}-arm64.dmg`, 'iriz-macos-arm64.dmg'];
|
||||
const dmg = Buffer.from('synthetic identical dmg bytes');
|
||||
const manifest = {
|
||||
version, source_sha: source, source_dirty: false, notarized: false,
|
||||
signing: { mode: 'ad-hoc', identity: '-' },
|
||||
artifacts: images.map(file => ({
|
||||
file, bytes: dmg.length, sha256: sha256(dmg), architectures: ['arm64'],
|
||||
})),
|
||||
};
|
||||
const files = new Map(images.map(name => [name, dmg]));
|
||||
files.set('release-manifest.json', Buffer.from(JSON.stringify(manifest)));
|
||||
files.set('SHA256SUMS.txt', Buffer.from([...files]
|
||||
.map(([name, bytes]) => `${sha256(bytes)} ${name}\n`).join('')));
|
||||
for (const [name, bytes] of files) await writeFile(join(root, name), bytes);
|
||||
const writeChecksums = async () => {
|
||||
const bytes = Buffer.from([...files].filter(([name]) => name !== 'SHA256SUMS.txt')
|
||||
.map(([name, value]) => `${sha256(value)} ${name}\n`).join(''));
|
||||
files.set('SHA256SUMS.txt', bytes);
|
||||
await writeFile(join(root, 'SHA256SUMS.txt'), bytes);
|
||||
};
|
||||
const writeManifest = async value => {
|
||||
const bytes = Buffer.from(JSON.stringify(value));
|
||||
files.set('release-manifest.json', bytes);
|
||||
await writeFile(join(root, 'release-manifest.json'), bytes);
|
||||
await writeChecksums();
|
||||
};
|
||||
const environment = {
|
||||
PRODUCT_RELEASE_ASSET_DIR: root,
|
||||
PRODUCT_RELEASE_VERSION: version,
|
||||
PRODUCT_RELEASE_TAG: `v${version}`,
|
||||
PRODUCT_RELEASE_SOURCE_SHA: source,
|
||||
PRODUCT_RELEASE_VERIFY_TOKEN: token,
|
||||
PRODUCT_RELEASE_STAGE: 'draft',
|
||||
};
|
||||
try { return await work({ root, environment, manifest, files, images, token, writeChecksums, writeManifest }); }
|
||||
finally { await rm(root, { recursive: true, force: true }); }
|
||||
}
|
||||
|
||||
function nativeFixtureRunner({ failCodesign = false, minimumOS = '14.0', shotNames = UI_SHOT_NAMES } = {}) {
|
||||
const calls = [];
|
||||
const run = async (command, args, options = {}) => {
|
||||
calls.push([command, ...args]);
|
||||
assert.equal(options.env.GH_TOKEN, undefined);
|
||||
assert.equal(options.env.HOME, options.env.CFFIXED_USER_HOME);
|
||||
if (command === '/usr/bin/hdiutil' && args[0] === 'attach') {
|
||||
const mount = args[args.indexOf('-mountpoint') + 1];
|
||||
const resources = join(mount, 'iriz.app', 'Contents', 'Resources');
|
||||
const meeting = join(resources, 'IrizApp_IrizDictate.bundle', 'MeetingMinutes');
|
||||
const executable = join(mount, 'iriz.app', 'Contents', 'MacOS', 'iriz');
|
||||
await mkdir(join(resources, 'IrizApp_IrizCore.bundle'), { recursive: true });
|
||||
await mkdir(join(executable, '..'), { recursive: true });
|
||||
await writeFile(executable, 'synthetic executable');
|
||||
await writeFile(join(mount, 'iriz.app', 'Contents', 'Info.plist'), 'synthetic plist');
|
||||
await chmod(executable, 0o755);
|
||||
await symlink('/Applications', join(mount, 'Applications'));
|
||||
await cp(new URL('../Sources/IrizDictate/Resources/MeetingMinutes', import.meta.url), meeting,
|
||||
{ recursive: true });
|
||||
}
|
||||
if (command === '/usr/bin/plutil') return {
|
||||
stdout: `${args.includes('LSMinimumSystemVersion') ? minimumOS : '9.8.7'}\n`, stderr: '',
|
||||
};
|
||||
if (command === '/usr/bin/lipo') return { stdout: 'arm64\n', stderr: '' };
|
||||
if (command === '/usr/bin/codesign' && args[0] === '-dv') {
|
||||
if (failCodesign) throw new Error('synthetic codesign failure');
|
||||
return { stdout: '', stderr: 'Signature=adhoc\nTeamIdentifier=not set\n' };
|
||||
}
|
||||
if (command === '/usr/bin/ditto') await cp(args[0], args[1], { recursive: true });
|
||||
if (args[0] === '--export-ui-shots') {
|
||||
assert.equal(options.cwd, options.env.HOME);
|
||||
for (const name of shotNames) await writeFile(join(args[1], name), PNG_SIGNATURE);
|
||||
}
|
||||
return { stdout: '', stderr: '' };
|
||||
};
|
||||
return { calls, run };
|
||||
}
|
||||
|
||||
function fixture() {
|
||||
const version = '9.8.7';
|
||||
@@ -170,6 +254,76 @@ export async function selftest() {
|
||||
assert.throws(() => validateManifest({ ...data.manifest, version: '0.0.0' }, snapshot, new Map()), /version\/source/);
|
||||
assert.throws(() => validateManifest({ ...data.manifest, source_dirty: true }, snapshot, new Map()), /version\/source/);
|
||||
});
|
||||
await test('downloaded release emits receipt only after native verification', () => downloadedFixture(async data => {
|
||||
let probed = false;
|
||||
const receipt = await verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: async () => { probed = true; } });
|
||||
assert.equal(probed, true);
|
||||
assert.equal(receipt, `PRODUCT_RELEASE_VERIFIED=${data.token}`);
|
||||
}));
|
||||
await test('downloaded release refuses invalid receipt token', () => downloadedFixture(async data => {
|
||||
data.environment.PRODUCT_RELEASE_VERIFY_TOKEN = '';
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: async () => assert.fail('native probe must not run') }), /verify token/);
|
||||
}));
|
||||
await test('downloaded release refuses invalid stage', () => downloadedFixture(async data => {
|
||||
data.environment.PRODUCT_RELEASE_STAGE = 'published';
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: async () => assert.fail('native probe must not run') }), /stage/);
|
||||
}));
|
||||
await test('downloaded release refuses manifest contract drift', () => downloadedFixture(async data => {
|
||||
await data.writeManifest({ ...data.manifest, source_dirty: true });
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: async () => assert.fail('native probe must not run') }), /manifest version\/source/);
|
||||
await data.writeManifest({ ...data.manifest, signing: { mode: 'self-signed', identity: 'local' } });
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: async () => assert.fail('native probe must not run') }), /required ad-hoc/);
|
||||
}));
|
||||
await test('downloaded release refuses checksum mismatch', () => downloadedFixture(async data => {
|
||||
const bad = Buffer.from(data.files.get('SHA256SUMS.txt').toString().replace(/^[a-f0-9]{64}/, '0'.repeat(64)));
|
||||
await writeFile(join(data.root, 'SHA256SUMS.txt'), bad);
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: async () => assert.fail('native probe must not run') }), /SHA256SUMS mismatch/);
|
||||
}));
|
||||
await test('downloaded release propagates native probe failure without receipt', () => downloadedFixture(async data => {
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: async () => { throw new Error('synthetic hdiutil failure'); } }), /synthetic hdiutil failure/);
|
||||
}));
|
||||
await test('downloaded native probe uses readonly mount and clean launch smoke', () => downloadedFixture(async data => {
|
||||
const native = nativeFixtureRunner();
|
||||
const receipt = await verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: input => verifyDownloadedNative({ ...input, run: native.run }) });
|
||||
assert.equal(receipt, `PRODUCT_RELEASE_VERIFIED=${data.token}`);
|
||||
assert.equal(native.calls.filter(call => call[0] === '/usr/bin/hdiutil' && call[1] === 'verify').length, 2);
|
||||
assert(native.calls.some(call => call[0] === '/usr/bin/hdiutil' && call[1] === 'attach' &&
|
||||
call.includes('-readonly') && call.includes('-nobrowse') && call.includes('-noautoopen')));
|
||||
assert(native.calls.some(call => call[0] === '/usr/bin/lipo' && call[1] === '-archs'));
|
||||
assert.equal(native.calls.filter(call => call[0] === '/usr/bin/codesign' && call[1] === '--verify').length, 2);
|
||||
assert(native.calls.some(call => call[0] === '/usr/bin/ditto'));
|
||||
const detach = native.calls.findIndex(call => call[0] === '/usr/bin/hdiutil' && call[1] === 'detach');
|
||||
const launch = native.calls.findIndex(call => call[1] === '--export-ui-shots');
|
||||
assert(detach >= 0 && launch > detach && native.calls[launch][0].includes('/iriz.app/Contents/MacOS/iriz'));
|
||||
}));
|
||||
await test('downloaded native probe requires macOS 14', () => downloadedFixture(async data => {
|
||||
const native = nativeFixtureRunner({ minimumOS: '13.0' });
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: input => verifyDownloadedNative({ ...input, run: native.run }) }), /minimum macOS/);
|
||||
assert.equal(native.calls.at(-1)[0], '/usr/bin/hdiutil');
|
||||
assert.equal(native.calls.at(-1)[1], 'detach');
|
||||
}));
|
||||
await test('downloaded native probe requires every expected UI shot', () => downloadedFixture(async data => {
|
||||
const native = nativeFixtureRunner({ shotNames: UI_SHOT_NAMES.slice(1) });
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: input => verifyDownloadedNative({ ...input, run: native.run }) }), /UI shots/);
|
||||
}));
|
||||
await test('downloaded native probe detaches after mounted check failure', () => downloadedFixture(async data => {
|
||||
const native = nativeFixtureRunner({ failCodesign: true });
|
||||
await assert.rejects(() => verifyDownloadedRelease({ environment: data.environment,
|
||||
nativeProbe: input => verifyDownloadedNative({ ...input, run: native.run }) }), /synthetic codesign failure/);
|
||||
assert.equal(native.calls.at(-1)[0], '/usr/bin/hdiutil');
|
||||
assert.equal(native.calls.at(-1)[1], 'detach');
|
||||
assert(!native.calls.some(call => call[1] === '--export-ui-shots'));
|
||||
}));
|
||||
const badge = 'docs/assets/download-macos.png';
|
||||
const block = `<!-- application-downloads:start -->\n<a href="${STABLE}"><img src="${badge}" alt="Download for macOS" width="180"></a>\n[Download](${STABLE})\n<!-- application-downloads:end -->`;
|
||||
const readme = `# iriz\n\n## Contents\n\n${block}\n\n## What This Is\n`;
|
||||
@@ -194,7 +348,7 @@ export async function selftest() {
|
||||
result.writeUInt32BE(crc32(result.subarray(4, result.length - 4)), result.length - 4);
|
||||
return result;
|
||||
};
|
||||
const pngHeader = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
const pngHeader = PNG_SIGNATURE;
|
||||
const ihdr = Buffer.from([0, 0, 0, 1, 0, 0, 0, 1, 8, 6, 0, 0, 0]);
|
||||
const png = Buffer.concat([pngHeader, pngChunk('IHDR', ihdr), pngChunk('IDAT', deflateSync(Buffer.alloc(5))), pngChunk('IEND', Buffer.alloc(0))]);
|
||||
await test('valid badge PNG', () => validateBadgePNG(png));
|
||||
|
||||
Reference in New Issue
Block a user