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..f1b9f34 100644 --- a/src/util-identities.ts +++ b/src/util-identities.ts @@ -7,20 +7,35 @@ 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); } 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); } @@ -28,5 +43,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 & certificate-name pair, using input identity as-is:', identity, err); + identities.push(new Identitity(identity)) + } + return compactFlattenedList(identities); }