GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tools: notarize bin/node in the darwin tarballs · nodejs/node@7d50f8a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Makefile
  • tools
    • osx-notarize.sh
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Makefile‎

Copy file name to clipboardExpand all lines: Makefile
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ endif
11901190
--resources $(MACOSOUTDIR)/installer/productbuild/Resources \
11911191
--package-path $(MACOSOUTDIR)/pkgs ./$(PKG)
11921192
SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" sh tools/osx-productsign.sh
1193-
sh tools/osx-notarize.sh $(FULLVERSION)
1193+
sh tools/osx-notarize.sh $(PKG)
11941194

11951195
.PHONY: pkg
11961196
pkg: $(PKG) ## Build the macOS installer for releases.
@@ -1337,6 +1337,7 @@ else
13371337
endif
13381338
ifeq ($(OSTYPE),darwin)
13391339
SIGN="$(CODESIGN_CERT)" PKGDIR="$(BINARYNAME)" sh tools/osx-codesign.sh
1340+
sh tools/osx-notarize.sh $(BINARYNAME)/bin/node
13401341
endif
13411342
tar -cf $(BINARYNAME).tar $(BINARYNAME)
13421343
$(RM) -r $(BINARYNAME)
Collapse file

‎tools/osx-notarize.sh‎

Copy file name to clipboard
+114-45Lines changed: 114 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,107 @@
11
#!/bin/sh
22

3-
# Notarize a generated node-<version>.pkg file as an Apple requirement for installation on macOS Catalina and later, as validated by Gatekeeper.
3+
# Notarize a macOS release artifact as an Apple requirement for running or
4+
# installing on macOS Catalina and later, as validated by Gatekeeper.
45
# Uses notarytool and requires Xcode >= 13.0.
6+
#
7+
# Usage: osx-notarize.sh <path>
8+
#
9+
# <path> ending in .pkg: the installer is submitted as is, assessed with
10+
# spctl and the notarization ticket is stapled to it.
11+
# any other <path>: a Mach-O binary, such as bin/node from the release
12+
# tarball. Apple only accepts zip, dmg or pkg submissions, so the binary
13+
# is zipped for the upload and the zip is discarded afterwards. A bare
14+
# binary cannot carry a stapled ticket; Gatekeeper fetches it online by
15+
# the code directory hash, so the binary itself is left untouched and the
16+
# published checksums do not change.
17+
#
18+
# For backwards compatibility a bare version id (for example v26.13.0) is
19+
# accepted and resolved to node-<version>.pkg.
520

6-
pkgid="$1"
21+
# The notarization ticket can take a while to become available from Apple's
22+
# servers after notarytool reports "Accepted", so retry with backoff.
23+
retry() {
24+
delay=15
25+
attempt=1
26+
while ! "$@"; do
27+
if [ "$attempt" -ge 6 ]; then
28+
return 1
29+
fi
30+
echo "Attempt $attempt failed, retrying in ${delay}s..."
31+
sleep "$delay"
32+
attempt=$((attempt + 1))
33+
delay=$((delay * 2))
34+
done
35+
}
36+
37+
submit() {
38+
echo "Submitting $1 for notarization..."
39+
if xcrun notarytool submit \
40+
--keychain-profile "NODE_RELEASE_PROFILE" \
41+
--wait \
42+
"$1"; then
43+
echo "Notarization $1 submitted successfully."
44+
else
45+
echo "Notarization $1 failed."
46+
return 1
47+
fi
48+
}
49+
50+
# Remove the upload zip on every exit path, including a failed ditto or an
51+
# interrupted build, the same way the dep_updaters scripts clean their
52+
# workspace. $zip is only set by notarize_binary.
53+
cleanup() {
54+
EXIT_CODE=$?
55+
if [ -n "$zip" ]; then
56+
rm -f "$zip"
57+
fi
58+
exit $EXIT_CODE
59+
}
60+
61+
notarize_pkg() {
62+
submit "$1" || exit 1
63+
64+
if ! retry xcrun spctl --assess --type install --context context:primary-signature --ignore-cache --verbose=2 "$1"; then
65+
echo "error: Signature will not be accepted by Gatekeeper!" 1>&2
66+
exit 1
67+
fi
68+
echo "Verification was successful."
69+
70+
if ! retry xcrun stapler staple "$1"; then
71+
echo "error: Stapling $1 failed." 1>&2
72+
exit 1
73+
fi
74+
echo "Stapler was successful."
75+
}
76+
77+
notarize_binary() {
78+
# ditto preserves the code signature and resource forks, which plain zip
79+
# does not, so it is the archiver Apple documents for notarization uploads.
80+
# The zip only exists for the upload and is removed by cleanup.
81+
zip="$1.notarize.zip"
82+
rm -f "$zip"
83+
if ! ditto -c -k --keepParent "$1" "$zip"; then
84+
echo "error: Could not create $zip for submission." 1>&2
85+
exit 1
86+
fi
87+
88+
submit "$zip" || exit 1
89+
rm -f "$zip"
90+
91+
# There is nothing to staple to a bare binary, so the only way to confirm
92+
# the ticket is live is to have codesign look it up. spctl cannot be used
93+
# here: it rejects command line tools with "does not seem to be an app".
94+
if ! retry codesign --verify --verbose=2 -R=notarized "$1"; then
95+
echo "error: $1 will not be accepted by Gatekeeper!" 1>&2
96+
exit 1
97+
fi
98+
echo "Verification was successful."
99+
}
7100

