簽署與公證
為每個平台的套件簽署,為 Windows 下載做 Authenticode 簽署,並為 Mac 應用公證。
sign: identity: "Apple Development: you@example.com (ABCDE12345)" # signs the macOS app, else ad hoc profile: assets/AppStore.mobileprovision # signs the IPA keystore: assets/release.p12 # signs APKs, with key_alias certificate: assets/codesign.pfx # signs the Windows app and its installer # widgets_profile: assets/Widgets.mobileprovision # the iOS extension's profile; use a macOS profile for a Mac App Store build # share_profile: assets/Share.mobileprovision # signs the IPA's share extension # clip_profile: assets/Clip.mobileprovision # signs the IPA's App Clip金鑰庫密碼取自環境變數 NSGO_KEYSTORE_PASSWORD 與 NSGO_KEY_PASSWORD。-team 用於簽署 iPhone 封裝檔。-profile、-widgets-profile、-share-profile、-clip-profile 與 -macos-profile 可從命令列分別覆寫主應用程式、小工具擴充功能、分享擴充功能、App Clip 與 Mac App Store 的描述檔。-installer 則可覆寫 Mac Installer Distribution 身分憑證。
簽署 Windows 封裝檔
Section titled “簽署 Windows 封裝檔”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 # the RFC 3161 server that timestamps themsign.timestamp_url 預設使用 DigiCert 的伺服器,設為 none 則不會為簽章加上時間戳記(此情況下簽章將在憑證過期後失效)。若憑證存放在硬體權杖(token)或雲端服務中,則可改用自訂命令進行簽署,其中 %1 代表要簽署的檔案,建置時會對上述每個檔案執行該命令:
sign: sign_command: "signtool sign /fd sha256 /tr http://timestamp.digicert.com /td sha256 /a %1"若該命令回傳成功,但應用程式執行檔、命令輔助程式、PE 資源或安裝程式執行檔仍缺少內嵌的 Authenticode 簽章,build 將會中止並報錯。
安裝程式內部的解除安裝程式會在嵌入前先行簽署,所用的 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 ABCDE12345sign: identity: "Developer ID Application: Example Inc (ABCDE12345)" notarize: hello # the keychain profile above; or -notarize hello接著 build 會以強化執行階段(hardened runtime)進行簽署、提交磁碟映像檔、等待數分鐘取得 Apple 的審核結果,並將公證票券(ticket)裝訂(staple)至磁碟映像檔與應用程式;若遭拒絕則會印出 Apple 的錯誤日誌。在 CI 環境中,可使用 App Store Connect API 金鑰的 .p8 檔案、金鑰 ID 與發行者 ID,透過 NSGO_NOTARY_KEY、NSGO_NOTARY_KEY_ID 與 NSGO_NOTARY_ISSUER 取代鑰匙圈設定檔。除非應用程式主動宣告權限,否則強化執行階段會拒絕存取麥克風、相機、行事曆與位置資訊;只要 apple.info 中包含 NSMicrophoneUsageDescription、NSCameraUsageDescription、行事曆或提醒事項用途說明,或位置用途說明,build 便會自動加上對應權限。