Skip to content

Commit 0a25651

Browse files
Copilotshouze
andcommitted
feat: state of the art signing for macOS with entitlements and verification
Co-authored-by: shouze <54712+shouze@users.noreply.github.com>
1 parent 1a6b423 commit 0a25651

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

build.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,33 @@ console.log(` Built ${outfile}`);
8888
// ─── Ad-hoc codesign (macOS only) ────────────────────────────────────────────
8989

9090
if (targetOs === "darwin" && process.platform === "darwin") {
91-
const sign = Bun.spawn(["codesign", "--force", "--sign", "-", outfile], {
92-
stdout: "inherit",
93-
stderr: "inherit",
94-
});
91+
const sign = Bun.spawn(
92+
[
93+
"codesign",
94+
"--deep",
95+
"--force",
96+
"--sign",
97+
"-",
98+
"--entitlements",
99+
`${import.meta.dir}/entitlements.plist`,
100+
outfile,
101+
],
102+
{ stdout: "inherit", stderr: "inherit" },
103+
);
95104
const signCode = await sign.exited;
96105
if (signCode !== 0) {
97106
console.error(`codesign failed (exit ${signCode})`);
98107
process.exit(signCode);
99108
}
100109
console.log(` Codesigned ${outfile}`);
110+
111+
const verify = Bun.spawn(["codesign", "--verify", "--verbose", outfile], {
112+
stdout: "inherit",
113+
stderr: "inherit",
114+
});
115+
const verifyCode = await verify.exited;
116+
if (verifyCode !== 0) {
117+
console.error(`codesign verification failed (exit ${verifyCode})`);
118+
process.exit(verifyCode);
119+
}
101120
}

entitlements.plist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.allow-jit</key>
6+
<true/>
7+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8+
<true/>
9+
<key>com.apple.security.cs.disable-executable-page-protection</key>
10+
<true/>
11+
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
12+
<true/>
13+
<key>com.apple.security.cs.disable-library-validation</key>
14+
<true/>
15+
</dict>
16+
</plist>

0 commit comments

Comments
 (0)