8-
if [ -z "$pkgid" ]; then
9-
echo "Usage: $0 <pkgid>"
101+
target="$1"
102+
103+
if [ -z "$target" ]; then
104+
echo "Usage: $0 <path-to-pkg-or-binary>"
10105
exit 1
11106
fi
12107

@@ -26,6 +121,16 @@ if [ -z "$NOTARIZATION_TEAM_ID" ]; then
26121
exit 0
27122
fi
28123

124+
# Legacy call form: a version id instead of a path.
125+
if [ ! -e "$target" ] && [ -e "node-$target.pkg" ]; then
126+
target="node-$target.pkg"
127+
fi
128+
129+
if [ ! -e "$target" ]; then
130+
echo "error: $target does not exist." 1>&2
131+
exit 1
132+
fi
133+
29134
echo "Notarization process is done with Notarytool."
30135

31136
if ! command -v xcrun notarytool > /dev/null
@@ -34,45 +139,9 @@ then
34139
exit 1
35140
fi
36141

37-
echo "Submitting node-$pkgid.pkg for notarization..."
38-
39-
xcrun notarytool submit \
40-
--keychain-profile "NODE_RELEASE_PROFILE" \
41-
--wait \
42-
"node-$pkgid.pkg"
43-
44-
if [ $? -eq 0 ]; then
45-
echo "Notarization node-$pkgid.pkg submitted successfully."
46-
else
47-
echo "Notarization node-$pkgid.pkg failed."
48-
exit 1
49-
fi
50-
51-
# The notarization ticket can take a while to become available from Apple's
52-
# servers after notarytool reports "Accepted", so retry with backoff.
53-
retry() {
54-
delay=15
55-
attempt=1
56-
while ! "$@"; do
57-
if [ "$attempt" -ge 6 ]; then
58-
return 1
59-
fi
60-
echo "Attempt $attempt failed, retrying in ${delay}s..."
61-
sleep "$delay"
62-
attempt=$((attempt + 1))
63-
delay=$((delay * 2))
64-
done
65-
}
66-
67-
if ! retry xcrun spctl --assess --type install --context context:primary-signature --ignore-cache --verbose=2 "node-$pkgid.pkg"; then
68-
echo "error: Signature will not be accepted by Gatekeeper!" 1>&2
69-
exit 1
70-
else
71-
echo "Verification was successful."
72-
fi
142+
trap cleanup INT TERM EXIT
73143

74-
if ! retry xcrun stapler staple "node-$pkgid.pkg"; then
75-
echo "error: Stapling node-$pkgid.pkg failed." 1>&2
76-
exit 1
77-
fi
78-
echo "Stapler was successful."
144+
case "$target" in
145+
*.pkg) notarize_pkg "$target" ;;
146+
*) notarize_binary "$target" ;;
147+
esac

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.