Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,25 @@ jobs:
python3 platforms/macos/Installer/build.py
python3 platforms/macos/Uninstaller/build.py

- name: Sign and notarize the updater and the uninstaller
# 顺序有讲究(ADR-391):载荷是**复制**的二进制,必须在更新程序签名+公证+装订之后才复制;
# 否则安装器里会带着一份签名无效/无时间戳的副本,公证直接判 Invalid。
env:
MACOS_CERTIFICATE_P12_BASE64: ${{ secrets.APPLE_CERTIFICATE_P12_BASE64 }}
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_P12_PASSWORD }}
MACOS_SIGNING_IDENTITY: ${{ vars.MACOS_SIGNING_IDENTITY }}
ASC_API_KEY_P8: ${{ secrets.APPLE_ASC_API_KEY }}
ASC_API_KEY_ID: ${{ secrets.APPLE_ASC_API_KEY_ID }}
ASC_API_ISSUER_ID: ${{ secrets.APPLE_ASC_ISSUER_ID }}
run: |
set -euo pipefail
bash packaging/macos/ci-sign.sh \
--app platforms/macos/build/website-updater/LampyrisUpdateCheck.app \
--also platforms/macos/build/uninstaller/LampyrisUninstaller.app

- name: Stage the installer payload
# ADR-391:载荷必须在签名**之前**放进安装器 bundle,否则签名封印会把后加的
# 文件当成篡改。DMG 顶层因此只剩「安装萤火虫」「卸载萤火虫」「说明」三样。
# 主机来自验收 ZIP(已签名+公证),更新程序来自上一步(已签名+公证+装订);
# 脚本会拒绝缺票据的载荷,避免再把未签名副本塞进安装器。
run: |
set -euo pipefail
zip="$(grep -E 'Lampyris-.*-universal\.zip$' release-assets.txt | head -1)"
Expand All @@ -129,7 +145,7 @@ jobs:
--out "platforms/macos/build/installer-staged/安装萤火虫.app"
rm -rf "$work"

- name: Sign and notarize the updater app and the DMG apps
- name: Sign and notarize the DMG installer app
env:
MACOS_CERTIFICATE_P12_BASE64: ${{ secrets.APPLE_CERTIFICATE_P12_BASE64 }}
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_P12_PASSWORD }}
Expand All @@ -139,10 +155,7 @@ jobs:
ASC_API_ISSUER_ID: ${{ secrets.APPLE_ASC_ISSUER_ID }}
run: |
set -euo pipefail
bash packaging/macos/ci-sign.sh \
--app platforms/macos/build/website-updater/LampyrisUpdateCheck.app \
--also "platforms/macos/build/installer-staged/安装萤火虫.app" \
--also platforms/macos/build/uninstaller/LampyrisUninstaller.app
bash packaging/macos/ci-sign.sh --app "platforms/macos/build/installer-staged/安装萤火虫.app"

