macOS开发应用Sign(签名)和Notarizaiton(公证)

签名

可执行文件签名:

codesign -f -s ${证书ID} --timestamp ${签名文件}

.Pkg安装文件签名:

productsign --timestamp --sign ${证书ID} ${.pkg签名文件} ${.pkg签名后文件}

公证

新闻:苹果强制启用公证

2020年2月3日起,Mac App Store 以外通过其他途径分发的 Mac 软件必须经过 Apple 公证,才能在 macOS Catalina 中运行

公证命令

xcrun altool --notarize-app --primary-bundle-id ${AppBundleID 唯一标识} --username ${AppleID} --asc-provider ${证书提供者} --password ${应用公证专用密码} --file ${公证文件}

asc-provider:证书提供者,查询命令如下:

xcrun altool --list-providers -u  ${AppleID} -p ${应用公证专用密码}

问题1: The executable does not have the hardened runtime enabled

在公证后的报告中,遇到"message": "The executable does not have the hardened runtime enabled."错误是因为编译的时候没有开启hardened runtime导致的,可以采用codesign --options runtime --entitlements ${path}/app.entitlements解决,其中app.entitlements内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.cs.disable-library-validation</key>
	<true/>
	<key>com.apple.security.automation.apple-events</key>
	<true/>
	<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
	<true/>
	<key>com.apple.security.cs.allow-jit</key>
	<true/>
	<key>com.apple.security.cs.allow-dyld-environment-variables</key>
	<true/>
	<key>com.apple.security.cs.disable-executable-page-protection</key>
	<true/>
</dict>
</plist>

参考文章

[1] Mac notarizing 公证使用记录

[2] Mac app 打包时 Notarizition(公证)相关需求记录

[3] Mac开发-公证流程记录Notarizaiton-附带脚本

[4] Mac Electron 应用的签名(signature)和公证(notarization)

posted @ 2021-11-18 15:14  Macrored  阅读(1383)  评论(0编辑  收藏  举报