macOS应用Notarization公证机制

GateKeeper - macOS应用安全机制背景介绍

macOS应用程序可以不经过苹果审核就可以发布到任何渠道上供任何人下载,Gatekeeper是苹果专门开发的一款安全软件,用于保证用户安装来自App Store或者拥有开发者签名的应用。用户可以在【系统偏好设置】->【安全性与隐私】->【通用】选择App Store和被认可的开发者。但是Gatekeeper也只能做到最基础的防护,它也有诸多不足。Gatekeeper无法检测到这个应用是否被注入非法代码;被Gatekeeper标为受信任应用程序后,用户也没有什么操作可以取消等等。所以在此基础上,苹果引入了Notarization公证机制。

Notarization - 什么是Notarization

公证机制是在GateKeeper防护上增加的一层扩展,在macOS 10.14.5引入,10.15以后强制要求开发者在发布前将应用上传到苹果服务器进行公证。Notarization不同于iOS的review审核机制,Notarization只是扫描应用程序是否含有恶意代码。验证通过后,Xcode会下载验证票据到归档中,GateKeeper会校验用户下载程序中的票据,来验证该程序是否可被安装。

Important

Beginning in macOS 10.14.5, all new or updated kernel extensions and all software from developers new to distributing with Developer ID must be notarized in order to run. Beginning in macOS 10.15, notarization is required by default for all software.

To make this transition easier and to protect users on macOS Catalina who continue to use older versions of software, we’ve adjusted the notarization prerequisites until January 2020.

如何进行公证

1. 必须拥有开发者证书,用于签名程序;
2. 开启 Hardened Runtime

打开Project editor,选择对应 target -> Capabillites -> 开启 Harened Runtime

The hardened runtime capability is available in Xcode 10 and later on macOS 10.13.6 and later. However, this capability must be tested on macOS 10.14 and later.

3. 选择target进行打包流程;
4. 在Xcode Organizer 窗口选择归档archive,点击右侧栏Distribute App;
5. 选中Developer ID [Distribute directly to customers],点击Next;
5. 选中Upload [send to Apple notary service],点击Next开始签名、上传归档;
6. 上传成功后,等待苹果验证并在Organizer窗口检查archive状态;
  • Processing: The upload is successful and the app is being processed.

  • Upload failed: The upload failed.

  • Ready to distribute: The processing is complete and you can now export the notarized.

  • Rejected: The archive is invalid or failed security checks.

7. 公证成功后在Organizer 窗口右侧栏会多出一个Export Notarized App按钮,点击导出app

Tips

1. 如何查看app是否公证成功?
xcrun stapler validate /path/to/bundle.app
2. Notarization如何自动化?

参考Customizing the Notarization Workflow

3. 已经开启Hardened Runtime,上传归档还是提示 Hardened Runtime is not enabled.
"***" must be rebuilt with support for the Hardened Runtime. Enable the Hardened Runtime capability in the project editor, then test your app, rebuild your archive, and upload again.

如果本地项目已经开启了Hardened Runtime功能,这个基本上是第三方库或插件引起的,可以根据提示找到具体的第三方库,替换成最新的包或者重新编译开源库即可。

4. 如何在Mac上测试Notarization?

目前也没找到系统提供的有效的方法,但是可以通过新建一个mac用户来实现首次打开app验证Notarization。

你可能感兴趣的:(macOS应用Notarization公证机制)