- name: Package the updater app as a release asset
run: |
Expand Down
6 changes: 4 additions & 2 deletions docs/releases/1.4.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
1. **DMG 顶层只留三样**:`安装萤火虫.app`、`卸载萤火虫.app`、`安装与卸载说明.txt`。
2. **输入法本体与更新程序改为安装器载荷**:`安装萤火虫.app/Contents/Resources/Payload/{Lampyris.app,LampyrisUpdateCheck.app}`,
由 `packaging/macos/stage-installer-payload.sh` 装入;`make-dmg.sh` 在缺载荷或标识不符时**拒绝出包**。
3. **载荷在签名之前装入**:`codesign` 会封印 bundle 内的文件,签名后再塞载荷会让安装器自己的签名失效
(干净机器上会被 Gatekeeper 拒绝启动)。发布流程因此调整为「装载荷 → 签安装器/卸载器/更新程序(同一次公证提交)→ 打 DMG → 签/公证 DMG」。
3. **顺序两头卡死**:载荷要在**自身签名+公证+装订之后**才复制(否则安装器里是签名无效/无时间戳的副本,
公证判 `Invalid`),又要在**安装器签名之前**装进去(`codesign` 封印 bundle 内文件,后塞会让安装器签名失效)。
发布流程因此是「签更新程序+卸载器 → 装载荷 → 签安装器 → 打 DMG → 签/公证 DMG」,两次公证提交。
`stage-installer-payload.sh` 会拒绝缺票据或签名无效的载荷(这次就是它先在场能提早发现的那类错误)。
4. **顺带补上一个旧缺口**:安装器与卸载器现在也各自 staple(此前只有主应用与更新程序有公证票据)。
5. **仍然可审计**:Finder「显示包内容」能看到同一份已签名、已公证的 app;说明文件写清了位置与原因。
6. ZIP 渠道不变(`Lampyris-<v>-universal/` 内仍是 `Lampyris.app` + `LampyrisUpdateCheck.app` + `scripts/`),`install.sh` 不改。
Expand Down
11 changes: 8 additions & 3 deletions docs/决策记录.md
Original file line number Diff line number Diff line change
Expand Up @@ -4770,9 +4770,14 @@
2. 输入法本体与更新程序作为**载荷**放进 `安装萤火虫.app/Contents/Resources/Payload/`
(`Lampyris.app` + `LampyrisUpdateCheck.app`),由新脚本 `packaging/macos/stage-installer-payload.sh` 装入,
`make-dmg.sh` 只接受"已含载荷"的安装器并在缺载荷/标识不符时拒绝出包。
3. **载荷必须在签名之前装进去**:`codesign` 会封印 bundle 内所有文件,签名后再塞载荷会让安装器自己的签名失效
(干净机器上 Gatekeeper 直接拒绝启动,正是 ADR-390 刚修的那类故障)。因此发布流程改为
「下载验收 ZIP → 装载荷 → 签安装器/卸载器/更新程序(同一次公证提交)→ 打 DMG → 签/公证 DMG」。
3. **顺序是两头卡死的**(2026-11-23 第一次尝试就在第二步上挂了):载荷是**复制的二进制**——
既要在**载荷本身签名+公证+装订之后**才复制(否则安装器里是一份签名无效/无时间戳/无 hardened runtime 的副本,
公证直接判 `Invalid`,Apple 日志原话是 "The signature does not include a secure timestamp"),
又要在**安装器签名之前**装进去(`codesign` 封印 bundle 内所有文件,签名后再塞会让安装器签名失效,
Gatekeeper 在干净机器上直接拒绝启动)。于是发布流程定为:
① 签+公证+装订更新程序与卸载器 → ② 把(验收 ZIP 里的主机)+(已装订的更新程序)装成载荷 →
③ 签+公证+装订安装器(封印载荷)→ ④ 打 DMG → ⑤ 签+公证+装订 DMG。两次公证提交,顺序不能动。
`stage-installer-payload.sh` 会在载荷缺票据或签名无效时直接拒绝(本机预览需显式 `--unsigned-ok`)。
顺带补上原缺口:安装器与卸载器现在也各自 staple(此前只有主应用与更新程序有票据)。
4. 仍然**可审计**:Finder「显示包内容」能看到同一份已签名、已公证的 app;说明文件写清位置与原因。
5. ZIP 渠道不变(`Lampyris-<v>-universal/` 里仍是 `Lampyris.app` + `LampyrisUpdateCheck.app` + `scripts/`),
Expand Down
8 changes: 5 additions & 3 deletions docs/更新发布流程.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ drill 目录不是正式升级来源,不得创建 tag/Release、不得改生
## 3.5 更新程序的安装与定位(ADR-294/295)

