Skip to content

fix: resolve identity name when signing with a certificate hash - #454

Merged
MarshallOfSound merged 2 commits into
mainfrom
fix/identity-hash-team-id
Oct 25, 2026
Merged

MarshallOfSound merged 2 commits into
mainfrom
fix/identity-hash-team-id

Conversation

@claude

@claude claude Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Requested via Slack thread

Fixes #452.

When identity validation is turned off (as electron-builder does) and the identity is a certificate hash rather than a name, osx-sign had no certificate name to read the Apple team ID from, so sandboxed apps without ElectronTeamID in their Info.plist failed with "Could not automatically determine ElectronTeamID". This change looks up 40-character hash identities in the keychain before signing so both the name and the hash are known; if no certificate matches or the lookup fails, signing behaves exactly as before, and identities given by name are passed through untouched with no extra lookup.

This has been tested with mocked security find-identity output only, not on macOS with real certificates.

🤖 Generated with Claude Code

https://claude.ai/code/session_01D1vsfeqU5CviMmTaAJbdP5


Generated by Claude Code

With `identityValidation: false`, a certificate SHA-1 hash passed as
`identity` was used as the identity's name, so preAutoEntitlements could
not parse a team ID from it and threw "Could not automatically determine
ElectronTeamID". Passing the name instead is ambiguous to codesign when
two certificates share it.

When the unvalidated identity is a SHA-1 hash, look it up with
`security find-identity` on a best-effort basis to recover the name,
while codesign keeps receiving the hash. If the lookup fails or finds
nothing, fall back to the raw value as before.

Fixes #452

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D1vsfeqU5CviMmTaAJbdP5
@claude
claude Bot requested a review from a team as a code owner September 28, 2026 00:08
@claude
claude Bot requested a review from mmaietta September 28, 2026 00:08
@claude claude Bot mentioned this pull request Sep 28, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — the fallback logic preserves prior behavior exactly (falls back to new Identity(identity) on no match, lookup error, or non-hash input) while adding a best-effort keychain lookup so the team ID can be parsed when signing with a hash. Reviewed: the resolve/fallback logic in resolveUnvalidatedIdentity, how identity.hash || identity.name in signApplication keeps the --sign value unchanged after resolution, and test coverage for hash/case/duplicate/error/name paths — all consistent with the described fix.

Extended reasoning...

Small, self-contained change (one new exported helper plus a one-line call-site swap) affecting how osx-sign resolves a certificate identity when identityValidation is disabled; no crypto/auth logic changes, only a lookup step feeding an existing team-ID-parsing path. Verified the fallback to raw Identity construction is preserved on every failure path, and that the resolved Identity's hash is still used for the actual --sign argument so signing behavior is unchanged when resolution succeeds. Tests are thorough (unit + integration) and match the described behavior in the diff.

…m-id

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D1vsfeqU5CviMmTaAJbdP5
@Bug-Reaper

Bug-Reaper commented Oct 1, 2026 •

Copy link
Copy Markdown

I've been noodling this one for a few days, here's my pitch:

Add an optional arg to findIdentities(keychain, hash, validate = true) and then we can always just run findIdentities for all flows and only have the method fallback to the new Identity("raw input string") if validate = false.

Kind of nit from me as I'm not working in this code much. But it'd look like this:

export async function findIdentities(keychain: string | null, identity: string, validate: bool=true) {
  // Only to look for valid identities, excluding those flagged with
  // CSSMERR_TP_CERT_EXPIRED or CSSMERR_TP_NOT_TRUSTED. Fixes #9

  const args = ['find-identity', '-v'];
  if (keychain) {
    args.push(keychain);
  }

  const result = await execFileAsync('security', args);
  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);
      debugLog('Identity:', '\n', '> Name:', identityFound, '\n', '> Hash:', identityHashFound);
      return new Identity(identityFound, identityHashFound);
    }
    return null;
  });
  
  // NEW LOGIC
  if(identities.length==0 && !validate){
      debugLog('Failed to look up identity hash, using it as-is:', identity, err);
      identities.push(new Identity(identity));
  }
  // END NEW LOGIC
  
  return compactFlattenedList(identities);
}

Then in sign()

this:

//...
if (validatedOpts.identity) {
    debugLog('`identity` passed in arguments.');
    if (validatedOpts.identityValidation === false) {
      identityInUse = await resolveUnvalidatedIdentity(
        validatedOpts.keychain || null,
        validatedOpts.identity,
      );
    } else {
      identities = await findIdentities(validatedOpts.keychain || null, validatedOpts.identity);
    }
  }
//...

Can be simplified to

if (validatedOpts.identity) {
   
    debugLog('`identity` passed in arguments.');
    identities = await findIdentities(validatedOpts.keychain || null, validatedOpts.identity, !(validatedOpts.identityValidation === false));
  
  }

And all the behavior is preserved, doesn't change the usage of findIdentities() anywhere else in the codebase.

I like that it simplifies the code and doesn't add any new method with only a minimal addition to findIdentities(). Probably helps make the logic easier to follow but lmk what you think @mmaietta

@Bug-Reaper

Bug-Reaper commented Oct 1, 2026 •

Copy link
Copy Markdown

A test seems sensible here too, appreciate your attention on this!

@mmaietta

mmaietta commented Oct 1, 2026

Copy link
Copy Markdown

