Repository navigation
Expand file tree
/
Copy pathmacos_sign_runner.sh
More file actions
executable file
·89 lines (80 loc) · 3.18 KB
/
Copy pathmacos_sign_runner.sh
File metadata and controls
executable file
·89 lines (80 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
set -euo pipefail
fail() {
printf 'macOS Runner signing failed: %s\n' "$*" >&2
exit 1
}
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
echo "usage: $0 <webcodex-runner> <code-signing-identity|-> [adhoc|self-signed|developer-id]" >&2
exit 2
fi
[ "$(uname -s)" = Darwin ] || fail "this helper is macOS-only"
runner="$1"
identity="$2"
mode="${3:-developer-id}"
if [ "$identity" = "-" ] && [ "$#" -eq 2 ]; then mode=adhoc; fi
case "$mode:$identity" in
adhoc:-) ;;
self-signed:-|developer-id:-) fail "stable signing requires an identity" ;;
self-signed:*|developer-id:*) ;;
*) fail "invalid signing mode/identity" ;;
esac
[ -f "$runner" ] && [ ! -L "$runner" ] && [ -x "$runner" ] || {
fail "Runner signing input is not an executable regular file: $runner"
}
[ -n "$identity" ] || fail "Runner signing identity is empty"
tmp_plist="$(mktemp "${TMPDIR:-/tmp}/webcodex-runner-info.XXXXXX")"
cleanup() { rm -f "$tmp_plist"; }
trap cleanup EXIT INT TERM
/usr/bin/otool -X -s __TEXT __info_plist "$runner" |
python3 -c '
import sys
out = bytearray()
for line in sys.stdin:
fields = line.split()
for word in fields[1:]:
out.extend(bytes.fromhex(word)[::-1])
end = out.find(b"</plist>")
if end < 0:
raise SystemExit("Runner __info_plist has no plist terminator")
sys.stdout.buffer.write(out[: end + len(b"</plist>")])
' > "$tmp_plist"
identifier="$(plutil -extract CFBundleIdentifier raw -o - "$tmp_plist" 2>/dev/null || true)"
[ "$identifier" = "dev.webcodex.runner" ] || {
fail "Runner embedded identifier is not dev.webcodex.runner"
}
for key in NSScreenCaptureUsageDescription NSAccessibilityUsageDescription; do
value="$(plutil -extract "$key" raw -o - "$tmp_plist" 2>/dev/null || true)"
[ -n "$value" ] || fail "Runner embedded Info.plist is missing $key"
done
if [ "$mode" = self-signed ]; then
bash "$(dirname "$0")/macos_sign_self_signed.sh" "$runner" dev.webcodex.runner "$identity"
elif [ "$identity" = "-" ]; then
codesign --force --sign - --identifier dev.webcodex.runner "$runner"
else
codesign --force --options runtime --timestamp --sign "$identity" --identifier dev.webcodex.runner "$runner"
fi
codesign --verify --strict --verbose=2 "$runner"
details="$(codesign -d --verbose=4 "$runner" 2>&1)"
printf '%s\n' "$details" | grep -Fxq 'Identifier=dev.webcodex.runner' || {
fail "signed Runner did not retain dev.webcodex.runner"
}
requirement="$(codesign -d -r- "$runner" 2>&1)"
if [ "$mode" = developer-id ]; then
case "$requirement" in
*'identifier "dev.webcodex.runner"'*) ;;
*) fail "formal Runner designated requirement lost its stable identifier" ;;
esac
printf '%s\n' "$details" | grep -q '^Authority=Developer ID Application:' || {
fail "formal Runner is not signed by a Developer ID Application identity"
}
team="$(printf '%s\n' "$details" | sed -n 's/^TeamIdentifier=//p' | head -n 1)"
[ -n "$team" ] && [ "$team" != "not set" ] || fail "formal Runner has no Developer ID team"
case "$requirement" in
*cdhash*) fail "formal Runner designated requirement is still cdhash-bound" ;;
esac
case "$requirement" in
*"anchor apple generic"*) ;;
*) fail "formal Runner designated requirement is not Apple-anchored" ;;
esac
fi