**DMG 布局(ADR-391)**:DMG 顶层只有 `安装萤火虫.app`、`卸载萤火虫.app`、`安装与卸载说明.txt`;
输入法本体与更新程序作为载荷在 `安装萤火虫.app/Contents/Resources/Payload/`(签名前装入,随安装器一起公证)。
发布顺序因此是:下载验收 ZIP → `packaging/macos/stage-installer-payload.sh` 装载荷 →
`ci-sign.sh --app <更新程序> --also <安装器> --also <卸载器>` → `make-dmg.sh`(只接受已含载荷的安装器)→ `ci-sign.sh --dmg`。
输入法本体与更新程序作为载荷在 `安装萤火虫.app/Contents/Resources/Payload/`,顺序两头卡死:
载荷本身要先签名+公证+装订(否则复制出来的副本公证判 `Invalid`),安装器要在载荷装好后再签名(否则封印失效)。
发布顺序因此是:① `ci-sign.sh --app <更新程序> --also <卸载器>` → ② 下载验收 ZIP →
`packaging/macos/stage-installer-payload.sh` 装载荷 → ③ `ci-sign.sh --app <安装器>` →
④ `make-dmg.sh`(只接受已含载荷的安装器)→ ⑤ `ci-sign.sh --dmg`。两次公证提交,顺序不能动。

**DMG 与 ZIP 都自带 `LampyrisUpdateCheck.app`**(`prepare.sh` 在发布模式下强制要求它已签名并公证):`安装萤火虫.app` 与 `scripts/install.sh` 都会在装完输入法后把它装到 `~/Applications/LampyrisUpdateCheck.app`(校验 → staging → 旧版备份 → 替换 → 落地复验 → 失败回滚),并清理历史手工改名的 `Lampyris Update.app`。因此无论走哪个入口,装完都能用菜单「检查更新…」。

Expand Down
16 changes: 15 additions & 1 deletion packaging/macos/stage-installer-payload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ INSTALLER=""
APP=""
UPDATER=""
OUT=""
UNSIGNED_OK=0
while [ "$#" -gt 0 ]; do
case "$1" in
--installer) [ "$#" -ge 2 ] || exit 2; INSTALLER="$2"; shift 2 ;;
--app) [ "$#" -ge 2 ] || exit 2; APP="$2"; shift 2 ;;
--updater) [ "$#" -ge 2 ] || exit 2; UPDATER="$2"; shift 2 ;;
--out) [ "$#" -ge 2 ] || exit 2; OUT="$2"; shift 2 ;;
*) echo "用法:$0 --installer <安装萤火虫.app> --app <Lampyris.app> --updater <LampyrisUpdateCheck.app> --out <安装萤火虫.app>" >&2; exit 2 ;;
--unsigned-ok) UNSIGNED_OK=1; shift ;;
*) echo "用法:$0 --installer <安装萤火虫.app> --app <Lampyris.app> --updater <LampyrisUpdateCheck.app> --out <安装萤火虫.app> [--unsigned-ok]" >&2; exit 2 ;;
esac
done
[ -d "$INSTALLER" ] && [ ! -L "$INSTALLER" ] || { echo "安装器 app 不存在或为符号链接" >&2; exit 1; }
Expand All @@ -34,6 +36,18 @@ bundle_id() { /usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$1/Content
[ "$(bundle_id "$APP")" = cn.jokerhub.inputmethod.Lampyris ] || { echo "输入法标识不符" >&2; exit 1; }
[ "$(bundle_id "$UPDATER")" = cn.jokerhub.Lampyris.WebsiteUpdateCheck ] || { echo "更新程序标识不符" >&2; exit 1; }

# 载荷必须是**已签名并公证**的最终产物:ditto 复制的是二进制本身,如果拿未签名(或签名后又被
# 重签)的副本当载荷,安装器里就会出现签名无效/缺时间戳/无 hardened runtime 的可执行文件,
# 公证会直接判 Invalid(2026-11-23 v1.4.2 就是这样挂的)。本机离线预览可加 --unsigned-ok。
if [ "${UNSIGNED_OK}" = "0" ]; then
for bundle in "$APP" "$UPDATER"; do
[ -s "$bundle/Contents/CodeResources" ] || {
echo "载荷缺少公证票据:${bundle}(先在发布流程里签名+公证,或本机预览加 --unsigned-ok)" >&2; exit 1; }
codesign --verify --strict "$bundle" 2>/dev/null || {
echo "载荷签名无效:${bundle}" >&2; exit 1; }
done
fi

PAYLOAD="$OUT/Contents/Resources/Payload"
rm -rf "$OUT"
ditto "$INSTALLER" "$OUT"
Expand Down
35 changes: 30 additions & 5 deletions packaging/macos/tests/test-dmg-updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,28 @@ def stage_payload(self, work, payload_app=None, payload_updater=None):
result = subprocess.run(
['bash', str(ROOT / 'packaging/macos/stage-installer-payload.sh'),
'--installer', str(installer), '--app', str(app), '--updater', str(updater),
'--out', str(staged)], capture_output=True, text=True, check=False, timeout=120)
'--out', str(staged), '--unsigned-ok'],
capture_output=True, text=True, check=False, timeout=120)
return staged, result

