Repository navigation
fix: resolve identity name when signing with a certificate hash - #454
Conversation
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
There was a problem hiding this comment.
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
|
I've been noodling this one for a few days, here's my pitch: Add an optional arg to 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 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 I like that it simplifies the code and doesn't add any new method with only a minimal addition to |
|
A test seems sensible here too, appreciate your attention on this! |
|
I like the approach of adding the optional |
The proposed fix from claude in this PR does the same thing given it runs For ref, Turning And running To your point though, that's correct a duplicate identity (that's expired or un-trusted) being explicitly targeted via And further to that point, it's confusing that with If we try the more intuitive thing: const args = ['find-identity'];
if(validate){
args.push("-v");
}the behavior of Here's an example logSo the parsing potentially needs to be bumped too, unless the true duplicates are already handled? |
Took this concept and made the PROkay All Together NowWe amend We also make it look at unsigned/expired identities when NOTE: Need to sanity check 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 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 |
|
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 I think the PR distills the issue and fix nicely - appreciate whenever someone has a moment to review. |
|
🎉 This PR is included in version 2.7.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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-identityoutput only, not on macOS with real certificates.🤖 Generated with Claude Code
https://claude.ai/code/session_01D1vsfeqU5CviMmTaAJbdP5
Generated by Claude Code