From 39cac8b9646382d0130767b153725f0b24a39b5d Mon Sep 17 00:00:00 2001 From: EMRG Evolution Date: Thu, 6 Aug 2026 13:35:37 +0800 Subject: [PATCH] =?UTF-8?q?emrg:=20=E4=BF=AE=E5=A4=8D=20pkg=20=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=E8=AF=81=E4=B9=A6=E6=A0=A1=E9=AA=8C=20=E2=80=94=20?= =?UTF-8?q?=E9=9C=80=E8=A6=81=20Developer=20ID=20Installer=20=E8=AF=81?= =?UTF-8?q?=E4=B9=A6=EF=BC=88=E7=AC=AC=207=20=E6=AC=A1=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=20productsign=20cryptic=20=E9=94=99=E8=AF=AF=E6=A0=B9=E5=9B=A0?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/README.md | 28 ++++++++++++++++++++++++++++ .github/workflows/build-release.yml | 20 +++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 788f909a..f824bb84 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -51,6 +51,34 @@ security import 你的证书.p12 -k /tmp/test.keychain -P 密码 base64 < 含私钥的证书.p12 # 输出结果整段复制为 MACOS_SIGNING_P12_BASE64 ``` +## ⚠️ 需要两种证书:Developer ID Application + Developer ID Installer(v0.2.7 第 7 次构建教训) + +**现象**:第 7 次构建(#461 修复私钥校验后)在 `Sign pkg` 步骤报: +``` +productsign: error: Could not find appropriate signing identity for "***". +An installer signing identity (not an application signing identity) is required for signing flat-style products. +``` + +**根因**:macOS 代码签名需要**两种不同证书**,缺一不可: +| 证书类型 | 用途 | 产物 | +|---|---|---| +| `Developer ID Application` | 签名 .app(electron-builder codesign) | GUI 应用本体 | +| `Developer ID Installer` | 签名 .pkg(productsign) | 安装包 | + +p12 若只有 Application 证书:.app 签名成功,但 productsign 报 cryptic 错误——CI 已在 import 步骤加显式校验(#462),缺失时明确报错。 + +**获取 Installer 证书**(developer.apple.com → Certificates → + → Software → **Developer ID Installer**): +1. 在开发者门户创建 Developer ID Installer 证书(与 Application 是两张不同的证书,需分别申请) +2. 下载 .cer 双击导入钥匙串 +3. 导出 p12 时**同时勾选两张证书**(或分别导出后合并)——`security export -t identities` 会导出所有 identity + +**验证 p12 含两种证书**: +```bash +security import 你的证书.p12 -k /tmp/test.keychain -P 密码 +security find-certificate -c "Developer ID Installer" -a /tmp/test.keychain # 必须能找到 +security find-certificate -c "Developer ID Application" -a /tmp/test.keychain # 必须能找到 +``` + ## 降级行为 - **Secret 未配置**(空字符串):对应步骤跳过,构建不失败(不签名、不公证)。 diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index f43d21e4..e4389220 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -80,6 +80,16 @@ jobs: echo "::error::MACOS_SIGNING_P12_BASE64 未包含可签名私钥(security import 仅导入证书链)。请从 Keychain Access 导出含私钥的 p12(证书右键 → 导出 → 勾选\"包含私钥\"),重新 base64 后更新 GitHub Secret。import 输出:${IMPORT_OUTPUT}" exit 1 fi + # pkg 签名证书存在性校验(v0.2.7 第 7 次构建根因:p12 只有 Developer ID + # Application 证书——签 .app 成功,但 productsign 签 pkg 需要独立的 + # Developer ID Installer 证书,缺失报 "An installer signing identity (not + # an application signing identity) is required" 的 cryptic 错误)。 + # 两种证书在 developer.apple.com → Certificates 分别创建,导出 p12 时 + # 需同时勾选(或分别导出后合并)。 + if ! security find-certificate -c "Developer ID Installer" -a /tmp/ci.keychain >/dev/null 2>&1; then + echo "::error::MACOS_SIGNING_P12_BASE64 缺少 Developer ID Installer 证书(pkg 签名必需)。Developer ID Application 只能签 .app,productsign 签 pkg 需要独立的 Developer ID Installer 证书。请在 developer.apple.com → Certificates 创建 Developer ID Installer(与 Application 是两张不同证书),连同私钥一起导出 p12 后更新 GitHub Secret。" + exit 1 + fi # set-key-partition-list 与 electron-builder macCodeSign.js 完全一致: # security set-key-partition-list -S apple-tool:,apple: -s -k # -s = Match keys that can sign(必须显式提供才能定位私钥项目); @@ -152,7 +162,15 @@ jobs: run: | PKG="$(find dist/artifacts -maxdepth 1 -name 'EMRG-*-macos-*.pkg' | head -1)" if [ -z "$PKG" ]; then echo "no pkg found, skipping"; exit 0; fi - productsign --sign "$MACOS_SIGNING_IDENTITY" "$PKG" "${PKG}.signed" + # productsign 需要 Developer ID Installer 证书(非 Application)。 + # 从已导入的临时 keychain 自动探测 Installer 身份,避免使用 + # MACOS_SIGNING_IDENTITY(Application)导致 productsign 报 cryptic 错误。 + INSTALLER_ID="$(security find-identity -v -p codesigning /tmp/ci.keychain | grep -o 'Developer ID Installer: [^"]*' | head -1)" + if [ -z "$INSTALLER_ID" ]; then + echo "::error::临时 keychain 未找到 Developer ID Installer 身份(pkg 签名必需)。请检查 p12 是否包含 Developer ID Installer 证书。" + exit 1 + fi + productsign --sign "$INSTALLER_ID" "$PKG" "${PKG}.signed" mv "${PKG}.signed" "$PKG" # P3 验证:证书存在时签名必须成功(rant 验收:pkgutil 显示 signed by Developer ID) pkgutil --check-signature "$PKG"