Debian Codegraph @

.github/workflows/mac-signing-rehearsal.yml

raw symbols SCIP
1 # Manual rehearsal of the macOS Developer ID signing path, using a throwaway
2 # self-signed certificate generated on the runner.
3 #
4 # Purpose: exercise everything the real signing path does EXCEPT notarization,
5 # which a self-signed cert cannot do (Apple's notary service requires a genuine
6 # Developer ID Application certificate). In particular this validates the one
7 # thing the ad-hoc path can never test: that under the hardened runtime, the
8 # `disable-library-validation` entitlement actually lets FontForge's embedded
9 # Python interpreter load a third-party (foreign-signed) C extension.
10 #
11 # This workflow is workflow_dispatch only: it never runs on push and never
12 # produces a release artifact. The bundle it builds is SELF-SIGNED and must
13 # NOT be distributed.
14 name: macOS signing rehearsal (self-signed)
15
16 on:
17 workflow_dispatch:
18 inputs:
19 foreign_test_package:
20 description: 'PyPI package with a compiled C extension, used to test disable-library-validation under the hardened runtime'
21 type: string
22 default: cffi
23
24 jobs:
25 rehearsal:
26 runs-on: macos-14
27 steps:
28 - uses: actions/checkout@v6
29 with:
30 path: repo
31
32 # --- Mirror the normal mac build (deps + build) -----------------------
33 - name: Install dependencies
34 run: |
35 brew install cairo coreutils fontconfig gettext giflib gtk+3 gtkmm3 jpeg libpng libspiro libtiff libtool libuninameslist python@3 wget woff2 --quiet
36 PREFIX=$GITHUB_WORKSPACE/target
37 echo "PREFIX=$PREFIX" >> $GITHUB_ENV
38 echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig" >> $GITHUB_ENV
39 echo "PATH=/usr/local/opt/ruby/bin:/usr/local/opt/gettext/bin:$PATH" >> $GITHUB_ENV
40 echo "PYTHONPATH=$PREFIX" >> $GITHUB_ENV
41 - name: Build FontForge
42 working-directory: repo
43 run: |
44 FFCONFIG="-DCMAKE_INSTALL_PREFIX=$PREFIX -DENABLE_FONTFORGE_EXTRAS=ON -DCMAKE_FIND_ROOT_PATH=/usr/local/opt/gettext"
45 mkdir build && pushd build && cmake -GNinja $FFCONFIG .. && popd
46 ninja -C build install
47
48 # --- Generate + import a throwaway self-signed code-signing cert -------
49 # Use the system (LibreSSL) openssl so the PKCS#12 is readable by the
50 # macOS keychain without needing the `-legacy` flag.
51 - name: Generate and import self-signed certificate
52 run: |
53 WORK="$RUNNER_TEMP/selfsign"
54 mkdir -p "$WORK"
55 cat > "$WORK/cert.conf" <<'EOF'
56 [req]
57 distinguished_name = dn
58 x509_extensions = v3
59 prompt = no
60 [dn]
61 CN = FontForge Rehearsal Self-Signed
62 [v3]
63 basicConstraints = critical,CA:FALSE
64 keyUsage = critical,digitalSignature
65 extendedKeyUsage = critical,codeSigning
66 EOF
67 /usr/bin/openssl req -x509 -newkey rsa:2048 -nodes \
68 -keyout "$WORK/key.pem" -out "$WORK/cert.pem" \
69 -days 2 -config "$WORK/cert.conf"
70 /usr/bin/openssl pkcs12 -export \
71 -inkey "$WORK/key.pem" -in "$WORK/cert.pem" \
72 -out "$WORK/cert.p12" -passout pass:rehearsal \
73 -name "FontForge Rehearsal Self-Signed"
74
75 KEYCHAIN="$RUNNER_TEMP/rehearsal.keychain-db"
76 security create-keychain -p actions "$KEYCHAIN"
77 security set-keychain-settings -lut 3600 "$KEYCHAIN"
78 security unlock-keychain -p actions "$KEYCHAIN"
79 security import "$WORK/cert.p12" -k "$KEYCHAIN" -P rehearsal -T /usr/bin/codesign
80 security set-key-partition-list -S apple-tool:,apple: -s -k actions "$KEYCHAIN"
81 security list-keychains -d user -s "$KEYCHAIN" $(security list-keychains -d user | tr -d '"')
82 security find-identity -v -p codesigning "$KEYCHAIN"
83
84 # Drive ffosxbuild.sh down its Developer ID branch (hardened runtime +
85 # entitlements). NOTE: we intentionally do NOT set any notary secrets,
86 # so notarization is correctly skipped -- self-signed cannot notarize.
87 echo "CODESIGN_IDENTITY=FontForge Rehearsal Self-Signed" >> "$GITHUB_ENV"
88
89 - name: Build App Bundle (hardened runtime, self-signed)
90 working-directory: repo/build
91 run: ninja macbundle
92
93 # --- Verify the signing we just rehearsed -----------------------------
94 - name: Verify signature and hardened runtime
95 working-directory: repo/build/osx
96 run: |
97 set -e
98 APP="$PWD/FontForge.app"
99 MAIN="$APP/Contents/Resources/opt/local/bin/fontforge"
100
101 echo "::group::codesign --verify (whole bundle)"
102 codesign --verify --strict --verbose=2 "$APP"
103 echo "::endgroup::"
104
105 echo "::group::Main executable signature (expect runtime flag + entitlements)"
106 codesign -dvvv "$MAIN" 2>&1 | grep -Ei 'Identifier|Signature|flags|TeamIdentifier' || true
107 codesign -d --entitlements :- "$MAIN" 2>&1 || true
108 echo "::endgroup::"
109
110 # Sanity: the hardened runtime flag must be present on the main exec.
111 if ! codesign -dvvv "$MAIN" 2>&1 | grep -q 'flags=.*runtime'; then
112 echo "ERROR: hardened runtime flag not set on main executable"
113 exit 1
114 fi
115
116 # Expected: spctl REJECTS a self-signed (un-notarized) bundle. This is
117 # not a failure of our signing -- only Developer ID + notarization
118 # passes spctl. We log it for visibility but do not fail on it.
119 echo "::group::spctl assessment (expected to be rejected)"
120 spctl -a -t exec -vv "$APP" || echo "(expected) spctl rejected the self-signed bundle"
121 echo "::endgroup::"
122
123 - name: Test embedded interpreter loads a foreign C extension
124 working-directory: repo/build/osx
125 env:
126 FOREIGN_PKG: ${{ inputs.foreign_test_package }}
127 run: |
128 set -e
129 APP="$PWD/FontForge.app"
130 FF="$APP/Contents/Resources/opt/local/bin/fontforge"
131 FFPY="$APP/Contents/MacOS/FFPython"
132 SITE="$RUNNER_TEMP/foreign-site"
133
134 # Install the foreign package AFTER the bundle was signed, so its .so
135 # keeps its own (non-our-identity) signature. Importing it through the
136 # hardened-runtime `fontforge` binary therefore exercises
137 # disable-library-validation: without that entitlement, Library
138 # Validation would reject the foreign-signed module.
139 "$FFPY" -m pip install --target "$SITE" --no-input "$FOREIGN_PKG"
140
141 cat > "$RUNNER_TEMP/import_test.py" <<EOF
142 import importlib, os, sys
143 print("python:", sys.version.split()[0])
144 import fontforge
145 print("fontforge:", fontforge.version())
146 # Import the package's compiled module to force a foreign dlopen.
147 mod = importlib.import_module("$FOREIGN_PKG")
148 print("imported foreign package:", mod.__name__, getattr(mod, "__file__", "?"))
149 # Confirm at least one compiled .so came from the foreign site dir.
150 so = [f for r,_,fs in os.walk("$SITE") for f in fs if f.endswith(".so")]
151 print("foreign .so files:", so or "(none -- pick a package with a C extension)")
152 EOF
153
154 echo "Running import test through the hardened-runtime fontforge binary..."
155 PYTHONPATH="$SITE" "$FF" -lang=py -script "$RUNNER_TEMP/import_test.py"
156 echo "OK: embedded interpreter loaded the foreign C extension under the hardened runtime."
157
158 - name: Rehearsal artifact (self-signed -- DO NOT DISTRIBUTE)
159 uses: actions/upload-artifact@v7
160 with:
161 name: macOS_appbundle_REHEARSAL_self-signed_DO_NOT_DISTRIBUTE
162 path: repo/build/osx/FontForge-*.dmg