The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(build): sign nested Chromium with the discovered certificate hash
etherneta3ff6bb986e3
diff --git a/apps/desktop/scripts/sign-nested-chromium.mjs b/apps/desktop/scripts/sign-nested-chromium.mjsindex 474e18839d9..999a1809e54 100644--- a/apps/desktop/scripts/sign-nested-chromium.mjs+++ b/apps/desktop/scripts/sign-nested-chromium.mjs@@ -146,38 +146,30 @@ function repairOneFramework(frameworkDir) {return repaired}-export function parseDeveloperId(identityList) {+export function parseDeveloperId(identityList, qualifier = null) {const line = String(identityList || '').split(/\r?\n/)- .find(l => l.includes('Developer ID Application:'))+ .find(l => l.includes('Developer ID Application:') && (!qualifier || l.includes(qualifier)))if (!line) return null- const quoted = line.match(/"([^"]+)"/)- return quoted ? quoted[1] : null+ // Match electron-builder's selector: a certificate fingerprint, not the+ // display name shared by renewed certificates or identities in other keychains.+ const identity = line.match(/^\s*\d+\)\s+([\dA-Fa-f]{40})\s+"Developer ID Application:[^"]+"/)+ return identity ? identity[1] : null}export function findDeveloperId(exec = execFileSync, keychain = null) {- if (process.env.CSC_NAME) return process.env.CSC_NAMEconst args = ['find-identity', '-v', '-p', 'codesigning']if (keychain) args.push(keychain)- let out- try {- out = exec('security', args, { encoding: 'utf8' })- } catch {- return null+ const out = exec('security', args, { encoding: 'utf8' })+ const identity = parseDeveloperId(out, process.env.CSC_NAME?.trim())+ if (!identity && (keychain || process.env.CSC_NAME)) {+ throw new Error(`sign-nested-chromium: no matching Developer ID Application identity in ${keychain || 'the default keychain'}`)}- return parseDeveloperId(out)+ return identity}export async function resolveSigningIdentity(packager, exec = execFileSync) {- if (!packager?.codeSigningInfo?.value) {- return { identity: findDeveloperId(exec), keychain: null }- }- let info- try {- info = await packager.codeSigningInfo.value- } catch {- return { identity: findDeveloperId(exec), keychain: null }- }+ const info = await packager?.codeSigningInfo?.valueconst keychain = info?.keychainFile || process.env.CSC_KEYCHAIN || nullreturn { identity: findDeveloperId(exec, keychain), keychain }}diff --git a/apps/desktop/scripts/sign-nested-chromium.test.mjs b/apps/desktop/scripts/sign-nested-chromium.test.mjsindex cf25439f312..2550006bc34 100644--- a/apps/desktop/scripts/sign-nested-chromium.test.mjs+++ b/apps/desktop/scripts/sign-nested-chromium.test.mjs@@ -1,11 +1,13 @@import assert from 'node:assert/strict'+import childProcess from 'node:child_process'import fs from 'node:fs'+import { syncBuiltinESMExports } from 'node:module'import os from 'node:os'import path from 'node:path'-import { test } from 'vitest'+import { MacTargetHelper } from 'app-builder-lib/internal'+import { test, vi } from 'vitest'import {- parseDeveloperId,repairFrameworkLinks,resolveSigningIdentity,signNestedChromium@@ -44,16 +46,6 @@ test('repairFrameworkLinks turns a flattened Foo.framework/Foo into a symlink',}})-test('parseDeveloperId takes the first Developer ID Application line', () => {- const listing = `- 1) ABC "Apple Development: [email protected] (TEAM)"- 2) DEF "Developer ID Application: Nous Research Inc (763K57MW7Z)"- 3) GHI "Developer ID Installer: Nous Research Inc (763K57MW7Z)"-`- assert.equal(parseDeveloperId(listing), 'Developer ID Application: Nous Research Inc (763K57MW7Z)')- assert.equal(parseDeveloperId('nothing here'), null)-})-test('signNestedChromium no-ops without an identity', () => {const payload = tempRoot()try {@@ -99,19 +91,89 @@ test('signNestedChromium --deep signs the .app and file-signs loose Mach-O', ()}})-test('resolveSigningIdentity reads the packager keychain', async () => {- const seen = []+test('nested Chromium uses the same keychain certificate selector as the installed builder', async () => {+ const payload = tempRoot()+ const keychain = path.join(payload, 'builder.keychain')+ const hash = '0123456789ABCDEF0123456789ABCDEF01234567'+ const otherHash = 'F'.repeat(40)+ const listing = ` 1) ${hash} "Developer ID Application: Signing Fixture (TEAM)"\n 2) ${otherHash} "Developer ID Application: Other Fixture (TEAM)"\n 2 valid identities found\n`+ let ready = falseconst packager = {+ config: {},+ resourceList: Promise.resolve([]),codeSigningInfo: {- value: Promise.resolve({ keychainFile: '/tmp/builder.keychain' })+ value: Promise.resolve().then(() => {+ ready = true+ return { keychainFile: keychain }+ })}}- const listing = ' 1) DEF "Developer ID Application: Nous Research Inc (763K57MW7Z)"\n'- const r = await resolveSigningIdentity(packager, (_cmd, args) => {- seen.push(args)+ const readIdentity = (cmd, args) => {+ assert.ok(ready, 'identity discovery must await builder keychain initialization')+ assert.equal(path.basename(cmd), 'security')+ assert.equal(args[0], 'find-identity', 'never import credentials in this test')+ assert.equal(args.at(-1), keychain)return listing+ }+ // Exercise the installed builder's discovery and options, replacing only the+ // native process boundary. This proves selector parity, not native signing.+ const native = vi.spyOn(childProcess, 'execFile').mockImplementation((cmd, args, options, callback) => {+ callback(null, readIdentity(cmd, args), '')+ return undefined})- assert.equal(r.identity, 'Developer ID Application: Nous Research Inc (763K57MW7Z)')- assert.equal(r.keychain, '/tmp/builder.keychain')- assert.ok(seen[0].includes('/tmp/builder.keychain'))+ syncBuiltinESMExports()+ vi.stubEnv('CSC_NAME', undefined)+ vi.stubEnv('CSC_IDENTITY_AUTO_DISCOVERY', 'true')+ try {+ const app = path.join(payload, 'tools', 'chromium-1208', 'Browser.app')+ fs.mkdirSync(app, { recursive: true })+ const entitlements = path.join(payload, 'entitlements.plist')+ fs.writeFileSync(entitlements, '<plist/>')+ const helper = new MacTargetHelper(packager)+ const nested = await resolveSigningIdentity(packager, readIdentity)+ const identity = await helper.findSigningIdentity('mac', undefined, keychain, false)+ const outer = await helper.buildSignOptions(app, identity, undefined, keychain, undefined, 'mac')+ const calls = []+ const signed = signNestedChromium(payload, {+ ...nested, entitlements, exec: (cmd, args) => calls.push([cmd, ...args])+ })+ assert.equal(signed.signed, 1)+ assert.equal(calls.length, 1)+ const args = calls[0]+ assert.equal(outer.identity, hash)+ assert.equal(args[args.indexOf('--sign') + 1], outer.identity)+ assert.equal(args[args.indexOf('--keychain') + 1], outer.keychain)+ assert.ok(args.includes('--deep') && args.includes('--timestamp') && args.includes('runtime'))+ assert.equal(args.at(-1), app)+ vi.stubEnv('CSC_NAME', 'Other Fixture')+ const qualified = await resolveSigningIdentity(packager, readIdentity)+ const selected = await helper.findSigningIdentity('mac', undefined, keychain, false)+ assert.equal(selected.hash, otherHash)+ assert.equal(qualified.identity, selected.hash, 'CSC_NAME is a qualifier, not a codesign selector')+ } finally {+ native.mockRestore()+ syncBuiltinESMExports()+ vi.unstubAllEnvs()+ fs.rmSync(payload, { recursive: true, force: true })+ }+})++test('identity preparation failures abort instead of selecting another keychain or skipping signing', async () => {+ vi.stubEnv('CSC_NAME', 'Signing Fixture')+ try {+ const importFailure = new Error('builder keychain initialization failed')+ const packager = { codeSigningInfo: { value: Promise.reject(importFailure) } }+ await assert.rejects(resolveSigningIdentity(packager, () => {+ assert.fail('must not discover identities after the builder keychain failed')+ }), error => error === importFailure)+ const keychain = path.join(os.tmpdir(), 'builder.keychain')+ packager.codeSigningInfo = { value: Promise.resolve({ keychainFile: keychain }) }+ const discoveryFailure = new Error('security could not read the keychain')+ await assert.rejects(resolveSigningIdentity(packager, () => { throw discoveryFailure }),+ error => error === discoveryFailure)+ vi.stubEnv('CSC_NAME', undefined)+ await assert.rejects(resolveSigningIdentity(packager, () => ' 0 valid identities found\n'), /Developer ID/)+ } finally {+ vi.unstubAllEnvs()+ }})