diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml index e7b55c64b..539a820da 100644 --- a/.github/workflows/launcher.yml +++ b/.github/workflows/launcher.yml @@ -6,6 +6,9 @@ name: launcher # A release is launcher-vX.Y.Z: the patch after the last launcher tag, or the next minor when a merged pull # request is labelled feature. The version is given to the build (HORIZON_LAUNCHER_VERSION): no bump commits. # Never marked latest. Pushes to launcher branches only build. RELEASES_PAUSED=1 stops releases. +# macOS: with the repository variable MACOS_SIGN_IDENTITY set, Horizon.app and the .dmg are signed with +# Developer ID, notarized and stapled, from the runner's signing keychain (packaging/macos/README.md); +# unset (forks), they are signed ad hoc. # gh workflow run launcher --ref # dry run: builds everything, publishes nothing # gh workflow run launcher --ref main -f dry_run=false -f force=true @@ -102,7 +105,8 @@ jobs: # which only the Visual C++ redistributable installs. rustflags: -C target-feature=+crt-static runs-on: ${{ matrix.mac && (vars.MAC_RUNNER || 'ludovics-mac-mini') || matrix.os }} - timeout-minutes: 40 + # Notarizing the app and then the .dmg can take a few minutes each. + timeout-minutes: ${{ matrix.mac && 60 || 40 }} env: RUSTFLAGS: ${{ matrix.rustflags }} # Horizon's Azure app for Microsoft sign-in (docs/microsoft-account.md): a repository @@ -194,11 +198,19 @@ jobs: help() { "$client" --help > "$RUNNER_TEMP/help.txt" 2>&1 && head -3 "$RUNNER_TEMP/help.txt" && grep -q -- '--resources' "$RUNNER_TEMP/help.txt"; } soft help rm -rf "$HORIZON_LAUNCHER_HOME" + - name: The signing keychain, unlocked + if: runner.os == 'macOS' && vars.MACOS_SIGN_IDENTITY != '' + env: + MACOS_SIGN_IDENTITY: ${{ vars.MACOS_SIGN_IDENTITY }} + run: ../packaging/macos/keychain.sh unlock - name: Package + env: + MACOS_SIGN_IDENTITY: ${{ vars.MACOS_SIGN_IDENTITY }} run: | rm -rf dist out && mkdir -p out if [[ "$RUNNER_OS" == "macOS" ]]; then - # Horizon.app, zipped (self-update) and in a .dmg (installer): packaging/macos. + # Horizon.app, zipped (self-update) and in a .dmg (installer), signed (and notarized with + # Developer ID): packaging/macos. python3 -m venv "$RUNNER_TEMP/dmg" && "$RUNNER_TEMP/dmg/bin/pip" install --quiet dmgbuild==1.6.5 version=${HORIZON_LAUNCHER_VERSION:-$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)} DMGBUILD="$RUNNER_TEMP/dmg/bin/dmgbuild" ../packaging/macos/package.sh target/release/${{ matrix.binary }} "$version" out @@ -218,6 +230,9 @@ jobs: name: ${{ matrix.asset }} path: launcher/out/* retention-days: 3 + - name: The signing keychain, locked again + if: always() && runner.os == 'macOS' && vars.MACOS_SIGN_IDENTITY != '' + run: ../packaging/macos/keychain.sh lock sign: needs: [decide, build] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 546c6707e..2c4e13cf2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,9 @@ name: release # Builds Linux (an older Ubuntu, so the binary runs on any recent distribution and on NixOS through nix-ld) and # Windows on GitHub, macOS on the Mac mini's runner (MAC_RUNNER=macos-latest sends it to GitHub), then # publishes vYYYY.MM.DD[.N] with notes from the merged pull requests, as a beta (a pre-release) that promote.yml makes -# stable after 6 hours. +# stable after 6 hours. macOS: with the repository variable MACOS_SIGN_IDENTITY set, the programs are signed with +# Developer ID and the hardened runtime and the zip is notarized, from the runner's signing keychain +# (packaging/macos/README.md); unset (forks), ad hoc. # gh workflow run release --ref # dry run: builds and notes, publishes nothing # gh workflow run release -f dry_run=false -f force=true # on main: release now, whatever the rules say on: @@ -92,7 +94,8 @@ jobs: dir: horizon-macos-arm64 asset: horizon-macos-arm64.zip runs-on: ${{ matrix.mac && (vars.MAC_RUNNER || 'ludovics-mac-mini') || matrix.os }} - timeout-minutes: 40 + # Notarizing the zip can take a few minutes. + timeout-minutes: ${{ matrix.mac && 60 || 40 }} env: RUSTFLAGS: ${{ matrix.rustflags }} defaults: @@ -123,6 +126,22 @@ jobs: for binary in horizon-client horizon-ctl horizon-prepare horizon-server; do test -f "target/release/$binary${{ matrix.exe }}" || { echo "::error::target/release/$binary${{ matrix.exe }} is missing"; exit 1; } done + - name: The signing keychain, unlocked + if: runner.os == 'macOS' && vars.MACOS_SIGN_IDENTITY != '' + env: + MACOS_SIGN_IDENTITY: ${{ vars.MACOS_SIGN_IDENTITY }} + run: packaging/macos/keychain.sh unlock + - name: Signed with Developer ID and the hardened runtime + # Before the checks below, so they run the programs as players will. + if: runner.os == 'macOS' && vars.MACOS_SIGN_IDENTITY != '' + env: + MACOS_SIGN_IDENTITY: ${{ vars.MACOS_SIGN_IDENTITY }} + run: | + for binary in horizon-client horizon-ctl horizon-prepare horizon-server; do + codesign --force --options runtime --timestamp --keychain "$MACOS_SIGN_KEYCHAIN" \ + --identifier "dev.horizon.${binary#horizon-}" --sign "$MACOS_SIGN_IDENTITY" "target/release/$binary" + codesign --verify --strict --verbose=2 "target/release/$binary" + done - name: Only system libraries # Windows: no non-system DLL (a "DLL not found" dialog on some players' machines). Linux: the standard # loader and libraries every desktop distribution has. macOS: only the system's own libraries. @@ -200,6 +219,14 @@ jobs: fi ;; esac ls -l "${{ matrix.asset }}" + - name: Notarized + # A zip of programs can't be stapled: Gatekeeper asks Apple the first time each one runs. + if: runner.os == 'macOS' && vars.MACOS_SIGN_IDENTITY != '' + run: | + for binary in horizon-client horizon-ctl horizon-prepare horizon-server; do + codesign --verify --strict "dist/${{ matrix.dir }}/$binary" + done + packaging/macos/notarize.sh "dist/${{ matrix.asset }}" - uses: actions/upload-artifact@v4 with: name: ${{ matrix.asset }} @@ -229,6 +256,9 @@ jobs: path: dist/${{ matrix.server_asset }} if-no-files-found: error retention-days: 3 + - name: The signing keychain, locked again + if: always() && runner.os == 'macOS' && vars.MACOS_SIGN_IDENTITY != '' + run: packaging/macos/keychain.sh lock sign: needs: [decide, build] diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index ee33942b2..0da8f9341 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -1644,9 +1644,22 @@ fn find_app(dir: &Path) -> Option { None } +/// Whether the bundle's signature (Developer ID or ad hoc) is whole: every file it seals is there +/// and unchanged. +#[cfg(target_os = "macos")] +fn signature_holds(app: &Path) -> bool { + Command::new("codesign") + .args(["--verify", "--deep", "--strict"]) + .arg(app) + .stderr(std::process::Stdio::null()) + .status() + .is_ok_and(|s| s.success()) +} + /// Puts the bundle `new` in place of `app`: copied beside it first (`ditto` keeps its links, -/// modes and signature), then the old one is moved aside and the new one renamed in, so `app` is -/// never half written. The running launcher keeps its open files and works on. +/// modes and signature) and checked, then the old one is moved aside and the new one renamed in, +/// so `app` is never half written, and checked again where it lands (the old one comes back if it +/// doesn't hold). The running launcher keeps its open files and works on. #[cfg(target_os = "macos")] fn replace_bundle(new: &Path, app: &Path) -> Result<(), String> { let dir = app.parent().ok_or("The app has no folder.")?; @@ -1666,6 +1679,12 @@ fn replace_bundle(new: &Path, app: &Path) -> Result<(), String> { app.display() )); } + if !signature_holds(&staged) { + let _ = fs::remove_dir_all(&staged); + return Err( + "The downloaded app's signature doesn't hold; the launcher stays as it is.".into(), + ); + } fs::rename(app, &old).map_err(|e| { let _ = fs::remove_dir_all(&staged); format!("Could not move {} aside: {e}", app.display()) @@ -1678,6 +1697,16 @@ fn replace_bundle(new: &Path, app: &Path) -> Result<(), String> { app.display() )); } + if !signature_holds(app) { + let failed = dir.join(format!(".{name}.failed-{}", std::process::id())); + if fs::rename(app, &failed).is_ok() && fs::rename(&old, app).is_ok() { + let _ = fs::remove_dir_all(&failed); + } + return Err(format!( + "The new app's signature doesn't hold at {}; the launcher stays as it was.", + app.display() + )); + } let _ = fs::remove_dir_all(&old); Ok(()) } @@ -2586,6 +2615,15 @@ mod tests { ["Horizon.app"], "nothing staged or moved aside is left" ); + + // A bundle changed after it was signed is refused, and the installed one stays. + let tampered = make(&work.join("tampered"), "3.0.0"); + fs::write(tampered.join("Contents/Resources/version"), "3.0.1").unwrap(); + assert!(replace_bundle(&tampered, &installed).is_err()); + let version = fs::read_to_string(installed.join("Contents/Resources/version")).unwrap(); + assert_eq!(version, "2.0.0"); + let left = fs::read_dir(work.join("Applications")).unwrap().count(); + assert_eq!(left, 1, "nothing staged is left"); let _ = fs::remove_dir_all(&work); } diff --git a/packaging/macos/README.md b/packaging/macos/README.md index 7441ccf77..ece4995d5 100644 --- a/packaging/macos/README.md +++ b/packaging/macos/README.md @@ -14,11 +14,71 @@ swapped in by renaming, then restarted); a bare `horizon-launcher` binary, as launchers before the app shipped, finds the binary inside the zip and replaces only itself. -## Signing and Gatekeeper +## Signing and notarization -The app is signed **ad hoc** (`codesign --sign -`): no Apple account is needed, the bundle is -consistent and runs on Apple Silicon, but Gatekeeper doesn't know the developer. The first time -a player opens it after downloading: +Releases are signed with Ludovic's **Developer ID** ("Developer ID Application: Ludovic Marie +(YYJU63HSD4)"), with the hardened runtime and a secure timestamp, then **notarized** by Apple and +**stapled**, so Gatekeeper opens them on any Mac without a warning, offline too: + +- the launcher (`package.sh`): Horizon.app is signed, notarized and stapled first, so the zip the + launcher updates itself from and the .dmg both hold it stapled; then the .dmg is signed, + notarized and stapled. The script ends with what Gatekeeper says of each, which must read + `accepted` and `source=Notarized Developer ID`. +- the game (`.github/workflows/release.yml`): `horizon-client`, `horizon-ctl` and + `horizon-prepare` are signed right after they are built (so the checks and the 1500-frame smoke + run use them as players will), and the zip is notarized. Programs outside a bundle can't hold a + ticket: Gatekeeper asks Apple online the first time each one runs. + +No entitlements are needed. The launcher checks an update's signature before swapping the new +Horizon.app in, and again where it lands; when it doesn't hold, the old app is put back. + +The switch is the repository variable `MACOS_SIGN_IDENTITY`: set to the identity's name, the +builds sign and notarize; empty (as in forks), they are signed **ad hoc** as before. + +### The signing keychain on the Mac mini + +The release runner (`ludovics-mac-mini-release`, label `horizon-release`, `MAC_RUNNER`) is a +LaunchAgent whose jobs run in their own security session, where the login keychain is locked. +So signing uses a keychain of its own, `~/Library/Keychains/horizon-signing.keychain-db`, +holding only the Developer ID identity, Apple's "Developer ID Certification Authority" and the +notarytool profile `horizon-notary` (the App Store Connect team key "App Store Connect API - +GitHub CI (DISPO)"). Its password is the item "Horizon signing keychain" in the Agents vault. +`keychain.sh unlock` (each job's first macOS step) reads it with the fleet's 1Password service +account, unlocks the keychain, checks the identity and the profile are there and hands both to +the later steps; `keychain.sh lock` ends the job. Nothing secret is in the repository or on +GitHub, and nothing is printed. + +Setting it up again (a new Mac, a renewed certificate): + +1. `packaging/macos/keychain.sh create`: the keychain, locked after two hours idle and on sleep. +2. In Keychain Access on the Mac (the login keychain, *My Certificates*), right-click + "Developer ID Application: Ludovic Marie (YYJU63HSD4)", *Export…*, save it as a .p12 with a + password; then in the Mac's Terminal `packaging/macos/keychain.sh import FILE.p12`. It asks for + that password, imports the identity and its intermediate, removes any other identity, lets + `codesign` use the key without a prompt and deletes the .p12. (The login keychain also holds + other people's Apple Development and Distribution identities: never those.) +3. `packaging/macos/keychain.sh notary`: the notarytool profile, from the App Store Connect key + (written to a private temporary file and deleted). +4. The repository variable `MACOS_SIGN_IDENTITY`. + +The certificate and its intermediate expire on 1 February 2027: renew the certificate in the +Apple Developer account before then and repeat step 2. + +Signing by hand, as the workflow does: + +```sh +export MACOS_SIGN_IDENTITY="Developer ID Application: Ludovic Marie (YYJU63HSD4)" +export MACOS_SIGN_KEYCHAIN=~/Library/Keychains/horizon-signing.keychain-db MACOS_NOTARY_PROFILE=horizon-notary +packaging/macos/keychain.sh unlock +packaging/macos/package.sh target/release/horizon-launcher 0.0.0 out +packaging/macos/keychain.sh lock +``` + +### Gatekeeper with an ad hoc build + +An ad hoc build (a fork's, or `package.sh` without `MACOS_SIGN_IDENTITY`) is consistent and runs +on Apple Silicon, but Gatekeeper doesn't know the developer. The first time it is opened after +downloading: - macOS 14 and earlier: right-click (or Control-click) Horizon in Applications, choose **Open**, then **Open** in the dialog. @@ -27,13 +87,3 @@ a player opens it after downloading: After that it opens normally, and its own updates don't ask again (they aren't downloaded by a browser, so they carry no quarantine flag). - -To sign and notarize for real (Ludovic's Apple Developer account): import the "Developer ID -Application" certificate into the runner's keychain, set `MACOS_SIGN_IDENTITY` to its name for -`package.sh` (it then signs with the hardened runtime and a timestamp), and after it, notarize and -staple the disk image: - -```sh -xcrun notarytool submit dist/horizon-launcher-macos-arm64.dmg --keychain-profile horizon --wait -xcrun stapler staple dist/horizon-launcher-macos-arm64.dmg -``` diff --git a/packaging/macos/keychain.sh b/packaging/macos/keychain.sh new file mode 100755 index 000000000..ada8f6a37 --- /dev/null +++ b/packaging/macos/keychain.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# The keychain the macOS builds are signed and notarized from: a keychain of its own (not the +# login keychain, which a runner's job can't unlock), holding only the "Developer ID +# Application" identity, its intermediate certificate and the notarytool profile. Its password +# is in 1Password (the Agents vault, read with the fleet's service account), so a job unlocks +# it without anyone typing anything. See packaging/macos/README.md. +# +# packaging/macos/keychain.sh unlock # a job's first macOS step: unlock, check, export the env +# packaging/macos/keychain.sh lock # its last +# packaging/macos/keychain.sh create # once: the keychain, with the password from 1Password +# packaging/macos/keychain.sh import P12 # once, from the Mac's own Terminal: the identity +# packaging/macos/keychain.sh notary # once: the notarytool profile from the App Store Connect key +# +# MACOS_SIGN_IDENTITY names the identity (empty: nothing is signed, see package.sh); +# MACOS_SIGN_KEYCHAIN the keychain; MACOS_NOTARY_PROFILE the profile in it; MACOS_KEYCHAIN_PASSWORD, +# when set, is the keychain's password instead of 1Password's. +set -euo pipefail +kc=${MACOS_SIGN_KEYCHAIN:-$HOME/Library/Keychains/horizon-signing.keychain-db} +profile=${MACOS_NOTARY_PROFILE:-horizon-notary} +identity=${MACOS_SIGN_IDENTITY:-Developer ID Application: Ludovic Marie (YYJU63HSD4)} +# The 1Password CLI, signed in as the fleet's agents (`op` elsewhere), and the items it reads. +op=${OP:-$HOME/fleet/op} +[[ -x "$op" ]] || op=op +password_ref=${MACOS_KEYCHAIN_PASSWORD_REF:-op://Agents/Horizon signing keychain/password} +# "App Store Connect API - GitHub CI (DISPO)": a team key; by id, as the name's parentheses +# can't be in a secret reference. +notary_item=${MACOS_NOTARY_ITEM:-wwweyy32dwt6oylm6ypcfivsxe} + +# The keychain's password: $MACOS_KEYCHAIN_PASSWORD (a CI secret elsewhere), or from 1Password. +password() { + if [[ -n "${MACOS_KEYCHAIN_PASSWORD:-}" ]]; then + printf '%s' "$MACOS_KEYCHAIN_PASSWORD" + else + "$op" read "$password_ref" < /dev/null + fi +} + +case "${1:-}" in + unlock) + security unlock-keychain -p "$(password)" "$kc" + security find-identity -v -p codesigning "$kc" | grep -F "\"$identity\"" > /dev/null || + { echo "::error::$kc has no valid \"$identity\" (packaging/macos/keychain.sh import)"; exit 1; } + xcrun notarytool history --keychain-profile "$profile" --keychain "$kc" > /dev/null || + { echo "::error::no notarytool profile $profile in $kc (packaging/macos/keychain.sh notary)"; exit 1; } + echo "Unlocked $kc: \"$identity\" and the notarytool profile $profile" + if [[ -n "${GITHUB_ENV:-}" ]]; then + { echo "MACOS_SIGN_KEYCHAIN=$kc"; echo "MACOS_NOTARY_PROFILE=$profile"; } >> "$GITHUB_ENV" + fi + ;; + lock) + security lock-keychain "$kc" + ;; + create) + [[ -e "$kc" ]] && { echo "$kc already exists"; exit 1; } + security create-keychain -p "$(password)" "$kc" + # Locks itself after two hours idle and when the Mac sleeps. + security set-keychain-settings -t 7200 -l "$kc" + echo "Created $kc" + ;; + import) + p12=${2:?usage: keychain.sh import IDENTITY.p12} + pass=$(password) + security unlock-keychain -p "$pass" "$kc" + read -rsp "The password you gave the .p12 when exporting it: " p12pass && echo + security import "$p12" -k "$kc" -f pkcs12 -P "$p12pass" -T /usr/bin/codesign + unset p12pass + # The intermediate, so codesign builds the chain without the login keychain. + issuer=$(security find-certificate -c "$identity" -p "$kc" | openssl x509 -noout -issuer | + sed -n 's/.*CN *= *\([^,]*\).*/\1/p') + if [[ -n "$issuer" ]] && ! security find-certificate -c "$issuer" "$kc" > /dev/null 2>&1 && + security find-certificate -c "$issuer" -p "$HOME/Library/Keychains/login.keychain-db" > "$kc.ca.pem"; then + security import "$kc.ca.pem" -k "$kc" + fi + rm -f "$kc.ca.pem" + # Only the one identity: anything else the .p12 held goes. + security find-identity -v -p codesigning "$kc" | sed -n 's/^ *[0-9]*) \([0-9A-F]*\) "\(.*\)"$/\1 \2/p' | + while read -r hash name; do + [[ "$name" == "$identity" ]] || security delete-identity -Z "$hash" "$kc" + done + # codesign may use the key without asking. + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$pass" "$kc" > /dev/null + rm -f "$p12" + security find-identity -v -p codesigning "$kc" + echo "Imported; $p12 is deleted." + ;; + notary) + security unlock-keychain -p "$(password)" "$kc" + key=$(mktemp) && chmod 600 "$key" + trap 'rm -f "$key"' EXIT + "$op" read "op://Agents/$notary_item/private_key_p8" < /dev/null > "$key" + xcrun notarytool store-credentials "$profile" --key "$key" --keychain "$kc" \ + --key-id "$("$op" read "op://Agents/$notary_item/key_id" < /dev/null)" \ + --issuer "$("$op" read "op://Agents/$notary_item/issuer_id" < /dev/null)" + ;; + *) + sed -n '/^set -e/q; 2,$s/^# \{0,1\}//p' "$0" + exit 1 + ;; +esac diff --git a/packaging/macos/notarize.sh b/packaging/macos/notarize.sh new file mode 100755 index 000000000..d87904b5c --- /dev/null +++ b/packaging/macos/notarize.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# Notarizes signed macOS builds with Apple's notary service and staples the ticket to what can +# hold one: an .app (sent as a zip) and a .dmg are stapled, a .zip of bare programs can't be +# (Gatekeeper asks Apple online the first time one runs). +# +# packaging/macos/notarize.sh FILE... +# +# Uses the notarytool profile $MACOS_NOTARY_PROFILE in the keychain $MACOS_SIGN_KEYCHAIN, which +# `packaging/macos/keychain.sh unlock` unlocks and exports. +set -euo pipefail +profile=${MACOS_NOTARY_PROFILE:?the notarytool profile (packaging/macos/keychain.sh unlock)} +keychain=() +[[ -n "${MACOS_SIGN_KEYCHAIN:-}" ]] && keychain=(--keychain "$MACOS_SIGN_KEYCHAIN") + +for file in "$@"; do + file=${file%/} + sent=$file + if [[ "$file" == *.app ]]; then + sent=$(mktemp -d)/$(basename "$file").zip + ditto -c -k --norsrc --noextattr --noqtn --keepParent "$file" "$sent" + fi + echo "Notarizing $(basename "$file")…" + result=$(xcrun notarytool submit "$sent" --keychain-profile "$profile" ${keychain[@]+"${keychain[@]}"} \ + --wait --timeout 30m --output-format json) + [[ "$sent" == "$file" ]] || rm -rf "$(dirname "$sent")" + id=$(plutil -extract id raw -o - - <<< "$result") + status=$(plutil -extract status raw -o - - <<< "$result") + echo "$(basename "$file"): $status (submission $id)" + if [[ "$status" != Accepted ]]; then + xcrun notarytool log "$id" --keychain-profile "$profile" ${keychain[@]+"${keychain[@]}"} || true + echo "::error::$(basename "$file") was not notarized: $status" + exit 1 + fi + case "$file" in + *.app | *.dmg) xcrun stapler staple "$file" && xcrun stapler validate "$file" ;; + esac +done diff --git a/packaging/macos/package.sh b/packaging/macos/package.sh index 5743343f5..646de23d2 100755 --- a/packaging/macos/package.sh +++ b/packaging/macos/package.sh @@ -7,9 +7,11 @@ # packaging/macos/package.sh BINARY VERSION OUTDIR # # Needs macOS (ditto, codesign, hdiutil) and dmgbuild (pip install dmgbuild==1.6.5; $DMGBUILD -# names it if it isn't on PATH). Signing: ad hoc by default, which needs no Apple account; -# set MACOS_SIGN_IDENTITY to a "Developer ID Application: …" identity in the keychain to sign -# for real (then notarize the .dmg: see packaging/macos/README.md). +# names it if it isn't on PATH). Signing: ad hoc by default, which needs no Apple account. With +# MACOS_SIGN_IDENTITY set to a "Developer ID Application: …" identity (in $MACOS_SIGN_KEYCHAIN +# when set), the app and the .dmg are signed with the hardened runtime and a timestamp, and with +# MACOS_NOTARY_PROFILE too, both are notarized and stapled (keychain.sh unlock sets the two; +# see packaging/macos/README.md). set -euo pipefail here=$(cd "$(dirname "$0")" && pwd) binary=$1 @@ -27,12 +29,19 @@ printf 'APPL????' > "$app/Contents/PkgInfo" plutil -lint "$app/Contents/Info.plist" identity=${MACOS_SIGN_IDENTITY:--} +keychain=() +[[ -n "${MACOS_SIGN_KEYCHAIN:-}" ]] && keychain=(--keychain "$MACOS_SIGN_KEYCHAIN") if [[ "$identity" == "-" ]]; then codesign --force --sign - "$app" else - codesign --force --options runtime --timestamp --sign "$identity" "$app" + codesign --force --options runtime --timestamp ${keychain[@]+"${keychain[@]}"} --sign "$identity" "$app" fi codesign --verify --strict --verbose=2 "$app" +# Still starts under the hardened runtime. +"$app/Contents/MacOS/horizon-launcher" --version +notarize=$([[ "$identity" != "-" && -n "${MACOS_NOTARY_PROFILE:-}" ]] && echo yes || true) +# The app first, so the zip and the .dmg both carry it stapled. +[[ -z "$notarize" ]] || "$here/notarize.sh" "$app" rm -f "$out/horizon-launcher-macos-arm64.zip" "$out/horizon-launcher-macos-arm64.dmg" # No resource forks or extended attributes: they would land as ._ files inside the bundle. @@ -53,5 +62,16 @@ cat > "$out/dmg.json" </dev/null +dmg=$out/horizon-launcher-macos-arm64.dmg +if [[ "$identity" != "-" ]]; then + codesign --force --timestamp ${keychain[@]+"${keychain[@]}"} --sign "$identity" "$dmg" + codesign --verify --strict --verbose=2 "$dmg" +fi +hdiutil verify "$dmg" >/dev/null +if [[ -n "$notarize" ]]; then + "$here/notarize.sh" "$dmg" + # What Gatekeeper says of a download: both must be "source=Notarized Developer ID". + spctl --assess --verbose=2 "$app" + spctl --assess --type open --context context:primary-signature --verbose=2 "$dmg" +fi echo "Packaged $out/horizon-launcher-macos-arm64.zip and .dmg"