跳转到内容

签名与公证

为每个平台的包签名,为 Windows 下载做 Authenticode 签名,并为 Mac 应用公证。

sign:
identity: "Apple Development: you@example.com (ABCDE12345)" # 为 macOS 应用签名,省略时为临时签名
profile: assets/AppStore.mobileprovision # 为 iOS、tvOS 或 watchOS 壳 IPA 签名
keystore: assets/release.p12 # 与 key_alias 一起为 APK 签名
certificate: assets/codesign.pfx # 为 Windows 应用及其安装包签名
# watch_profile: assets/Watch.mobileprovision # 为独立手表 IPA 中的 <id>.watchkitapp 签名(通配符描述文件时可省略)
# widgets_profile: assets/Widgets.mobileprovision # iOS 扩展的描述文件;Mac App Store 构建使用 macOS 描述文件
# share_profile: assets/Share.mobileprovision # 为 IPA 中的分享扩展签名
# clip_profile: assets/Clip.mobileprovision # 为 IPA 中的轻 App 签名

密钥库的密码来自 NSGO_KEYSTORE_PASSWORD 和 NSGO_KEY_PASSWORD。-team 用于为 iPhone 包签名。命令行可用 -profile、-watch-profile、-widgets-profile、-share-profile、-clip-profile 和 -macos-profile 替换应用、手表应用、小组件扩展、分享扩展、轻 App 和 Mac App Store 的描述文件,-installer 替换 Mac Installer Distribution 身份。

对于 -target watchos,nsgo build 会保留用于 -run 真机安装的独立 <name>.app,同时写出 <name>.ipa(并复制到 dist/releases/<slug>-<version>-watchos.ipa),内含 Xcode 的 watch-only iOS 壳(ITSWatchOnlyContainer)、嵌套的手表应用(<id>.watchkitapp)和 WatchKitSupport2/WK。上传 App Store Connect 时,为 <id> 设置 sign.profile 并为 <id>.watchkitapp 设置同一团队的 sign.watch_profile(或使用同时覆盖两者的通配符 sign.profile),构建会校验两份描述文件并按由内向外的顺序签名。

Authenticode 标识 Windows 下载的发布者;SmartScreen 另行检查其信誉。sign.certificate 是一个 .pfx,为可执行文件、命令行伴随程序、应用资源里自带的程序与库、安装包和其中的卸载器、以及 Store 渠道构建的 MSIX 签名;密码来自 NSGO_CERTIFICATE_PASSWORD。签名在 Go 中生成,与 signtool 的结果相同,因此在 Mac 上不需要 Windows SDK:

sign:
certificate: assets/codesign.pfx
timestamp_url: http://timestamp.digicert.com # 为签名加时间戳的 RFC 3161 服务器

sign.timestamp_url 默认为 DigiCert 的服务器;设为 none 则不加时间戳,签名随证书到期而失效。证书在硬件令牌或云服务中时,改用一条命令签名,%1 是待签文件,build 对上面每个文件都运行它:

sign:
sign_command: "signtool sign /fd sha256 /tr http://timestamp.digicert.com /td sha256 /a %1"

build 会检查命令留下的嵌入式 Authenticode 签名:即使命令成功退出,只要应用可执行文件、命令行伴随程序、PE 资源或安装程序仍未签名,构建就会停止。

安装包内的卸载器在嵌入前签名,与应用和安装程序使用同一 sign.certificate 或 sign.sign_command。命令行可用 -certificate、-sign-command 和 -timestamp-url 指定这些值。

经 Apple 公证的应用在 Mac 上下载后打开时不会出现 Gatekeeper 警告。用 Developer ID 签名,并指定 notarytool 存在钥匙串中的凭据:

xcrun notarytool store-credentials hello --apple-id you@example.com --team-id ABCDE12345
sign:
identity: "Developer ID Application: Example Inc (ABCDE12345)"
notarize: hello # 上面的钥匙串配置;也可用 -notarize hello

之后 build 会以强化运行时签名,提交磁盘映像,等待 Apple 的结果(通常几分钟),并把公证票据装订到磁盘映像和应用上;被拒时会打印 Apple 的日志。在 CI 中可用 NSGO_NOTARY_KEY、NSGO_NOTARY_KEY_ID 和 NSGO_NOTARY_ISSUER(App Store Connect API 密钥的 .p8 文件、ID 和 issuer)代替钥匙串配置。强化运行时默认禁止使用麦克风、摄像头、日历和定位,apple.info 含 NSMicrophoneUsageDescription、NSCameraUsageDescription,或日历、提醒事项、定位的用途说明时,build 会为应用声明相应权限。