#!/usr/bin/env bash # Verify a signed Sprachmittler.app has the expected entitlements and, where required, # Hardened Runtime. Called by scripts/verify.sh and `make install` (T0.2, SP-10). # # Usage: scripts/check-signature.sh set -euo pipefail cd "$(dirname "$0")/.." APP="${1:-}" PROFILE="${2:-}" if [[ -z "$APP" || ! -d "$APP" ]]; then echo "usage: scripts/check-signature.sh " >&2 exit 2 fi case "$PROFILE" in debug | release | install) ;; *) echo "unknown profile '$PROFILE' (expected debug, release or install)" >&2 exit 2 ;; esac command -v jq >/dev/null || { echo "jq required (brew install jq)" >&2; exit 1; } codesign --verify --strict "$APP" tmp=$(mktemp "${TMPDIR:-/tmp}/sprachmittler-entitlements.XXXXXX") err=$(mktemp "${TMPDIR:-/tmp}/sprachmittler-entitlements-error.XXXXXX") trap 'rm -f "$tmp" "$err"' EXIT # codesign writes the entitlement plist to stdout. Capture stderr separately so a signing # failure is visible, without printing the executable path on every successful run. if ! codesign -d --entitlements :- "$APP" > "$tmp" 2> "$err"; then cat "$err" >&2 exit 1 fi if ! json=$(plutil -convert json -o - "$tmp"); then echo "✗ $PROFILE signature: no readable entitlements" >&2 exit 1 fi app_sandbox=$(jq -r 'if has("com.apple.security.app-sandbox") then .["com.apple.security.app-sandbox"] else "missing" end' <<<"$json") if [[ "$app_sandbox" != "false" ]]; then echo "✗ $PROFILE signature: com.apple.security.app-sandbox must be false (ADR-003)" >&2 exit 1 fi get_task_allow=$(jq -r 'if has("com.apple.security.get-task-allow") then .["com.apple.security.get-task-allow"] else "absent" end' <<<"$json") keys=$(jq -r 'keys[]' <<<"$json" | sort) if [[ "$PROFILE" == "debug" ]]; then # Xcode normally injects get-task-allow for the debugger, but the AC only requires that it # may be present. Accept either the exact sandbox-only set or sandbox + get-task-allow=true. if [[ "$get_task_allow" == "true" ]]; then expected=$'com.apple.security.app-sandbox\ncom.apple.security.get-task-allow' suffix=" + get-task-allow" elif [[ "$get_task_allow" == "absent" ]]; then expected='com.apple.security.app-sandbox' suffix="" else echo "✗ debug signature: get-task-allow must be true when present" >&2 exit 1 fi else expected='com.apple.security.app-sandbox' if [[ "$get_task_allow" != "absent" ]]; then echo "✗ $PROFILE signature: get-task-allow must not be present" >&2 exit 1 fi codesign -dvv "$APP" 2>&1 | grep -E 'flags=.*runtime' >/dev/null \ || { echo "✗ $PROFILE signature: Hardened Runtime flag is missing" >&2; exit 1; } suffix=" + Hardened Runtime" fi if [[ "$keys" != "$expected" ]]; then echo "✗ $PROFILE signature: unexpected entitlements" >&2 diff <(printf '%s\n' "$expected") <(printf '%s\n' "$keys") >&2 || true exit 1 fi echo "✓ $PROFILE signature: app-sandbox=false$suffix"