Electron打包后如何正确进行代码签名?

红爱 Dev 阅读 36

我用Electron Forge打包了一个macOS应用,但安装时提示“无法验证开发者”,查了文档说要代码签名。我申请了Apple Developer证书,也在build配置里加了identity: '我的证书名',可还是报错“no identity found”。

是不是还要额外配置entitlements文件?或者我的证书类型不对?有人遇到过类似问题吗?

{
  "packagerConfig": {
    "osxSign": {
      "identity": "Apple Development: myname@example.com (XXXXXX)",
      "entitlements": "entitlements.mac.plist"
    }
  }
}
我来解答 赞 5 收藏
二维码
手机扫码查看
1 条解答
技术慧玲
这个问题我踩过坑,说下怎么解决。

"no identity found" 一般是证书名称没写对,不是你配置里写的那个格式。

先在终端查一下你钥匙串里的证书实际名称:

security find-identity -v -p codesigning


会列出类似 "Developer ID Application: Your Name (TEAMID)" 这样的完整名称,复制这个填到 identity 里。

另外 Apple Development 证书是开发测试用的,如果你要分发给用户(不走 App Store),得用 Developer ID Application 证书,不是 Apple Development。

完整的配置大概这样:

{
"packagerConfig": {
"osxSign": {
"identity": "Developer ID Application: Your Name (XXXXXXXXXX)",
"entitlements": "entitlements.mac.plist",
"entitlementsInherit": "entitlements.mac.plist",
"hardenedRuntime": true,
"signatureFlags": ["library"]
},
"osxNotarize": {
"appleId": "your@email.com",
"appleIdPassword": "your-app-specific-password",
"teamId": "XXXXXXXXXX"
}
}
}


entitlements.mac.plist 文件内容:





com.apple.security.cs.allow-jit

com.apple.security.cs.allow-unsigned-executable-memory

com.apple.security.cs.disable-library-validation




hardenedRuntime 记得开,不开的话有些系统会直接拒绝运行。

最后提醒一句:代码签名和公证是两件事。macOS 10.15+ 不仅要签名,还要 notarize(公证),否则安装完还是报"无法验证开发者"。上面配置里的 osxNotarize 就是干这个的。
点赞
2026-03-17 03:02