Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Release: sign and notarize the macOS app (#5749) (#6016)

Mikalai Kukhta4e2270517aa6
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 3c39d717f2..021fcd003e 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -4,11 +4,12 @@
# comes from [workspace.package] in Cargo.toml. An agent verifies the artifacts and publishes
# the draft separately; see docs/releasing.md. Tags and pushes to main do not trigger releases.
# At midnight Eastern, changed main commits build and publish a nightly pre-release.
-# A version with a suffix (0.2.0-rc.1) is a pre-release. Nothing is signed yet.
+# A version with a suffix (0.2.0-rc.1) is a pre-release.
+# The macOS app is signed and notarized when the APPLE_* secrets exist, nothing else is signed yet.
#
# Linux x86_64, aarch64 AppImage (+ .zsync), .deb, .rpm, .flatpak, .snap, .tar.gz packaging/linux
# FreeBSD x86_64 .tar.gz (built in a FreeBSD VM) packaging/freebsd
-# macOS universal .dmg, and the CLI as a .zip packaging/macos
+# macOS universal .dmg, and the CLI as a .zip (both archs built in parallel) packaging/macos
# Windows x64, x86, arm64 .msi and a portable .zip; x64 also the plain .exe packaging/windows
# Web a .zip of the static site packaging/web
#
@@ -295,11 +296,19 @@ jobs:
path: dist/release/*
if-no-files-found: error
- macos:
- name: macOS universal
+ # The two halves of the universal binary build in parallel on their own runners (each alone
+ # took about half of the old single job's 45 minutes); `macos` below joins and packages them.
+ macos-build:
+ name: macOS build ${{ matrix.arch }}
needs: version
if: needs.version.outputs.build == 'true'
runs-on: macos-14
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - { arch: aarch64, target: aarch64-apple-darwin }
+ - { arch: x86_64, target: x86_64-apple-darwin }
env:
SOLIDCRAFT_VERSION: ${{ needs.version.outputs.version }}
SOLIDCRAFT_BUILD_DATE: ${{ needs.version.outputs.date }}
@@ -307,12 +316,58 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: dtolnay/rust-toolchain@stable
with:
- targets: aarch64-apple-darwin, x86_64-apple-darwin
+ targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
- key: release-macos-universal
- - name: Build and package (dmg, CLI zip; the dmg is mounted and checked)
- run: packaging/macos/package.sh --arch universal
+ key: release-macos-${{ matrix.arch }}
+ - name: Build
+ run: packaging/macos/package.sh --build-only ${{ matrix.target }}
+ # Not named release-*: the release job collects every release-* artifact as an asset.
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ with:
+ name: macos-bin-${{ matrix.arch }}
+ path: |
+ target/${{ matrix.target }}/release/solidcraft
+ target/${{ matrix.target }}/release/solidcraft-cli
+ target/${{ matrix.target }}/release/solvecraft-cli
+ if-no-files-found: error
+
+ macos:
+ name: macOS universal
+ needs: [version, macos-build]
+ if: needs.version.outputs.build == 'true'
+ runs-on: macos-14
+ env:
+ SOLIDCRAFT_VERSION: ${{ needs.version.outputs.version }}
+ SOLIDCRAFT_BUILD_DATE: ${{ needs.version.outputs.date }}
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ with:
+ name: macos-bin-aarch64
+ path: target/aarch64-apple-darwin/release
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ with:
+ name: macos-bin-x86_64
+ path: target/x86_64-apple-darwin/release
+ - name: Set up Developer ID signing and notarization
+ # Optional until the APPLE_* secrets exist (docs/releasing.md, "macOS signing"). Without
+ # them (forks, dry runs) the app keeps its ad-hoc signature and is not notarized.
+ env:
+ APPLE_CERTIFICATE_P12: ${{ secrets.APPLE_CERTIFICATE_P12 }}
+ APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
+ APPLE_API_KEY_P8: ${{ secrets.APPLE_API_KEY_P8 }}
+ APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
+ APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
+ run: packaging/macos/signing.sh --setup
+ - name: Join, sign, package and check (dmg, CLI zip; the dmg is mounted and checked)
+ run: |
+ # Artifacts don't keep the executable bit.
+ chmod +x target/*-apple-darwin/release/solidcraft target/*-apple-darwin/release/solidcraft-cli target/*-apple-darwin/release/solvecraft-cli
+ packaging/macos/package.sh --arch universal --skip-build ${MACOS_SIGN_IDENTITY:+--sign}
+ - name: Remove the signing keychain and API key
+ if: always()
+ run: packaging/macos/signing.sh --cleanup
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release-macos
diff --git a/ROADMAP.md b/ROADMAP.md
index 15ba808c25..bc2232a7e6 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -63,7 +63,7 @@ PCB / Package, Render, Animation, Simulation, Manufacture/CAM, Drawings.
| M9 | Components and assemblies: New Component / Create Components from Bodies, active component, per-component origin/bodies/sketches/timeline entries, occurrences with transforms, Copy/Paste vs Paste New, nested Browser tree with visibility and isolate; Ground, Move/Copy of occurrences, joints (rigid, revolute, slider, cylindrical, pin-slot, planar, ball) by joint origins with limits and Drive Joints, closed kinematic loops (four-bar, slider-crank: the loop's other joints follow the driven one on its branch, and driving stops where a loop can no longer close), cams (`joint.cam`: a revolute cam drives a slider or revolute follower along a closed sketch profile or the cam's edges, knife, roller or flat followers, worked out again when the profile changes; drives, studies, closed loops, contact sets), As-built Joint, Rigid Group, Contact Sets (driving and motion studies stop where bodies in a set would pass through each other), Motion Study (joint values keyed along a timeline, playback, export of occurrence positions as JSON/CSV), motion analysis (joint values and a point's path charted over a study as value, velocity and acceleration; the parts that collide along a study, with the steps where they do), Exploded views (automatic or by hand, shown without changing placements, and exported as an animation coming apart and back together); interference, per-component physical properties; STEP with assembly structure; URDF export for robot simulators (links with meshes, mass and inertia; joint chains whose values match Drive Joints; docs/urdf.md). Physical properties now measure material-aware component/occurrence placements, descendants and repeated instances, including pending moves and body reassignment offsets; contact geometry and automatic exploded centres respect those offsets. Groundwork done: component tree, occurrences with transforms (instances, Paste New), world placement, active component as authoring frame, ground, Capture/Revert Position, moving bodies and sketches. UI: ASSEMBLE panel dialogs for New Component, Joint (snaps on faces, edges, circles and vertices; animated motion preview; offsets, flip, limits), As-built Joint, Joint Origin, Rigid Group, Drive Joints (live slider), Motion Link, Cam and Interference (overlaps shown red); joints in the timeline and the Browser | in progress | 32 |
| M10 | Sheet metal: flange (base, edge, contour), hem, unfold/refold, convert, flat pattern + DXF, rules: done. PLASTIC enclosure subset: Boss, Rib, Web, Lip/Groove, Snap Fit, Rest, Plastic Rules (library, edit, assign; rule draft and clearance as feature defaults): done, tested against hand-computed geometry. UI: SHEET METAL and PLASTIC tabs with dialogs (live preview, Edit Feature, pre-selection) for Flange, Hem, Unfold/Refold, Convert, Sheet Metal Rules, Create Flat Pattern (flat view with bend lines, bend table CSV/JSON and DXF export with exact circle/arc/line cutouts), Boss, Lip/Groove, Snap Fit, Rest, Manage and Assign Plastic Rules; Fold (bend along a sketch line); flanges meeting at a corner closed at any angle with the rule's gap; edge flanges with their own angle and height per edge in one feature; corner reliefs (notch, round, rectangular, tear) chosen by the rule; Convert to Sheet Metal from a solid or shelled body by its bend edges (flat faces, sharp bends) | in progress | 36 |
| M11 | 2D drawings | deferred | — |
-| M12 | Release: cross-platform packages, verification and deliberate publication implemented; original current-UI demo refreshed. Trusted distribution signing and broader performance work remain | in progress | 16 |
+| M12 | Release: cross-platform packages, verification and deliberate publication implemented; original current-UI demo refreshed. macOS Developer ID signing and notarization are in the release workflow (#5749; they switch on when the Apple secrets exist). Windows installer signing and broader performance work remain | in progress | 16 |
| M14 | Configurations: a table of rows (parameter expressions and feature suppressions per row) switched with config.activate (undoable, all or nothing), kept through parameter renames and feature deletes (config.configure, config.table, config.column/row/activate). Per-row body materials and appearances (library looks, custom colour/opacity and clearing overrides), undoable activation and save/reopen: done. Ordered typed configuration rules, atomic validation and structured rule editing: done. Component appearance and certified semantic face style columns, atomic preview/apply and independent-copy remapping: done. Exact constructed sketch-side and immutable imported-face lineage now preserve legacy names and reject retargeting. Left: ambiguous shifted/two-sided caps | in progress | 4 |
| M13 | Never lose work: atomic saves (temporary file, flush, rename; a crash at any moment leaves the old file or the new one) with the replaced version kept as `<file>.bak`; autosave of unsaved changes to the recovery folder every 5 minutes (preference) and after big operations, only when something changed; "Recover unsaved design?" on the next launch (`doc.recovery_list`, `doc.recover`, `doc.recovery_discard`); a kill-mid-save test (process killed while saving a 0.5 MB design 25 times). File format: `"format": "solidcraft/12"`, older formats upgraded step by step (`doc::format`), newer ones refused with a message, out-of-range numbers and broken placements refused; a corpus of designs saved by M0, components-era, joints-era and current builds (apps/solidcraft-cli/tests/corpus) that must open and evaluate as saved; damaged and hostile variants (truncation, bit flips, hostile values, removed keys, repeated features, deep nesting) never panic | done | 6 |
| M15 | Frames and weldments (#4003): structural members along 2D and 3D sketch lines, butt and mitre corners, trim to faces and bodies, end caps, gussets, cosmetic welds and a cut list. Done: the profile library (`frame.profile.list`, `frame.profile.properties`, `frame.profile.insert`): bar, round bar, rectangular and round tube, angle, channel and I-beam, each SolidCraft's own parametric definition with exact fillet arcs and exact section properties (area, centroid, second moments), tested against hand-computed values; members (`frame.member`): one body per straight line of a 2D or 3D frame sketch, following parameter edits, with a built-in profile (its dimensions parameter expressions) or a profile sketch (its drawn material by alternating nested loops), anchor, angle and mirror; each member's name kept with its line. Left: corners, trims, end caps, gussets, welds, cut list, FRAME tab and dialogs | in progress | 60 |
diff --git a/docs/releasing.md b/docs/releasing.md
index 0263dcd142..621e4ebafa 100644
--- a/docs/releasing.md
+++ b/docs/releasing.md
@@ -128,8 +128,9 @@ change release infrastructure does not itself request publication of the applica
and an example model on an available platform. Inspect the package-check job output for
other platforms; report any platform you could not exercise yourself.
3. Review the generated notes. Add a concise description of features, fixes, breaking changes,
- and known limitations. Keep the installation instructions. Packages are currently unsigned;
- do not claim otherwise. Resolve failed checks or missing artifacts before publication.
+ and known limitations. Keep the installation instructions. The macOS app is Developer ID
+ signed and notarized only when the build summary says so; other packages are unsigned. Do not
+ claim otherwise. Resolve failed checks or missing artifacts before publication.
4. Publish the verified draft using `gh` or the equivalent GitHub release API. For example:
```sh
@@ -246,6 +247,44 @@ When the token expires, create a new one the same way and run step 2 again. If a
published while the secret was missing or expired, submit it afterwards with
`gh workflow run winget.yml -R bherbruck/solidcraft -f tag=v<version>`.
+## macOS signing and notarization
+
+`packaging/macos/package.sh` signs with the hardened runtime and notarizes when the release
+workflow has these repository secrets; without them (forks, dry runs) it keeps the ad-hoc
+signature and the job summary says so:
+
+| Secret | Content |
+| --- | --- |
+| `APPLE_CERTIFICATE_P12` | base64 of the **Developer ID Application** certificate and key, exported as `.p12` |
+| `APPLE_CERTIFICATE_PASSWORD` | password of that `.p12` |
+| `APPLE_API_KEY_P8` | text of the App Store Connect API key (`AuthKey_<id>.p8`) |
+| `APPLE_API_KEY_ID` | the key's ID |
+| `APPLE_API_ISSUER` | the issuer ID (App Store Connect > Users and Access > Integrations) |
+
+`packaging/macos/signing.sh --setup` imports the certificate into a temporary keychain after the
+build, and `--cleanup` removes it at the end of the job.
+
+The app is signed with `packaging/macos/entitlements.plist`. Its
+`com.apple.security.cs.disable-library-validation` entitlement lets the hardened runtime load
+3Dconnexion's `3DconnexionClient.framework` (`crates/threedx-client/src/macos.rs`); without it
+the 3D mouse silently stops working. Test a notarized build with a real 3D mouse before
+publishing. The script notarizes the app (a zip of it) and staples it before the `.dmg` is made,
+so a copy dragged to /Applications opens offline. It then notarizes and staples the `.dmg`, and
+notarizes the CLI `.zip` (a zip can't be stapled). `stapler staple` is retried, because it can
+fail with error 65 for a while after Apple accepts a submission. The checks are `stapler validate`
+and `spctl` on the `.dmg`, and `spctl --assess` on the mounted app. To try it
+locally, pass `--sign` and set `MACOS_SIGN_IDENTITY` and the `APPLE_API_KEY_PATH`, `APPLE_API_KEY_ID`,
+`APPLE_API_ISSUER` variables and run the script.
+
+The certificate expires in **November 2027**. To renew it, create a new Developer ID Application
+certificate in the Apple Developer account, export it with its key as a `.p12`, and replace
+`APPLE_CERTIFICATE_P12` and `APPLE_CERTIFICATE_PASSWORD`. Releases built before the expiry stay
+valid, because the signature carries a secure timestamp.
+
+Signing currently uses a maintainer's **personal** Developer ID, so downloads show that person's
+name, not an organisation's. Moving to an organisation account means replacing the certificate
+and the API key secrets (`APPLE_API_KEY_P8`, `APPLE_API_KEY_ID`, `APPLE_API_ISSUER`).
+
## Update signing
The app's **Update now** (docs/book/src/guide/updates.md) only installs a package whose SHA-256
diff --git a/packaging/macos/entitlements.plist b/packaging/macos/entitlements.plist
new file mode 100644
index 0000000000..fbadfcac84
--- /dev/null
+++ b/packaging/macos/entitlements.plist
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <!-- The hardened runtime only loads libraries signed by our own team. The 3D mouse support
+ (crates/threedx-client/src/macos.rs) dlopens 3Dconnexion's
+ /Library/Frameworks/3DconnexionClient.framework, which is signed by 3Dconnexion. Without
+ this, the load fails and the 3D mouse stops working without any message. -->
+ <key>com.apple.security.cs.disable-library-validation</key>
+ <true/>
+</dict>
+</plist>
diff --git a/packaging/macos/package.sh b/packaging/macos/package.sh
index 08112bb989..de66ee44d3 100755
--- a/packaging/macos/package.sh
+++ b/packaging/macos/package.sh
@@ -6,9 +6,20 @@
# $DIST/solidcraft-cli-<version>-macos-<arch>.zip the headless CLI (and its solvecraft-cli
# compatibility alias) with the licence files
#
-# Usage: packaging/macos/package.sh [--arch universal|aarch64|x86_64] [--skip-build]
+# Usage: packaging/macos/package.sh [--arch universal|aarch64|x86_64] [--skip-build] [--sign]
+# packaging/macos/package.sh --build-only <rust-target>
#
-# The app is ad-hoc signed (not notarized): the first launch needs right-click > Open.
+# --build-only builds just that target (aarch64-apple-darwin or x86_64-apple-darwin) and stops,
+# so the release workflow can build the two halves of the universal binary on separate runners;
+# a later `--arch universal --skip-build` run joins the binaries it finds under
+# $CARGO_TARGET_DIR/<target>/release/ and packages them.
+#
+# Signing: with --sign, MACOS_SIGN_IDENTITY (a "Developer ID Application: ..." name or its SHA-1
+# hash, found in the keychain) signs the app, the CLI and the DMG with the hardened runtime and a
+# secure timestamp. With the App Store Connect API key as well (APPLE_API_KEY_PATH = the .p8 file,
+# APPLE_API_KEY_ID, APPLE_API_ISSUER) the app, the DMG and the CLI zip are notarized; the app
+# and the DMG are stapled. Without --sign the app is ad-hoc signed, not notarized: first launch needs
+# right-click > Open.
# Adapted from PhotoCraft's packaging (storytold/photocraft, Apache-2.0; see ATTRIBUTION.md).
set -euo pipefail
# shellcheck source=../env.sh
@@ -16,13 +27,64 @@ set -euo pipefail
# The same reverse-DNS id as the Linux APP_ID.
MACOS_BUNDLE_ID=ai.storyteller.solidcraft
+# sign_code <path> [identifier] [entitlements]: Developer ID with the hardened runtime and a secure
+# timestamp, or the ad-hoc signature (Apple silicon refuses unsigned code) without an identity.
+sign_code() {
+ local path="$1" identifier="${2:-}" entitlements="${3:-}"
+ local args=(--force)
+ if [ -n "$SIGN_IDENTITY" ]; then
+ args+=(--sign "$SIGN_IDENTITY" --options runtime --timestamp)
+ else
+ args+=(--sign - --timestamp=none)
+ fi
+ if [ -n "$identifier" ]; then args+=(--identifier "$identifier"); fi
+ if [ -n "$entitlements" ] && [ -n "$SIGN_IDENTITY" ]; then args+=(--entitlements "$entitlements"); fi
+ codesign "${args[@]}" "$path"
+}
+
+# notarize <path>: submit to Apple and wait up to 30 minutes; a rejection or timeout fails the
+# build, and a rejection prints Apple's log.
+notarize() {
+ local out
+ # Not fatal here: the status check below is the only failure path, so the log is always fetched.
+ out="$(xcrun notarytool submit "$1" --key "$APPLE_API_KEY_PATH" --key-id "$APPLE_API_KEY_ID" \
+ --issuer "$APPLE_API_ISSUER" --wait --timeout 30m --output-format json || true)"
+ echo "$out"
+ local id
+ id="$(printf '%s' "$out" | /usr/bin/plutil -extract id raw -o - - 2>/dev/null || true)"
+ if [ "$(printf '%s' "$out" | /usr/bin/plutil -extract status raw -o - - 2>/dev/null || true)" != Accepted ]; then
+ if [ -n "$id" ]; then
+ xcrun notarytool log "$id" --key "$APPLE_API_KEY_PATH" --key-id "$APPLE_API_KEY_ID" --issuer "$APPLE_API_ISSUER" >&2 || true
+ fi
+ echo "notarization of $1 was not accepted" >&2
+ return 1
+ fi
+}
+
+# staple <path>: stapling can fail with error 65 for a while after Apple accepts a submission, so
+# try a few times.
+staple() {
+ local i
+ for i in 1 2 3 4 5 6; do
+ if xcrun stapler staple "$1"; then return 0; fi
+ echo "stapler staple failed (attempt $i), retrying" >&2
+ sleep "${STAPLE_RETRY_SLEEP:-20}"
+ done
+ echo "could not staple $1" >&2
+ return 1
+}
+
ARCH=universal
SKIP_BUILD=0
+BUILD_ONLY=
+SIGN=0
while [ $# -gt 0 ]; do
case "$1" in
--arch) ARCH="$2"; shift 2 ;;
--skip-build) SKIP_BUILD=1; shift ;;
- -h | --help) sed -n '2,10p' "$0"; exit 0 ;;
+ --build-only) BUILD_ONLY="$2"; shift 2 ;;
+ --sign) SIGN=1; shift ;;
+ -h | --help) sed -n '2,23p' "$0"; exit 0 ;;
*) echo "unknown argument: $1" >&2; exit 2 ;;
esac
done
@@ -33,6 +95,28 @@ case "$ARCH" in
*) echo "unknown --arch $ARCH" >&2; exit 2 ;;
esac
+if [ -n "$BUILD_ONLY" ] && [ "$SKIP_BUILD" = 1 ]; then
+ echo "--skip-build and --build-only exclude each other" >&2; exit 2
+fi
+if [ -n "$BUILD_ONLY" ] && [ "$SIGN" = 1 ]; then
+ echo "--build-only builds nothing to sign: drop --sign" >&2; exit 2
+fi
+SIGN_IDENTITY=
+NOTARIZE=0
+if [ "$SIGN" = 1 ]; then
+ SIGN_IDENTITY="${MACOS_SIGN_IDENTITY:-}"
+ if [ -z "$SIGN_IDENTITY" ]; then echo "--sign needs MACOS_SIGN_IDENTITY" >&2; exit 2; fi
+ if [ -n "${APPLE_API_KEY_PATH:-}" ] && [ -n "${APPLE_API_KEY_ID:-}" ] && [ -n "${APPLE_API_ISSUER:-}" ]; then
+ NOTARIZE=1
+ else
+ echo "==> Developer ID signing without notarization: the APPLE_API_* settings are incomplete"
+ fi
+else
+ echo "==> no --sign: ad-hoc signing, no notarization"
+fi
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
# Keep in sync with LSMinimumSystemVersion in Info.plist.in.
export MACOSX_DEPLOYMENT_TARGET=11.0
SHORT_VERSION="${VERSION%%-*}"
@@ -41,6 +125,16 @@ APP="$WORK/SolidCraft.app"
DMG="$DIST/solidcraft-$VERSION-macos-$ARCH.dmg"
CLI_ZIP="$DIST/solidcraft-cli-$VERSION-macos-$ARCH.zip"
+if [ -n "$BUILD_ONLY" ]; then
+ case "$BUILD_ONLY" in
+ aarch64-apple-darwin | x86_64-apple-darwin) ;;
+ *) echo "unknown --build-only target $BUILD_ONLY" >&2; exit 2 ;;
+ esac
+ echo "==> SolidCraft $VERSION for macOS ($BUILD_ONLY, build only)"
+ (cd "$ROOT" && cargo build --release --locked -p solidcraft -p solidcraft-cli --target "$BUILD_ONLY")
+ exit 0
+fi
+
echo "==> SolidCraft $VERSION for macOS ($ARCH)"
if [ "$SKIP_BUILD" = 0 ]; then
args=()
@@ -73,12 +167,29 @@ copy_docs "$APP/Contents/Resources/Licenses"
sed -e "s/@VERSION@/$VERSION/g" -e "s/@SHORT_VERSION@/$SHORT_VERSION/g" "$ROOT/assets/platforms/macos/Info.plist.in" >"$APP/Contents/Info.plist"
plutil -lint "$APP/Contents/Info.plist"
printf 'APPL????' >"$APP/Contents/PkgInfo"
-# Ad-hoc signature over the whole bundle (Apple silicon refuses unsigned code). Nested code is
-# signed first: the bundle signature refuses an unsigned helper in Contents/MacOS.
-codesign --force --sign - --timestamp=none --identifier "$MACOS_BUNDLE_ID-cli" "$APP/Contents/MacOS/solidcraft-cli"
-codesign --force --sign - --timestamp=none "$APP"
+# Signature over the whole bundle. Nested code is signed first: the bundle signature refuses an
+# unsigned helper in Contents/MacOS. The entitlements go on the bundle (they apply to the main
+# executable): the 3D mouse driver is loaded by the app, not by the CLI.
+sign_code "$APP/Contents/MacOS/solidcraft-cli" "$MACOS_BUNDLE_ID-cli"
+sign_code "$APP" "" "$SCRIPT_DIR/entitlements.plist"
codesign --verify --strict --deep --verbose=2 "$APP"
+if [ -n "$SIGN_IDENTITY" ]; then
+ # The hardened runtime and the library-validation exception must be on the signed app.
+ # Match a captured string, not a pipe: grep -q closing the pipe can SIGPIPE codesign under pipefail.
+ info="$(codesign --display --verbose=2 "$APP" 2>&1)"
+ grep -q 'flags=.*runtime' <<<"$info"
+ info="$(codesign --display --entitlements - --xml "$APP" 2>/dev/null)"
+ grep -q 'com.apple.security.cs.disable-library-validation' <<<"$info"
+fi
test -x "$APP/Contents/MacOS/solidcraft-cli" || { echo "solidcraft-cli is missing from $APP" >&2; exit 1; }
+if [ "$NOTARIZE" = 1 ]; then
+ # Staple the app itself, so a copy dragged out of the DMG opens offline too.
+ echo "==> notarizing $APP"
+ ditto -c -k --keepParent "$APP" "$WORK/SolidCraft-app.zip"
+ notarize "$WORK/SolidCraft-app.zip"
+ staple "$APP"
+ xcrun stapler validate "$APP"
+fi
# ---- DMG ---------------------------------------------------------------------------------------
echo "==> building $DMG"
@@ -119,18 +230,40 @@ codesign --verify --deep --verbose=2 "$MNT/SolidCraft.app"
"$MNT/SolidCraft.app/Contents/MacOS/SolidCraft" --version
hdiutil detach "$MNT"
+if [ -n "$SIGN_IDENTITY" ]; then
+ sign_code "$DMG"
+ codesign --verify --verbose=2 "$DMG"
+fi
+if [ "$NOTARIZE" = 1 ]; then
+ echo "==> notarizing $DMG"
+ notarize "$DMG"
+ staple "$DMG"
+ xcrun stapler validate "$DMG"
+ # Gatekeeper's verdict on the DMG and on the app as a user gets it.
+ spctl -a -t open --context context:primary-signature -vv "$DMG"
+ MNT="$(mktemp -d)"
+ hdiutil attach -readonly -nobrowse -mountpoint "$MNT" "$DMG"
+ spctl --assess --type execute --verbose=4 "$MNT/SolidCraft.app"
+ hdiutil detach "$MNT"
+fi
+
# ---- CLI ---------------------------------------------------------------------------------------
echo "==> building $CLI_ZIP"
CLI_DIR="$WORK/solidcraft-cli-$VERSION-macos-$ARCH"
mkdir -p "$CLI_DIR"
cp "$WORK/bin/solidcraft-cli" "$CLI_DIR/"
-codesign --force --sign - --timestamp=none --identifier "$MACOS_BUNDLE_ID-cli" "$CLI_DIR/solidcraft-cli"
+sign_code "$CLI_DIR/solidcraft-cli" "$MACOS_BUNDLE_ID-cli"
# Compatibility shim (docs/compatibility.md): the old CLI name forwards to solidcraft-cli.
cp "$WORK/bin/solvecraft-cli" "$CLI_DIR/"
-codesign --force --sign - --timestamp=none --identifier "$MACOS_BUNDLE_ID-cli-alias" "$CLI_DIR/solvecraft-cli"
+sign_code "$CLI_DIR/solvecraft-cli" "$MACOS_BUNDLE_ID-cli-alias"
copy_docs "$CLI_DIR"
rm -f "$CLI_ZIP"
ditto -c -k --keepParent "$CLI_DIR" "$CLI_ZIP"
+if [ "$NOTARIZE" = 1 ]; then
+ # A zip of bare executables can't be stapled; Gatekeeper finds the ticket online.
+ echo "==> notarizing $CLI_ZIP"
+ notarize "$CLI_ZIP"
+fi
"$WORK/bin/solidcraft-cli" --version
echo "==> done"
diff --git a/packaging/macos/signing.sh b/packaging/macos/signing.sh
new file mode 100755
index 0000000000..e66c8c9b71
--- /dev/null
+++ b/packaging/macos/signing.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+# Developer ID signing material for the macOS release job (docs/releasing.md, "macOS signing"):
+#
+# packaging/macos/signing.sh --setup import the certificate into a temporary keychain and write
+# the notarization API key; export MACOS_SIGN_IDENTITY and
+# APPLE_API_* to later steps through $GITHUB_ENV
+# packaging/macos/signing.sh --cleanup delete the keychain and the key
+#
+# --setup reads APPLE_CERTIFICATE_P12 (base64 .p12), APPLE_CERTIFICATE_PASSWORD, APPLE_API_KEY_P8,
+# APPLE_API_KEY_ID and APPLE_API_ISSUER from the environment, and needs RUNNER_TEMP, GITHUB_ENV and
+# GITHUB_STEP_SUMMARY. Without the certificate it does nothing, so forks and dry runs keep the
+# ad-hoc signature that package.sh falls back to.
+set -euo pipefail
+
+KEYCHAIN="${RUNNER_TEMP:-}/signing.keychain-db"
+API_KEY="${RUNNER_TEMP:-}/AuthKey.p8"
+
+setup() {
+ : "${RUNNER_TEMP:?}" "${GITHUB_ENV:?}" "${GITHUB_STEP_SUMMARY:?}"
+ local p12="${APPLE_CERTIFICATE_P12:-}" password="${APPLE_CERTIFICATE_PASSWORD:-}"
+ if [ -n "$p12$password" ] && { [ -z "$p12" ] || [ -z "$password" ]; }; then
+ echo "::error::only one of APPLE_CERTIFICATE_P12 and APPLE_CERTIFICATE_PASSWORD is set"
+ exit 1
+ fi
+ if [ -z "$p12" ]; then
+ echo "The APPLE_CERTIFICATE_* secrets aren't set: the app is ad-hoc signed and not notarized" | tee -a "$GITHUB_STEP_SUMMARY"
+ exit 0
+ fi
+ local keychain_password identity
+ keychain_password="$(openssl rand -hex 24)"
+ echo "::add-mask::$keychain_password"
+ printf '%s' "$p12" | base64 --decode >"$RUNNER_TEMP/certificate.p12"
+ security create-keychain -p "$keychain_password" "$KEYCHAIN"
+ security set-keychain-settings -lut 21600 "$KEYCHAIN"
+ security unlock-keychain -p "$keychain_password" "$KEYCHAIN"
+ security import "$RUNNER_TEMP/certificate.p12" -P "$password" -A -t cert -f pkcs12 -k "$KEYCHAIN"
+ security set-key-partition-list -S apple-tool:,apple: -s -k "$keychain_password" "$KEYCHAIN" >/dev/null
+ # shellcheck disable=SC2046 # the keychain paths have no spaces on the runner
+ security list-keychains -d user -s "$KEYCHAIN" $(security list-keychains -d user | tr -d '"')
+ rm -f "$RUNNER_TEMP/certificate.p12"
+ identity="$(security find-identity -v -p codesigning "$KEYCHAIN" | awk '/Developer ID Application/ { print $2; exit }')"
+ if [ -z "$identity" ]; then
+ echo "::error::the certificate has no Developer ID Application identity"
+ exit 1
+ fi
+ echo "MACOS_SIGN_IDENTITY=$identity" >>"$GITHUB_ENV"
+ if [ -n "${APPLE_API_KEY_P8:-}" ] && [ -n "${APPLE_API_KEY_ID:-}" ] && [ -n "${APPLE_API_ISSUER:-}" ]; then
+ printf '%s\n' "$APPLE_API_KEY_P8" >"$API_KEY"
+ {
+ echo "APPLE_API_KEY_PATH=$API_KEY"
+ echo "APPLE_API_KEY_ID=$APPLE_API_KEY_ID"
+ echo "APPLE_API_ISSUER=$APPLE_API_ISSUER"
+ } >>"$GITHUB_ENV"
+ echo "The macOS app is signed with the Developer ID and notarized" >>"$GITHUB_STEP_SUMMARY"
+ else
+ echo "The APPLE_API_* secrets aren't set: the macOS app is signed but not notarized" | tee -a "$GITHUB_STEP_SUMMARY"
+ fi
+}
+
+cleanup() {
+ : "${RUNNER_TEMP:?}"
+ security delete-keychain "$KEYCHAIN" || true
+ rm -f "$API_KEY" "$RUNNER_TEMP/certificate.p12"
+}
+
+case "${1:-}" in
+ --setup) setup ;;
+ --cleanup) cleanup ;;
+ *) echo "usage: $0 --setup | --cleanup" >&2; exit 2 ;;
+esac