Skip to content

Commit 3be7baa

Browse files
fix(macos): timestamp hash-pinned Developer ID signatures (#118989)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent b6662bf commit 3be7baa

3 files changed

Lines changed: 91 additions & 2 deletions

File tree

‎docs/platforms/mac/signing.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ title: "macOS signing"
1313
- Node: `>=22.22.3 <23`, `>=24.15.0 <25`, or `>=25.9.0` (repo `package.json` `engines`). The packager also builds the Control UI (`pnpm ui:build`).
1414
- Requires a real signing identity by default; the codesign script exits with an error if none is found and `ALLOW_ADHOC_SIGNING` is not set. Ad-hoc signing (`SIGN_IDENTITY="-"`) is explicit opt-in and does not persist TCC permissions across rebuilds. See [macOS permissions](/platforms/mac/permissions).
1515
- Reads `SIGN_IDENTITY` from the environment (e.g. `export SIGN_IDENTITY="Apple Development: Your Name (TEAMID)"`, or a Developer ID Application cert). Without it, `codesign-mac-app.sh` auto-selects an identity in this order: Developer ID Application, Apple Distribution, Apple Development, then the first valid codesigning identity found.
16-
- `CODESIGN_TIMESTAMP=auto` (default) enables trusted timestamps only for Developer ID Application signatures. Set `on`/`off` to force either way.
16+
- `SIGN_IDENTITY` also accepts a certificate SHA-1 hash to distinguish certificates with the same common name.
17+
- `CODESIGN_TIMESTAMP=auto` (default) enables trusted timestamps for Developer ID Application signatures selected by name or certificate hash. Set `on`/`off` to force either way.
1718
- Stamps Info.plist with `OpenClawBuildTimestamp` (ISO8601 UTC) and `OpenClawGitCommit` (short hash, `unknown` if unavailable) so the About tab can show build, git, and debug/release channel.
1819
- Runs a Team ID audit after signing and fails if any Mach-O inside the bundle has a different Team ID. Set `SKIP_TEAM_ID_CHECK=1` to bypass.
1920

‎scripts/codesign-mac-app.sh‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ case "$TIMESTAMP_MODE" in
162162
timestamp_arg="--timestamp=none"
163163
;;
164164
auto)
165-
if [[ "$IDENTITY" == *"Developer ID Application"* ]]; then
165+
identity_name="$IDENTITY"
166+
if [[ "$IDENTITY" =~ ^[[:xdigit:]]{40}$ ]]; then
167+
# A hash selector conceals the certificate class required for notarization timestamps.
168+
identity_name="$(security find-identity -p codesigning -v 2>/dev/null \
169+
| awk -v hash="$IDENTITY" 'toupper($2) == toupper(hash) { print }')"
170+
fi
171+
if [[ "$identity_name" == *"Developer ID Application"* ]]; then
166172
timestamp_arg="--timestamp"
167173
fi
168174
;;

‎test/scripts/codesign-mac-app.test.ts‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function installFakeCodesign(binDir: string) {
3939
`#!/usr/bin/env bash
4040
set -euo pipefail
4141
42+
if [ -n "\${CODESIGN_ARGS_LOG:-}" ]; then
43+
printf '%s\\n' "$*" >>"$CODESIGN_ARGS_LOG"
44+
fi
45+
4246
entitlements=""
4347
target=""
4448
while [ "$#" -gt 0 ]; do
@@ -475,4 +479,82 @@ describe("codesign-mac-app temp file hygiene", () => {
475479
expect(readFileSync(countFile, "utf8")).toBe("1");
476480
expect(entitlementTemps(tempRoot)).toEqual([]);
477481
});
482+
483+
it.each([
484+
{
485+
label: "Developer ID hash",
486+
identity: "63A99BFF1D40E5A75C8A32B84BE99D1DDA6A44E1",
487+
timestamp: true,
488+
},
489+
{
490+
label: "lowercase Developer ID hash",
491+
identity: "63a99bff1d40e5a75c8a32b84be99d1dda6a44e1",
492+
timestamp: true,
493+
},
494+
{
495+
label: "Developer ID name",
496+
identity: "Developer ID Application: Example Corp (ABCDE12345)",
497+
timestamp: true,
498+
},
499+
{
500+
label: "development certificate hash",
501+
identity: "11AA22BB33CC44DD55EE66FF77008899AABBCCDD",
502+
timestamp: false,
503+
},
504+
{
505+
label: "unknown certificate hash",
506+
identity: "0123456789ABCDEF0123456789ABCDEF01234567",
507+
timestamp: false,
508+
},
509+
{ label: "ad-hoc identity", identity: "-", timestamp: false },
510+
{
511+
label: "explicitly disabled timestamp",
512+
identity: "63A99BFF1D40E5A75C8A32B84BE99D1DDA6A44E1",
513+
timestamp: false,
514+
mode: "off",
515+
},
516+
])("applies automatic timestamp policy to $label", ({ identity, timestamp, mode }) => {
517+
const tempRoot = tempDirs.make("openclaw-codesign-timestamp-");
518+
const app = path.join(tempRoot, "Fake.app");
519+
const binDir = path.join(tempRoot, "bin");
520+
const captureDir = path.join(tempRoot, "capture");
521+
const argsLog = path.join(captureDir, "codesign-args.log");
522+
mkdirSync(path.join(app, "Contents", "MacOS"), { recursive: true });
523+
mkdirSync(binDir);
524+
mkdirSync(captureDir);
525+
writeFileSync(path.join(app, "Contents", "MacOS", "OpenClaw"), "#!/bin/sh\n");
526+
installFakeCodesign(binDir);
527+
const fakeSecurity = path.join(binDir, "security");
528+
writeFileSync(
529+
fakeSecurity,
530+
`#!/usr/bin/env bash
531+
printf '%s\\n' \\
532+
' 1) 63A99BFF1D40E5A75C8A32B84BE99D1DDA6A44E1 "Developer ID Application: Example Corp (ABCDE12345)"' \\
533+
' 2) 11AA22BB33CC44DD55EE66FF77008899AABBCCDD "Apple Development: Example Developer (ABCDE12345)"'
534+
`,
535+
);
536+
chmodSync(fakeSecurity, 0o755);
537+
538+
const result = spawnSync("bash", [scriptPath, app], {
539+
cwd: process.cwd(),
540+
encoding: "utf8",
541+
env: {
542+
...process.env,
543+
CODESIGN_ARGS_LOG: argsLog,
544+
CODESIGN_CAPTURE_DIR: captureDir,
545+
CODESIGN_LOG: path.join(captureDir, "codesign.log"),
546+
PATH: `${binDir}${path.delimiter}${process.env.PATH ?? ""}`,
547+
SIGN_IDENTITY: identity,
548+
SKIP_TEAM_ID_CHECK: "1",
549+
TMPDIR: tempRoot,
550+
...(mode === undefined ? {} : { CODESIGN_TIMESTAMP: mode }),
551+
},
552+
});
553+
554+
expect(result.status).toBe(0);
555+
const expectedFlag = timestamp ? "--timestamp" : "--timestamp=none";
556+
for (const args of readFileSync(argsLog, "utf8").trim().split("\n")) {
557+
expect(args.split(" ")).toContain(expectedFlag);
558+
}
559+
});
478560
});

0 commit comments

Comments
 (0)