I like the approach of adding the optional validate arg to simplify the entrypoint, but your suggestion also runs security find-identity for identities given by name when validation is off. If I'm understanding correctly, that drops expired certificates and could still hit the "multiple identities" error, which turning validation off currently avoids with this change.

@Bug-Reaper

Bug-Reaper commented Oct 2, 2026 •

Copy link
Copy Markdown

I like the approach of adding the optional validate arg to simplify the entrypoint, but your suggestion also runs security find-identity for identities given by name when validation is off. If I'm understanding correctly, that drops expired certificates and could still hit the "multiple identities" error, which turning validation off currently avoids with this change.

The proposed fix from claude in this PR does the same thing given it runs findIdentities in resolveUnvalidatedIdentity.

For ref, findIdentities runs security find-identity -v with optional --keychain specifier.

Turning validate=false simply allows this method to return the raw input identity if no valid one is found.

And running security find-identity -v to get extra info like we're doing in both solutions doesn't actually force-on any validation


To your point though, that's correct a duplicate identity (that's expired or un-trusted) being explicitly targeted via CSC_NAME=<IDENTITYHASH> or something would still be bugged. (Applies to both fixes).

And further to that point, it's confusing that with validate=false It won't look at expired/un-trusted identities. I wasn't a huge fan of that either.

If we try the more intuitive thing:

  const args = ['find-identity'];
  if(validate){
    args.push("-v");
  }

the behavior of security find-identity changes without -v flag where it then lists out all identities (verified & invalidated) followed by all verified identities.

Here's an example log
👉 security find-identity -v            
 1) FC1A16756489E49CD3F03D55A89FAB453C0E7C7B "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 2) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 3) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 4) E8AF00545728444E4B2439B28054962FF9F5D58C "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 5) D37C92D2935AC1F1AE6F317CFEBE510295A409D3 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 6) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 7) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 8) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 9) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
10) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
11) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
    11 valid identities found

👉 security find-identity               

Policy: X.509 Basic
 Matching identities
 1) FC1A16756489E49CD3F03D55A89FAB453C0E7C7B "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 2) 2A3E1E027C6C6311A0B66087E092C2931BE88DF1 "Developer ID Application: tim apple (ZZZZZZZZZZ)" (CSSMERR_TP_CERT_EXPIRED)
 3) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 4) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 5) E8AF00545728444E4B2439B28054962FF9F5D58C "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 6) D37C92D2935AC1F1AE6F317CFEBE510295A409D3 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 7) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 8) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 9) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
10) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
11) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
12) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
    12 identities found

 Valid identities only
 1) FC1A16756489E49CD3F03D55A89FAB453C0E7C7B "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 2) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 3) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 4) E8AF00545728444E4B2439B28054962FF9F5D58C "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 5) D37C92D2935AC1F1AE6F317CFEBE510295A409D3 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
 6) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 7) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 8) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
 9) 082F22402E3FCF18C19E959ECC5963836370BB9E "Developer ID Application: tim apple (ZZZZZZZZZZ)"
10) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"
11) 148EBF0A1F92BC0BF106BE497AA5135C2E33E199 "Developer ID Installer: tim apple (ZZZZZZZZZZ)"

So the parsing potentially needs to be bumped too, unless the true duplicates are already handled?

@Bug-Reaper

Bug-Reaper commented Oct 2, 2026 •

Copy link
Copy Markdown
Took this concept and made the PR

Okay All Together Now

We amend findIdentities to return the input identity that could not be found if validate is passed in as false.

We also make it look at unsigned/expired identities when validate is false to keep it consistent and avoid some extremely niche edge-cases.

NOTE: Need to sanity check compactFlattenedList removes true duplicate identities (same hash)

export async function findIdentities(keychain: string | null, identity: string, validate: bool=true) {


  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);
  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);
      debugLog('Identity:', '\n', '> Name:', identityFound, '\n', '> Hash:', identityHashFound);
      return new Identity(identityFound, identityHashFound);
    }
    return null;
  });
  
  if(identities.length==0 && !validate){
      debugLog('Failed to look up identity hash, using it as-is:', identity, err);
      identities.push(new Identity(identity));
  }
  
  return compactFlattenedList(identities);
}

Then in sign() it's safe to simplify:

if (validatedOpts.identity) {
   
    debugLog('`identity` passed in arguments.');
    identities = await findIdentities(validatedOpts.keychain || null, validatedOpts.identity, !(validatedOpts.identityValidation === false));
  
  }

Behavior is unchanged for everyone, edge cases are now covered, simplifies sign logic, etc...

see #458

@Bug-Reaper

Bug-Reaper commented Oct 2, 2026 •

Copy link
Copy Markdown

Maintainers/@mmaietta . Here's a PR candidate alternative to put the "half baked identity" paradox to bed for good

https://github.com/electron/osx-sign/pull/458/changes

Instead of nesting a new helper method, I refined the flow/logic to be simpler. Basically just always try to get the full identity-info pair hash/name and then if validate is false we will still pass through a half-baked identity part if the full pair can't be resolved.

I think the PR distills the issue and fix nicely - appreciate whenever someone has a moment to review.

@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) October 25, 2026 22:04
@MarshallOfSound
MarshallOfSound merged commit a760994 into main Oct 25, 2026
9 checks passed
@MarshallOfSound
MarshallOfSound deleted the fix/identity-hash-team-id branch October 25, 2026 22:04
@electron-npm-package-publisher

Copy link
Copy Markdown

🎉 This PR is included in version 2.7.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Identity Resolution Catch-22

4 participants