Open source CapCut alternative.
TypeScript
feat(build): sign and notarize bundled tools for production
David Le5e687ec61f9d
diff --git a/.github/workflows/publish-bundled-tools.yml b/.github/workflows/publish-bundled-tools.ymlindex fce62854..6e01757d 100644--- a/.github/workflows/publish-bundled-tools.yml+++ b/.github/workflows/publish-bundled-tools.yml@@ -55,9 +55,44 @@ jobs:path: vendor/donkey-toolskey: donkey-tools-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/fetch-bundled-tools.sh', 'tools/pdf-fill/main.swift') }}+ # Import the Developer ID cert into a throwaway keychain and stage the notary API key, so the tools+ # are production-signed + notarized. Absent the secrets this no-ops to ad-hoc signing (still runnable,+ # but flagged not-for-distribution), so the workflow stays green before signing is configured.+ - name: Set up Developer ID signing+ id: signing+ env:+ CERT_P12: ${{ secrets.DONKEY_DEVELOPER_ID_CERT_P12 }}+ CERT_PASSWORD: ${{ secrets.DONKEY_DEVELOPER_ID_CERT_PASSWORD }}+ SIGN_IDENTITY: ${{ secrets.DONKEY_TOOLS_SIGN_IDENTITY }}+ NOTARY_KEY_P8: ${{ secrets.DONKEY_NOTARY_KEY_P8 }}+ run: |+ if [ -z "$CERT_P12" ] || [ -z "$SIGN_IDENTITY" ]; then+ echo "::warning::No Developer ID secrets; bundled tools will be ad-hoc signed (not for public distribution)."+ echo "identity=-" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ keychain="$RUNNER_TEMP/donkey-signing.keychain-db"+ kpw="$(uuidgen)"+ security create-keychain -p "$kpw" "$keychain"+ security set-keychain-settings -lut 21600 "$keychain"+ security unlock-keychain -p "$kpw" "$keychain"+ echo "$CERT_P12" | base64 --decode > "$RUNNER_TEMP/cert.p12"+ security import "$RUNNER_TEMP/cert.p12" -k "$keychain" -P "$CERT_PASSWORD" -T /usr/bin/codesign+ security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$kpw" "$keychain" >/dev/null+ security list-keychains -d user -s "$keychain" $(security list-keychains -d user | sed -e 's/"//g')+ rm -f "$RUNNER_TEMP/cert.p12"+ if [ -n "$NOTARY_KEY_P8" ]; then+ echo "$NOTARY_KEY_P8" | base64 --decode > "$RUNNER_TEMP/notary.p8"+ fi+ echo "identity=$SIGN_IDENTITY" >> "$GITHUB_OUTPUT"+- name: Build and publish the tools bundleenv:GH_TOKEN: ${{ github.token }}+ DONKEY_TOOLS_SIGN_IDENTITY: ${{ steps.signing.outputs.identity }}+ DONKEY_NOTARY_KEY_P8: ${{ runner.temp }}/notary.p8+ DONKEY_NOTARY_KEY_ID: ${{ secrets.DONKEY_NOTARY_KEY_ID }}+ DONKEY_NOTARY_ISSUER_ID: ${{ secrets.DONKEY_NOTARY_ISSUER_ID }}run: ./scripts/publish-bundled-tools.sh "${{ steps.ver.outputs.version }}"- name: Commit the refreshed manifestdiff --git a/docs/guides/releasing-donkey.md b/docs/guides/releasing-donkey.mdindex 4d342bc4..54b33e09 100644--- a/docs/guides/releasing-donkey.md+++ b/docs/guides/releasing-donkey.md@@ -43,6 +43,32 @@ updates the numeric GitHub Release with the DMG and checksum, updateschanges, marks the release as GitHub's latest, moves the alias tags, andprunes releases beyond the latest 10.+## Bundled Tools++The capability skills (media, pdf) run CLI tools — `ffmpeg`, `yt-dlp`, and a few+others — that the app downloads on first launch instead of baking into the app+download. The `Publish Bundled Tools` workflow builds them from source on an+arm64 runner, signs and notarizes them, uploads the bundle as a GitHub release+asset, and commits the refreshed `bundled-tools.json` (the manifest the app reads+to know what to fetch). It runs on demand and whenever the tools recipe changes.++Every tool is re-signed during the build: relocating their bundled libraries+invalidates the original signature, and macOS will not run an unsigned binary on+Apple Silicon. Without the secrets below the tools are only ad-hoc signed — fine+for local development, not for distribution. Set these repository secrets to+produce a signed, notarized bundle:++- `DONKEY_DEVELOPER_ID_CERT_P12` / `DONKEY_DEVELOPER_ID_CERT_PASSWORD` — the+ Developer ID Application certificate (base64-encoded `.p12`) and its password.+- `DONKEY_TOOLS_SIGN_IDENTITY` — the identity to sign with, e.g.+ `Developer ID Application: Your Name (TEAMID)`.+- `DONKEY_NOTARY_KEY_P8` (base64 App Store Connect API key `.p8`),+ `DONKEY_NOTARY_KEY_ID`, `DONKEY_NOTARY_ISSUER_ID` — the notarization credentials.++Standalone CLI binaries cannot be stapled (only app/dmg/pkg bundles can), so+notarization here is the online proof that the Developer ID signature is good;+the signature itself is what lets the downloaded tools run.+## One-Time Sparkle SetupGenerate one Sparkle EdDSA signing keypair on a trusted Mac:diff --git a/scripts/fetch-bundled-tools.sh b/scripts/fetch-bundled-tools.shindex 6504b4b4..4fd7cb94 100755--- a/scripts/fetch-bundled-tools.sh+++ b/scripts/fetch-bundled-tools.sh@@ -243,6 +243,12 @@ elsefail "exiftool" "download failed"fi+# dylibbundler invalidated each binary's signature when it rewrote install names, and an+# unsigned Mach-O is killed on exec on Apple Silicon — so (re)sign before the tools are used.+# Ad-hoc by default; publish-bundled-tools.sh sets a Developer ID identity for releases.+log "Signing"+"$SCRIPT_DIR/sign-bundled-tools.sh" "$VENDOR_DIR"+log "Summary"printf '%s\n' "${STATUS[@]}"echodiff --git a/scripts/publish-bundled-tools.sh b/scripts/publish-bundled-tools.shindex 3c9bbe84..0a791f85 100755--- a/scripts/publish-bundled-tools.sh+++ b/scripts/publish-bundled-tools.sh@@ -33,9 +33,39 @@ for t in "${MANDATORY_TOOLS[@]}"; do[ -x "$VENDOR_DIR/$t" ] || { echo "FATAL: $t missing from $VENDOR_DIR after build" >&2; exit 1; }done-# NOTE: for public distribution the binaries should be Developer ID-signed and the tarball notarized here,-# or Gatekeeper will block first launch of the downloaded tools. Left as a deliberate follow-up; the-# checksum in the manifest already guarantees integrity of the download.+# Developer ID signing happened inside the build (fetch-bundled-tools.sh runs sign-bundled-tools.sh with+# whatever DONKEY_TOOLS_SIGN_IDENTITY is set). Notarize those signed binaries so Apple validates them and+# Gatekeeper trusts them. Bare CLI binaries can't be stapled (only .app/.dmg/.pkg can), so Gatekeeper does+# an online check; for the app-downloaded, un-quarantined tools the Developer ID signature is what counts,+# and notarization is the proof that signature is good. Skipped (with a warning) when only ad-hoc signed.+notarize_bundle() {+ if [ "${DONKEY_TOOLS_SIGN_IDENTITY:--}" = "-" ]; then+ echo "Warning: tools are only ad-hoc signed (no DONKEY_TOOLS_SIGN_IDENTITY); NOT for public distribution." >&2+ return 0+ fi+ local zip="$RUNNER_TEMP_DIR/donkey-tools-notarize.zip"+ rm -f "$zip"+ /usr/bin/ditto -c -k --keepParent "$VENDOR_DIR" "$zip"+ if [ -f "${DONKEY_NOTARY_KEY_P8:-/nonexistent}" ] && [ -n "${DONKEY_NOTARY_KEY_ID:-}" ] && [ -n "${DONKEY_NOTARY_ISSUER_ID:-}" ]; then+ echo "==> Notarizing with App Store Connect API key"+ xcrun notarytool submit "$zip" \+ --key "$DONKEY_NOTARY_KEY_P8" --key-id "$DONKEY_NOTARY_KEY_ID" --issuer "$DONKEY_NOTARY_ISSUER_ID" --wait+ elif [ -n "${DONKEY_NOTARY_PROFILE:-}" ]; then+ echo "==> Notarizing with keychain profile $DONKEY_NOTARY_PROFILE"+ xcrun notarytool submit "$zip" --keychain-profile "$DONKEY_NOTARY_PROFILE" --wait+ elif [ -n "${DONKEY_NOTARY_APPLE_ID:-}" ] && [ -n "${DONKEY_NOTARY_TEAM_ID:-}" ] && [ -n "${DONKEY_NOTARY_PASSWORD:-}" ]; then+ echo "==> Notarizing with Apple ID $DONKEY_NOTARY_APPLE_ID"+ xcrun notarytool submit "$zip" \+ --apple-id "$DONKEY_NOTARY_APPLE_ID" --team-id "$DONKEY_NOTARY_TEAM_ID" --password "$DONKEY_NOTARY_PASSWORD" --wait+ else+ echo "FATAL: DONKEY_TOOLS_SIGN_IDENTITY is set but no notary credentials were provided." >&2+ exit 1+ fi+ rm -f "$zip"+}++RUNNER_TEMP_DIR="${RUNNER_TEMP:-/tmp}"+notarize_bundleecho "==> Packaging $ASSET (bundle contents at archive root)"rm -f "$OUT"diff --git a/scripts/sign-bundled-tools.sh b/scripts/sign-bundled-tools.shnew file mode 100755index 00000000..48437eba--- /dev/null+++ b/scripts/sign-bundled-tools.sh@@ -0,0 +1,62 @@+#!/usr/bin/env bash+#+# Code-signs every Mach-O in a bundled-tools directory (the binaries + their @loader_path dylibs).+# REQUIRED, not cosmetic: dylibbundler rewrites install names, which invalidates any existing signature,+# and the Apple Silicon kernel kills an unsigned/invalidly-signed Mach-O on exec. So the vendored tools+# must be (re)signed or they won't run on the user's Mac.+#+# Identity comes from DONKEY_TOOLS_SIGN_IDENTITY:+# "-" (default) ad-hoc — runs locally and on any arm64 Mac for non-quarantined files (dev).+# "Developer ID ..." real identity + hardened runtime + secure timestamp (production); pair with+# notarization (see publish-bundled-tools.sh) for distribution.+#+# Usage: scripts/sign-bundled-tools.sh [vendor-dir] (default: vendor/donkey-tools)+set -uo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"+VENDOR_DIR="${1:-$ROOT_DIR/vendor/donkey-tools}"+IDENTITY="${DONKEY_TOOLS_SIGN_IDENTITY:--}"++if [ ! -d "$VENDOR_DIR" ]; then+ echo "sign-bundled-tools: $VENDOR_DIR does not exist" >&2+ exit 1+fi++sign_opts=(--force --sign "$IDENTITY")+real_identity=false+if [ "$IDENTITY" != "-" ]; then+ # Hardened runtime + secure timestamp are required for notarization to accept the binaries.+ sign_opts+=(--options runtime --timestamp)+ real_identity=true+fi++is_macho() { file -b "$1" 2>/dev/null | grep -q "Mach-O"; }++# A signing failure under a real identity must abort (an unsigned prod binary is a broken release); under+# ad-hoc it's tolerated so a non-Mach-O file (e.g. the exiftool Perl script) is simply skipped.+sign_one() {+ local f="$1"+ is_macho "$f" || return 0+ if codesign "${sign_opts[@]}" "$f" >/dev/null 2>&1; then+ return 0+ fi+ if $real_identity; then+ echo "FATAL: failed to sign $f with '$IDENTITY'" >&2+ exit 1+ fi+}++# Inside-out: dylibs (the dependencies) before the executables that load them.+while IFS= read -r -d '' f; do sign_one "$f"; done \+ < <(find "$VENDOR_DIR" -type f -name "*.dylib" -print0)+while IFS= read -r -d '' f; do+ case "$f" in *.dylib) continue ;; esac+ sign_one "$f"+done < <(find "$VENDOR_DIR" -maxdepth 1 -type f -perm -u+x -print0)++if $real_identity; then+ echo "Signed bundled tools in $VENDOR_DIR with '$IDENTITY' (hardened runtime)."+else+ echo "Ad-hoc signed bundled tools in $VENDOR_DIR."+fi