一 背景
- 从 macOS10.15版本后,从 App Store 之外分发的 App 都需要经过 签名 和 Apple 公证(notarize),否则下载安装后打开会弹出“无法打开”,“移到废纸篓”的提示。
- 公司一款自用的跨平台构建的mac软件,一直放在公司服务器上供下载使用,macOS10.15后遇见了该问题。几经周折尝试,才签名公证成功,记录如下。
- 由于软件跨平台构建,脚本一键构建打包。寻求方案主要关注命令行处理方式。
- 软件取名 Dog, dmg包,部分描述信息用xxxx代替。
二 签名证书
- 参考官网 Create, export, and delete signing certificates
- 支持部门同事处理,获得 签名证书.p12文件,安装。
- 可在 钥匙串访问 中查看证书。
三 签名
-
Dog.app 签名
- 命令
// 字符串为证书名称,在 钥匙串访问 中可查看安装的证书 codesign -f -o runtime -s "Developer ID Application: xxxx Ltd. (6LRF78xxxx)" -v Dog.app --deep
- 备注
- 当上述没有-o runtime 参数时,在公证时,碰见以下错误
“The executable does not have the hardened runtime enabled”
- 搜索资料,一种方式是在XCode工程的设置中处理 Enable Hardened Runtime 项;但由于使用的第三方库也有同样报错,并不能解决问题。后在 github 的一个评论中找到签名加上-o runtime 参数的办法,尝试可行。点击此处,见最后一个评论。
- 当上述没有-o runtime 参数时,在公证时,碰见以下错误
- 命令
-
查看签名
-
命令
spctl --verbose=4 --assess --type execute Dog.app
-
输出
// 如下,此时并不是网上所说的accepted
Dog.app: rejected
source=Unnotarized Developer ID
-
-
Dog.dmg 签名
- appdmg 生成 Dog.dmg后,需要也对 Dog.dmg 签名。
- 命令相同,Dog.app 替换为 Dog.dmg。
四 公证
-
官网上对如何公证有以下描述:
For more information about how to use the Xcode UI to upload your software, see Upload a macOS app to be notarized.
For targets other than macOS apps, use the altool command line utility to notarize, as described in Customizing the Notarization Workflow. -
即对 app包可用 Xcode UI 上传进行公证。详见 Upload a macOS app to be notarized。
-
而对于其他,例如 Dog.dmg 可通过 altool 命令行 上传进行公证。详见 Customizing the Notarization Workflow, 里面提供了具体的上传命令:
% xcrun altool --notarize-app --primary-bundle-id "com.example.ote.zip" --username "AC_USERNAME" --password "@keychain:AC_PASSWORD" --asc-provider <ProviderShortname> --file OvernightTextEditor_11.6.8.zip
-
我的使用如下:
# primary-bundle-id : APP ID ,请咨询签名证书创建者 # username : 开发者账号 ,请咨询签名证书创建者 # password : 应用专用密码(登录 appleid.apple.com ,点击 Generate Password,创建一个应用专用密码,这样可以避免暴露真实的密码。),请咨询签名证书创建者 # asc-provider : 证书提供者(ProviderShortname) ,请咨询签名证书创建者 # file : 公证的软件包路径 xcrun altool --notarize-app --primary-bundle-id "6LRF78xxxx.cn.xxxx.Xixxxx" --username "lxxxx@xxxx.cn" --password "ayrs-xxxx-xxxx-tjhf" --asc-provider "6LRF78xxxx" -t osx --file "./Dog.dmg"
-
参数 asc-provider
- 搜索资料,说是通过命令 xcrun altool --list-providers -u “apple id” -p “app password” 获得, 但我执行总报错,后通过 在证书创建的macbook上执行如下命令获得:
security find-identity -p codesigning - 结果为
Developer ID Application: xxxxBeijing)Network Technology Co., Ltd. (6LRF78xxx) // 使用的括号内的 6LRF78xxx
- 搜索资料,说是通过命令 xcrun altool --list-providers -u “apple id” -p “app password” 获得, 但我执行总报错,后通过 在证书创建的macbook上执行如下命令获得:
-
参数 file
- 测试绝对路径或相对路径均可
- 可直接对dmg公证,而不是必须是pkg或者zip
-
输出
// 若出现以下信息,则重新尝试 *** Error: An error occurred saving your changes to the Apple database. This problem may be a transient issue on the Apple side. If the problem persists for more than an hour, please contact your iTunes representative. (1129) // 若出现以下信息,则成功上传 No errors uploading './Dog.dmg'. RequestUUID = cb2524dd-f691-xxxx-acc3-8807exxxx864
-
若上传无错误,将返回RequestUUID, 用于查询公证结果
-
-
查询公证结果
- 命令
xcrun altool --notarization-info cb2524dd-f691-xxxx-acc3-8807exxxx864 --username "lxxxx@xxxx.cn" // 同上 --password "ayrs-xxxx-xxxx-tjhf" // 同上
- 输出
// 若还未处理完毕 No errors getting notarization info. Date: 2020-10-26 07:56:27 +0000 Hash: 13bf499496e371751b127190xxxx489663b890cdfd72c RequestUUID: cb2524dd-f691-xxxx-acc3-8807exxxx864 Status: in progress // 若公证成功 No errors getting notarization info. Date: 2020-10-26 07:56:55 +0000 Hash: 13bf499496e371751b1xxxxc86fd6eddebf489663b890cdfd72c LogFileURL: https://osxapps-ssl.itunes.apple.com/itunes-assets/Enigma124/v4/c7/56/a0/c756a0cf-b58c-1658-1904-d75e5a7e3c0e/developer_log.json?accessKey=1603893616_8033843945181087xxxx2Cdu3YhDOrVYv4%2FEmd8QWqhlKn1s4u92SbQqAR5mPQhMX66pTtSXi9vFQPWzttmQ60aqxxxxNZVr4ZjTJeV9jie%2BVmIKl0B95SXDKHGOuaYiFteW1opHFS%2FxJCw0CvkOG2RYLagtULbzbxxxxQkUgcc%2Fc%3D RequestUUID: cb2524dd-f691-xxxx-acc3-8807exxxx864 Status: success Status Code: 0 Status Message: Package Approve
-
若此时再次验证app签名:
sudo spctl --verbose=4 --assess --type execute Dog.app
输出如下:
Dog.app: accepted // 公证后变为accepted
source=Notarized Developer ID
五 参考
- 整体流程参考 官网 为 app 签名以通过“门禁”验证
- 细节参考 文章 Mac App 签名公证流程