diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df5940..7c828f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - The MCP bundle now includes `lib/memory-contract.mjs` and `lib/continuity.mjs`; packaging and native materialization include both modules. - Hoje calls the existing word-presence evaluation “Retrieval checks” to distinguish it from model-answer accuracy. +### Fixed +- macOS KeepMind Corp builds now ad-hoc sign the complete app bundle and fail packaging if strict signature verification fails, fixing inconsistent resource seals. + ### Security - Continuity writes check revisions under a local project lock. Human review, lesson confirmation and feedback cannot be granted through model-supplied arguments. - Generic MCP writes refuse protected project/fact aliases, evidence cannot use symlinks or cross-space paths, and rejected writes retain audit coverage. diff --git a/electron-builder.corp.yml b/electron-builder.corp.yml index 529d257..ff37a0c 100644 --- a/electron-builder.corp.yml +++ b/electron-builder.corp.yml @@ -2,6 +2,7 @@ appId: com.keepmind.corp productName: KeepMind Corp icon: build/icon extends: electron-builder.yml +afterSign: scripts/mac-adhoc-sign.cjs directories: output: dist-corp files: @@ -29,6 +30,8 @@ publish: owner: criptogus repo: keepmind-corp mac: + # The afterSign hook seals the complete bundle with a deterministic ad-hoc signature. + identity: null extendInfo: CFBundleDisplayName: KeepMind Corp artifactName: KeepMind-Corp-${version}-${arch}-mac.${ext} diff --git a/scripts/mac-adhoc-sign.cjs b/scripts/mac-adhoc-sign.cjs new file mode 100644 index 0000000..c387daa --- /dev/null +++ b/scripts/mac-adhoc-sign.cjs @@ -0,0 +1,16 @@ +const { execFileSync } = require('node:child_process') +const { join } = require('node:path') + +// Corp only: avoid changing the main app's legacy safeStorage/keychain identity. +// In app-builder-lib 25.1.8 mac signApp returns true even with identity: null, +// so afterSign runs after all resource/plist changes, including for --mac --dir. +module.exports = function macAdhocSign(context) { + if (process.platform !== 'darwin' || context.electronPlatformName !== 'darwin') return + + const app = join(context.appOutDir, `${context.packager.appInfo.productFilename}.app`) + // Use argv directly so spaces in the product name/path need no shell quoting. + execFileSync('codesign', ['--force', '--deep', '--sign', '-', app], { stdio: 'inherit' }) + execFileSync('codesign', ['--verify', '--deep', '--strict', '--verbose=2', app], { stdio: 'inherit' }) + // codesign writes signature details to stderr; retain them in the build log. + execFileSync('codesign', ['-dv', '--verbose=4', app], { stdio: 'inherit' }) +} diff --git a/tests/mac-adhoc-sign.test.ts b/tests/mac-adhoc-sign.test.ts new file mode 100644 index 0000000..30712bd --- /dev/null +++ b/tests/mac-adhoc-sign.test.ts @@ -0,0 +1,67 @@ +import { createRequire } from 'node:module' +import { readFileSync } from 'node:fs' +import { join } from 'node:path' +import { afterEach, describe, expect, it, vi } from 'vitest' + +const require = createRequire(import.meta.url) +const childProcess = require('node:child_process') +const { load } = require('js-yaml') +const context = { + electronPlatformName: 'darwin', + appOutDir: '/tmp/corp build/mac-arm64', + packager: { appInfo: { productFilename: 'KeepMind Corp' } } +} + +// Spy on the CommonJS builtin used by the builder's CommonJS hook. +function setup(platform = 'darwin') { + vi.spyOn(process, 'platform', 'get').mockReturnValue(platform as NodeJS.Platform) + const exec = vi.spyOn(childProcess, 'execFileSync').mockImplementation(() => Buffer.alloc(0)) + const file = require.resolve('../scripts/mac-adhoc-sign.cjs') + delete require.cache[file] + return { exec, hook: require(file) } +} + +afterEach(() => vi.restoreAllMocks()) + +describe('Corp macOS ad-hoc signing', () => { + it('signs the whole product bundle, strictly verifies it, and logs its signature in order', () => { + const { exec, hook } = setup() + hook(context) + const app = join(context.appOutDir, 'KeepMind Corp.app') + expect(exec.mock.calls).toEqual([ + ['codesign', ['--force', '--deep', '--sign', '-', app], { stdio: 'inherit' }], + ['codesign', ['--verify', '--deep', '--strict', '--verbose=2', app], { stdio: 'inherit' }], + ['codesign', ['-dv', '--verbose=4', app], { stdio: 'inherit' }] + ]) + }) + + it.each(['linux', 'win32'])('skips on a %s host', platform => { + const { exec, hook } = setup(platform) + hook(context) + expect(exec).not.toHaveBeenCalled() + }) + + it('skips non-mac targets on a mac host', () => { + const { exec, hook } = setup() + hook({ ...context, electronPlatformName: 'win32' }) + expect(exec).not.toHaveBeenCalled() + }) + + it.each([1, 2])('fails the build when codesign call %i fails', call => { + const { exec, hook } = setup() + const failure = new Error('codesign failed') + for (let i = 1; i < call; i++) exec.mockImplementationOnce(() => Buffer.alloc(0)) + exec.mockImplementationOnce(() => { throw failure }) + expect(() => hook(context)).toThrow(failure) + expect(exec).toHaveBeenCalledTimes(call) + }) + + it('wires the Corp hook after signing and disables automatic certificate selection', () => { + const config = load(readFileSync('electron-builder.corp.yml', 'utf8')) + expect(config.afterSign).toBe('scripts/mac-adhoc-sign.cjs') + expect(config.mac.identity).toBeNull() + expect(typeof require(join(process.cwd(), config.afterSign))).toBe('function') + const main = load(readFileSync('electron-builder.yml', 'utf8')) + expect(main.afterSign).toBeUndefined() + }) +})