def test_staging_refuses_unsigned_payloads(self):
"""载荷是复制的二进制:未签名/未装订的副本会让公证判 Invalid(v1.4.2 的真实故障)。"""
with tempfile.TemporaryDirectory() as directory:
work = pathlib.Path(directory)
installer = work / '安装.app'
fake_app(installer, 'cn.jokerhub.Lampyris.Installer', executable='LampyrisInstaller')
app, updater = work / 'Lampyris.app', work / UPDATER_NAME
fake_app(app, 'cn.jokerhub.inputmethod.Lampyris')
fake_app(updater, UPDATER_ID, executable='LampyrisUpdateCheck')
staged = work / 'staged.app'
result = subprocess.run(
['bash', str(ROOT / 'packaging/macos/stage-installer-payload.sh'),
'--installer', str(installer), '--app', str(app), '--updater', str(updater),
'--out', str(staged)], capture_output=True, text=True, check=False, timeout=120)
self.assertNotEqual(result.returncode, 0)
self.assertIn('缺少公证票据', result.stderr)
self.assertFalse(staged.exists())

def test_staging_puts_both_payloads_inside_the_installer(self):
with tempfile.TemporaryDirectory() as directory:
work = pathlib.Path(directory)
Expand Down Expand Up @@ -108,13 +127,19 @@ def test_dmg_top_level_holds_only_the_three_items(self):
self.assertNotIn('"$STAGE/' + UPDATER_NAME + '"', builder)
self.assertIn('Contents/Resources/Payload', builder)

def test_workflow_stages_payload_before_signing(self):
def test_workflow_orders_signing_staging_and_resigning(self):
workflow = (ROOT / '.github/workflows/release.yml').read_text()
updater_signed = workflow.index(
'--app platforms/macos/build/website-updater/LampyrisUpdateCheck.app')
stage = workflow.index('stage-installer-payload.sh')
sign = workflow.index('--also "platforms/macos/build/installer-staged/安装萤火虫.app"')
self.assertLess(stage, sign, '载荷必须在签名之前装进安装器(否则签名失效)')
self.assertIn('--also "platforms/macos/build/installer-staged/安装萤火虫.app"', workflow)
installer_signed = workflow.index(
'--app "platforms/macos/build/installer-staged/安装萤火虫.app"')
# 载荷是复制品:先签更新程序 → 再装载荷 → 最后签安装器(把载荷封进安装器签名)。
self.assertLess(updater_signed, stage)
self.assertLess(stage, installer_signed)
self.assertIn('--installer "platforms/macos/build/installer-staged/安装萤火虫.app"', workflow)
# 正式流程不得用 --unsigned-ok 绕过票据检查。
self.assertNotIn('--unsigned-ok', workflow)

def test_installer_reads_the_payload_inside_its_bundle(self):
installer = (ROOT / 'platforms/macos/Installer/Sources/LampyrisInstaller/main.swift').read_text()
Expand Down
Loading