From 2527bf6487bfcd09631d7bb9d4522368c4f2b6b9 Mon Sep 17 00:00:00 2001 From: Bug-Reaper Date: Fri, 2 Oct 2026 00:07:30 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=8D=20:=20Fix=20:=20Always=20attem?= =?UTF-8?q?pt=20to=20resolve=20identityHash=20&=20certificateName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need both for different edge-cases that can also overlap. For that reason we do this even if validation is turned off. If validation is off, an unresolved identity-part will still be as-is to `new Identity(opts.identity )` & this preserves older behavior. More info here https://github.com/electron/osx-sign/issues/452 --- src/sign.ts | 6 +----- src/util-identities.ts | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/sign.ts b/src/sign.ts index 5bc6c91..ffa866e 100644 --- a/src/sign.ts +++ b/src/sign.ts @@ -440,11 +440,7 @@ export async function sign(_opts: SignOptions) { // Determine identity for signing if (validatedOpts.identity) { debugLog('`identity` passed in arguments.'); - if (validatedOpts.identityValidation === false) { - identityInUse = new Identity(validatedOpts.identity); - } else { - identities = await findIdentities(validatedOpts.keychain || null, validatedOpts.identity); - } + identities = await findIdentities(validatedOpts.keychain || null, validatedOpts.identity, !(validatedOpts.identityValidation === false)); } else { debugWarn('No `identity` passed in arguments...'); if (validatedOpts.platform === 'mas') { diff --git a/src/util-identities.ts b/src/util-identities.ts index 2d47aa4..29e0b46 100644 --- a/src/util-identities.ts +++ b/src/util-identities.ts @@ -7,11 +7,19 @@ export class Identity { ) {} } -export async function findIdentities(keychain: string | null, identity: string) { - // Only to look for valid identities, excluding those flagged with - // CSSMERR_TP_CERT_EXPIRED or CSSMERR_TP_NOT_TRUSTED. Fixes #9 +export async function findIdentities(keychain: string | null, identity: string, validate: bool = true) { + // An incoming identity string will be either a certificateName OR the identityHash for a certificate. + // Certain edge-cases require us to have the identityHash to correctly invoke `codesign`. + // Other flows require us to have the certificateName for automatic plist entitlement management done by osx-sign. + // For those reasons, we always try to extrapolate the full certificateName & identityHash pair + // More info here : https://github.com/electron/osx-sign/issues/452 - const args = ['find-identity', '-v']; + const args = ['find-identity']; + if(validate){ + // Only to look for valid identities, excluding those flagged with + // CSSMERR_TP_CERT_EXPIRED or CSSMERR_TP_NOT_TRUSTED. Fixes #9 + args.push('-v'); + } if (keychain) { args.push(keychain); } @@ -28,5 +36,10 @@ export async function findIdentities(keychain: string | null, identity: string) return null; }); + if(identities.length==0 && !validate){ + debugLog('Failed to look up full identity-hash & name pair, using input identity as-is:', identity, err); + identities.push(new Identitity(identity)) + } + return compactFlattenedList(identities); } From 83417c00b03542838cebfb69ef18cbaae6af3c7c Mon Sep 17 00:00:00 2001 From: Bug-Reaper Date: Fri, 2 Oct 2026 01:24:52 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=82=EF=B8=8F=20=20:=20Fix=20:=20Preve?= =?UTF-8?q?nt=20duplicate=20results=20from=20being=20parsed=20after=20`sec?= =?UTF-8?q?urity=20find-identity`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that we allow `security find-identity` w/o `-v` we must accomodate for a result which will contain all valid identities twice. --- src/util-identities.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util-identities.ts b/src/util-identities.ts index 29e0b46..f1b9f34 100644 --- a/src/util-identities.ts +++ b/src/util-identities.ts @@ -25,10 +25,17 @@ export async function findIdentities(keychain: string | null, identity: string, } const result = await execFileAsync('security', args); + // When running with validate=false. All valid identities will appear in results twice. Set() on unique hash is used here to prevent duplicates stacking up + const seen: Set = new Set(); + const identities = result.split('\n').map(function (line) { if (line.indexOf(identity) >= 0) { const identityFound = line.substring(line.indexOf('"') + 1, line.lastIndexOf('"')); const identityHashFound = line.substring(line.indexOf(')') + 2, line.indexOf('"') - 1); + if (seen.has(identityHashFound)) { + return null; // duplicate + } + seen.add(identityHashFound); debugLog('Identity:', '\n', '> Name:', identityFound, '\n', '> Hash:', identityHashFound); return new Identity(identityFound, identityHashFound); } @@ -37,7 +44,7 @@ export async function findIdentities(keychain: string | null, identity: string, }); if(identities.length==0 && !validate){ - debugLog('Failed to look up full identity-hash & name pair, using input identity as-is:', identity, err); + debugLog('Failed to look up full identity-hash & certificate-name pair, using input identity as-is:', identity, err); identities.push(new Identitity(identity)) }