Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Harden signed macOS runtime validation
wytb3d3ce1f918d
diff --git a/bin/runtime-gate.cjs b/bin/runtime-gate.cjsindex 7e23585e..92d7ba76 100644--- a/bin/runtime-gate.cjs+++ b/bin/runtime-gate.cjs@@ -1,7 +1,7 @@#!/usr/bin/env node'use strict';-const { execFileSync } = require('node:child_process');+const { execFileSync, spawnSync } = require('node:child_process');const crypto = require('node:crypto');const fs = require('node:fs');const path = require('node:path');@@ -117,6 +117,45 @@ function sha256File(file) {return hash.digest('hex');}+function verifyDarwinCodeSignature(file, expectedTeamIdentifier) {+ const codesign = '/usr/bin/codesign';+ const verify = spawnSync(codesign, ['--verify', '--strict', file], {+ encoding: 'utf8',+ timeout: 30_000,+ });+ if (verify.error || verify.status !== 0) {+ const detail = `${verify.stderr || ''}${verify.stdout || ''}`.trim();+ throw new Error(`[native-deps-gate] signed Darwin runtime signature is invalid: ${file}`+ + `${detail ? `: ${detail}` : verify.error ? `: ${verify.error.message}` : ''}`);+ }++ const describe = spawnSync(codesign, ['-dv', '--verbose=2', file], {+ encoding: 'utf8',+ timeout: 30_000,+ });+ if (describe.error || describe.status !== 0) {+ throw new Error(`[native-deps-gate] cannot read signed Darwin runtime identity: ${file}`+ + `${describe.error ? `: ${describe.error.message}` : ''}`);+ }+ const output = `${describe.stderr || ''}\n${describe.stdout || ''}`;+ const team = /^TeamIdentifier=(.+)$/m.exec(output)?.[1]?.trim() || '';+ if (!team || team === 'not set' || team !== expectedTeamIdentifier) {+ throw new Error(`[native-deps-gate] signed Darwin runtime TeamIdentifier mismatch: expected `+ + `${expectedTeamIdentifier}, got ${team || 'missing'}: ${file}`);+ }+}++function acceptSignedDarwinRuntimeMutation(file, targetPlatform, options = {}) {+ if (targetPlatform !== 'darwin' || options.allowSignedDarwinRuntime !== true) return false;+ const expectedTeamIdentifier = String(options.expectedTeamIdentifier || '').trim();+ if (!expectedTeamIdentifier || expectedTeamIdentifier === 'not set') {+ throw new Error('[native-deps-gate] signed Darwin runtime validation requires an expected TeamIdentifier');+ }+ const verifier = options.verifySignedDarwinBinary || verifyDarwinCodeSignature;+ verifier(file, expectedTeamIdentifier);+ return true;+}+function listDirs(dir) {if (!fs.existsSync(dir)) return [];return fs.readdirSync(dir, { withFileTypes: true })@@ -312,7 +351,10 @@ function verifyFfmpegRuntimeDir(runtimeRoot, targetPlatform, targetArch, optionsrequiredFile(`${name} runtime executable`, file);const expected = marker.binaries && marker.binaries[name];const stat = fs.statSync(file);- if (!expected || expected.bytes !== stat.size || expected.sha256 !== sha256File(file)) {+ const rawHashMatches = expected+ && expected.bytes === stat.size+ && expected.sha256 === sha256File(file);+ if (!rawHashMatches && (!expected || !acceptSignedDarwinRuntimeMutation(file, targetPlatform, options))) {throw new Error(`[native-deps-gate] ${name} runtime hash/size mismatch: ${file}`);}assertExecutableArch(file, targetPlatform, targetArch, options);@@ -351,8 +393,15 @@ function verifyWhisperRuntimeDir(runtimeRoot, targetPlatform, targetArch, optionrequiredFile(`whisper runtime file ${relativePath}`, file);const actual = { bytes: fs.statSync(file).size, sha256: sha256File(file) };const recorded = marker.files && marker.files[relativePath];- if (actual.bytes !== expected.bytes || actual.sha256 !== expected.sha256- || !recorded || recorded.bytes !== actual.bytes || recorded.sha256 !== actual.sha256) {+ const markerMatchesContract = recorded+ && recorded.bytes === expected.bytes+ && recorded.sha256 === expected.sha256;+ const rawHashMatches = actual.bytes === expected.bytes && actual.sha256 === expected.sha256;+ const acceptedSignedMutation = !rawHashMatches+ && expected.executable === true+ && markerMatchesContract+ && acceptSignedDarwinRuntimeMutation(file, targetPlatform, options);+ if (!markerMatchesContract || (!rawHashMatches && !acceptedSignedMutation)) {throw new Error(`[native-deps-gate] whisper runtime hash/size mismatch: ${file}`);}if (expected.executable) {diff --git a/test/main/util/runtime-gate.test.ts b/test/main/util/runtime-gate.test.tsindex aaaa3a59..592d15d8 100644--- a/test/main/util/runtime-gate.test.ts+++ b/test/main/util/runtime-gate.test.ts@@ -6,12 +6,19 @@ import * as os from 'node:os';import * as path from 'node:path';const require = createRequire(import.meta.url);-const { verifyRuntimeRoot, verifyWindowsVcImportClosure } = require('../../../bin/runtime-gate.cjs') as {+const {+ verifyFfmpegRuntimeDir,+ verifyRuntimeRoot,+ verifyWhisperRuntimeDir,+ verifyWindowsVcImportClosure,+} = require('../../../bin/runtime-gate.cjs') as {+ verifyFfmpegRuntimeDir: (root: string, platform: string, arch: string, options?: Record<string, unknown>) => string[];verifyRuntimeRoot: (root: string, platform: string, arch: string, options?: {allowedKeys?: string[];whisperContract?: any;windowsVcContract?: any;}) => string[];+ verifyWhisperRuntimeDir: (root: string, platform: string, arch: string, options?: Record<string, unknown>) => string;verifyWindowsVcImportClosure: (root: string, arch: string) => string;};@@ -193,6 +200,29 @@ function writeFfmpegRuntime(root: string, key: string): void {}, null, 2));}+function writeDarwinFfmpegRuntime(root: string, key: string): Record<'ffmpeg' | 'ffprobe', string> {+ const dir = path.join(root, 'ffmpeg', key);+ fs.mkdirSync(dir, { recursive: true });+ const binaries = {+ ffmpeg: Buffer.from('original ffmpeg Mach-O fixture'),+ ffprobe: Buffer.from('original ffprobe Mach-O fixture'),+ };+ const files = {} as Record<'ffmpeg' | 'ffprobe', string>;+ for (const [name, bytes] of Object.entries(binaries) as Array<[keyof typeof binaries, Buffer]>) {+ files[name] = path.join(dir, name);+ fs.writeFileSync(files[name], bytes);+ }+ fs.writeFileSync(path.join(dir, 'NOTICE.txt'), 'test notice\n');+ fs.writeFileSync(path.join(dir, '.orkas-ffmpeg-ready.json'), JSON.stringify({+ schema: 1,+ platformKey: key,+ verification: 'pinned-sha256',+ capabilities: ['libass', 'ass', 'subtitles'],+ binaries: Object.fromEntries(Object.entries(binaries).map(([name, bytes]) => [name, record(bytes)])),+ }, null, 2));+ return files;+}+function record(bytes: Buffer): { bytes: number; sha256: string } {return { bytes: bytes.length, sha256: crypto.createHash('sha256').update(bytes).digest('hex') };}@@ -284,6 +314,24 @@ function writeWhisperRuntime(root: string, key: string, contract: any): void {}, null, 2));}+function darwinWhisperContract(key: string): any {+ const cli = Buffer.from('original whisper Mach-O fixture');+ const model = Buffer.from('test whisper model');+ const license = Buffer.from('test license');+ return {+ schema: 1,+ version: 'test-whisper-darwin',+ model: { name: 'test-model', relativePath: 'models/test.bin', ...record(model), testBytes: model },+ licenses: { 'LICENSE.whisper.cpp': { ...record(license), testBytes: license } },+ targets: {+ [key]: {+ source: 'test',+ files: { 'bin/whisper-cli': { ...record(cli), executable: true, testBytes: cli } },+ },+ },+ };+}+function writeAllRuntimes(root: string, key: string, contract: any, withNodeCompanions = true): void {writeRuntime(root, 'python', key);writeRuntime(root, 'uv', key);@@ -344,6 +392,68 @@ describe('runtime-gate', () => {})).toThrow(/ffmpeg runtime hash\/size mismatch/);});+ it('accepts signed Darwin FFmpeg mutations only after expected-team signature verification', () => {+ const root = path.join(tmpDir, 'runtime');+ const key = 'darwin-arm64';+ const files = writeDarwinFfmpegRuntime(root, key);+ fs.appendFileSync(files.ffmpeg, 'Developer ID signature');+ fs.appendFileSync(files.ffprobe, 'Developer ID signature');+ const verified: string[] = [];++ expect(verifyFfmpegRuntimeDir(root, 'darwin', 'arm64', {+ checkArch: false,+ allowSignedDarwinRuntime: true,+ expectedTeamIdentifier: 'TEAM123',+ verifySignedDarwinBinary(file: string, team: string) {+ expect(team).toBe('TEAM123');+ verified.push(path.basename(file));+ },+ })).toHaveLength(2);+ expect(verified.sort()).toEqual(['ffmpeg', 'ffprobe']);+ });++ it('rejects signed Darwin FFmpeg mutations when signature verification fails', () => {+ const root = path.join(tmpDir, 'runtime');+ const key = 'darwin-arm64';+ const files = writeDarwinFfmpegRuntime(root, key);+ fs.appendFileSync(files.ffmpeg, 'untrusted mutation');++ expect(() => verifyFfmpegRuntimeDir(root, 'darwin', 'arm64', {+ checkArch: false,+ allowSignedDarwinRuntime: true,+ expectedTeamIdentifier: 'TEAM123',+ verifySignedDarwinBinary() {+ throw new Error('wrong signing team');+ },+ })).toThrow(/wrong signing team/);+ });++ it('keeps non-executable Whisper assets byte-exact after Darwin signing', () => {+ const root = path.join(tmpDir, 'runtime');+ const key = 'darwin-arm64';+ const contract = darwinWhisperContract(key);+ writeWhisperRuntime(root, key, contract);+ const cli = path.join(root, 'whisper', key, 'bin', 'whisper-cli');+ fs.appendFileSync(cli, 'Developer ID signature');++ expect(verifyWhisperRuntimeDir(root, 'darwin', 'arm64', {+ checkArch: false,+ whisperContract: contract,+ allowSignedDarwinRuntime: true,+ expectedTeamIdentifier: 'TEAM123',+ verifySignedDarwinBinary: () => undefined,+ })).toBe(cli);++ fs.appendFileSync(path.join(root, 'whisper', key, 'models', 'test.bin'), 'tampered');+ expect(() => verifyWhisperRuntimeDir(root, 'darwin', 'arm64', {+ checkArch: false,+ whisperContract: contract,+ allowSignedDarwinRuntime: true,+ expectedTeamIdentifier: 'TEAM123',+ verifySignedDarwinBinary: () => undefined,+ })).toThrow(/whisper runtime hash\/size mismatch/);+ });+it('fails when a foreign-platform FFmpeg payload remains in the package', () => {const root = path.join(tmpDir, 'runtime');const key = 'win32-x64';