From b5129de9dcbd3ab57e0e3d77a91ba8b0efacda54 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 4 Nov 2026 18:53:33 +1100 Subject: [PATCH 01/14] Verify bare binaries in macos_verify_code_signing CLIs ship bare Mach-O binaries, so `beeper/cli` and the Day One CLI each hand-roll this verification because the action only accepted `.app` and `.dmg`. Raised in https://github.com/beeper/cli/pull/56#discussion_r4455635831. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../macos/macos_verify_code_signing.rb | 19 ++++- spec/macos_verify_code_signing_spec.rb | 69 +++++++++++++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index e134e979c..25df1c7f4 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -20,8 +20,10 @@ def self.run(params) verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) when '.dmg' verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) + when '' + verify_binary(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) else - UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles and `.dmg` disk images") + UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles, `.dmg` disk images and bare binaries without an extension") end end @@ -58,6 +60,16 @@ def self.verify_disk_image(path:, expected_authority:, verify_notarization:) verify!("#{path} has no notarization ticket stapled to it", 'xcrun', 'stapler', 'validate', path) if verify_notarization end + # A bare binary can't carry a stapled ticket, so Gatekeeper's online lookup is the only + # notarization check available. It can lag a fresh submission. + # + def self.verify_binary(path:, expected_authority:, verify_notarization:) + UI.user_error!("#{path} is not signed at all") unless signed?(path) + verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil? + + verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'execute', '--verbose=2', path) if verify_notarization + end + # Distinguishes an artifact that carries no signature at all from one whose signature is # broken: the former is expected for a disk image, the latter always a failure. # @@ -104,6 +116,7 @@ def self.details - `.app` — the signature is valid and satisfies its designated requirement, Gatekeeper accepts the bundle for execution, and a notarization ticket is stapled to it. - `.dmg` — if the image is signed, the signature is valid (and can be checked against the expected authority) and Gatekeeper accepts opening it; when `verify_notarization` is true, a notarization ticket is stapled to the image. + - no extension, for a bare binary — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it for execution. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission. DETAILS end @@ -111,7 +124,7 @@ def self.available_options [ FastlaneCore::ConfigItem.new( key: :artifact_path, - description: 'The path, or list of paths, to the `.app` bundle(s) or `.dmg` disk image(s) to verify', + description: 'The path, or list of paths, to the `.app` bundle(s), `.dmg` disk image(s) or bare binaries to verify', type: Array, verify_block: proc do |value| UI.user_error!('`artifact_path` must be a String or an Array of Strings') unless value.all?(String) @@ -127,7 +140,7 @@ def self.available_options ), FastlaneCore::ConfigItem.new( key: :verify_notarization, - description: 'Whether to also assert that the artifact is accepted by Gatekeeper and has a notarization ticket stapled to it', + description: 'Whether to also assert that the artifact is accepted by Gatekeeper and, unless it is a bare binary, has a notarization ticket stapled to it', type: Boolean, default_value: true ), diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index 18a9988e8..d18b1afc4 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -197,6 +197,75 @@ def expect_stapler_validate(path, exitstatus: 0) end end + describe 'bare binaries' do + it 'verifies the signature and Gatekeeper acceptance, without expecting a stapled ticket' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_gatekeeper_assess_execute(path) + expect(Open3).not_to receive(:popen2e).with('xcrun', any_args) + + run_described_fastlane_action(artifact_path: path) + end + end + + it 'skips Gatekeeper when `verify_notarization` is `false`' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect(Open3).not_to receive(:popen2e).with('spctl', any_args) + + run_described_fastlane_action(artifact_path: path, verify_notarization: false) + end + end + + it 'passes when signed by the expected authority' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path, authority: authority) + + run_described_fastlane_action(artifact_path: path, expected_authority: authority, verify_notarization: false) + end + end + + it 'fails when signed by a different authority' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path, authority: 'Apple Development: Someone Else (ZZZZZ99999)') + + expect { run_described_fastlane_action(artifact_path: path, expected_authority: authority) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /is not signed by '#{Regexp.escape(authority)}'/) + end + end + + it 'fails when the signature is not valid' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path, exitstatus: 1, output: "#{path}: invalid signature (code or signature have been modified)\n") + + expect { run_described_fastlane_action(artifact_path: path) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /The code signature of .*test-cli is not valid/) + end + end + + # Unlike a disk image, there is no container whose contents could carry the signature instead. + it 'fails when it is not signed at all' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path, exitstatus: 1, output: "#{path}: code object is not signed at all\n") + + expect { run_described_fastlane_action(artifact_path: path) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli is not signed at all/) + end + end + + it 'fails when Gatekeeper rejects it' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_gatekeeper_assess_execute(path, exitstatus: 3) + + expect { run_described_fastlane_action(artifact_path: path) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli was rejected by Gatekeeper/) + end + end + end + it 'verifies every artifact when given a list of paths' do with_artifacts('One.app', 'Two.dmg') do |(app_path, dmg_path)| expect_codesign_verify_deep(app_path) From 69214438466f39f56ead687ed1d3f19f22a09396 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 4 Nov 2026 18:55:49 +1100 Subject: [PATCH 02/14] Assess bare binaries with spctl's open type `spctl --type execute` rejects every bare binary, notarized or not, with `the code is valid but does not seem to be an app`. The stubbed specs could not catch this; running against a real binary did. Checked on a notarized `beeper` binary from Buildkite: `--type open --context context:primary-signature` reports `Notarized Developer ID`, and rejects a Developer ID re-signed copy as `Unnotarized Developer ID`. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../actions/macos/macos_verify_code_signing.rb | 7 +++++-- spec/macos_verify_code_signing_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 25df1c7f4..326d0a131 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -63,11 +63,14 @@ def self.verify_disk_image(path:, expected_authority:, verify_notarization:) # A bare binary can't carry a stapled ticket, so Gatekeeper's online lookup is the only # notarization check available. It can lag a fresh submission. # + # `--type execute` is not an option here: it rejects any bare binary, notarized or not, with + # `the code is valid but does not seem to be an app`. + # def self.verify_binary(path:, expected_authority:, verify_notarization:) UI.user_error!("#{path} is not signed at all") unless signed?(path) verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil? - verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'execute', '--verbose=2', path) if verify_notarization + verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=2', path) if verify_notarization end # Distinguishes an artifact that carries no signature at all from one whose signature is @@ -116,7 +119,7 @@ def self.details - `.app` — the signature is valid and satisfies its designated requirement, Gatekeeper accepts the bundle for execution, and a notarization ticket is stapled to it. - `.dmg` — if the image is signed, the signature is valid (and can be checked against the expected authority) and Gatekeeper accepts opening it; when `verify_notarization` is true, a notarization ticket is stapled to the image. - - no extension, for a bare binary — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it for execution. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission. + - no extension, for a bare binary — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it as notarized. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission. DETAILS end diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index d18b1afc4..2a95d5ac2 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -201,7 +201,7 @@ def expect_stapler_validate(path, exitstatus: 0) it 'verifies the signature and Gatekeeper acceptance, without expecting a stapled ticket' do with_artifacts('test-cli') do |(path)| expect_codesign_verify(path) - expect_gatekeeper_assess_execute(path) + expect_gatekeeper_assess_open(path) expect(Open3).not_to receive(:popen2e).with('xcrun', any_args) run_described_fastlane_action(artifact_path: path) @@ -258,7 +258,7 @@ def expect_stapler_validate(path, exitstatus: 0) it 'fails when Gatekeeper rejects it' do with_artifacts('test-cli') do |(path)| expect_codesign_verify(path) - expect_gatekeeper_assess_execute(path, exitstatus: 3) + expect_gatekeeper_assess_open(path, exitstatus: 3) expect { run_described_fastlane_action(artifact_path: path) } .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli was rejected by Gatekeeper/) From 3ad7e2f734c1f6e8ff669058eee64af58922156d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 4 Nov 2026 18:56:37 +1100 Subject: [PATCH 03/14] Add `CHANGELOG.md` entry for bare binary support --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4755165ff..9831144a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ _None_ ### New Features -_None_ +- `macos_verify_code_signing` now verifies bare binaries, identified by having no file extension. [#782] ### Bug Fixes From d194c8a23b9bfe18e8262b3c3d0d00a5a37d0c6d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 6 Nov 2026 11:15:43 +1100 Subject: [PATCH 04/14] Move spctl type rationale next to the call The method doc comment now covers only what affects the caller. Why `spctl` runs with `--type open` is an implementation detail, so it sits inline. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../actions/macos/macos_verify_code_signing.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 326d0a131..7488a207e 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -60,16 +60,14 @@ def self.verify_disk_image(path:, expected_authority:, verify_notarization:) verify!("#{path} has no notarization ticket stapled to it", 'xcrun', 'stapler', 'validate', path) if verify_notarization end - # A bare binary can't carry a stapled ticket, so Gatekeeper's online lookup is the only - # notarization check available. It can lag a fresh submission. - # - # `--type execute` is not an option here: it rejects any bare binary, notarized or not, with - # `the code is valid but does not seem to be an app`. + # Notarization is checked online, since a bare binary can't carry a stapled ticket, so it can + # fail for a binary notarized only moments ago. # def self.verify_binary(path:, expected_authority:, verify_notarization:) UI.user_error!("#{path} is not signed at all") unless signed?(path) verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil? + # `--type execute` rejects any bare binary, notarized or not, as `does not seem to be an app`. verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=2', path) if verify_notarization end From 7dadb534e8ad506ba95e18eaeda92c947123915d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 6 Nov 2026 11:17:12 +1100 Subject: [PATCH 05/14] Add `verify_hardened_runtime` to code sign check A caller that verifies before notarizing passes `verify_notarization: false`, so nothing asserted the hardened runtime that notarization will later demand. beeper/cli#64 kept its own check for exactly this. The option defaults to `false` so existing callers are unaffected. Disk images are skipped with a warning rather than failed, because a list mixing an app with its `.dmg` is a normal call. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../macos/macos_verify_code_signing.rb | 40 ++++++--- spec/macos_verify_code_signing_spec.rb | 84 ++++++++++++++++++- 2 files changed, 109 insertions(+), 15 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 7488a207e..a8e176d56 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -17,11 +17,11 @@ def self.run(params) case File.extname(path).downcase when '.app' - verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) + verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) when '.dmg' - verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) + verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) when '' - verify_binary(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) + verify_binary(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) else UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles, `.dmg` disk images and bare binaries without an extension") end @@ -30,9 +30,9 @@ def self.run(params) UI.success("Verified #{paths.length} artifact(s)") end - def self.verify_app_bundle(path:, expected_authority:, verify_notarization:) + def self.verify_app_bundle(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:) UI.user_error!("#{path} is not signed at all") unless signed?(path, deep: true) - verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil? + verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: verify_hardened_runtime) return unless verify_notarization @@ -45,13 +45,15 @@ def self.verify_app_bundle(path:, expected_authority:, verify_notarization:) # signature` even when it carries a notarization ticket, so the stapled ticket is the only # check that means anything for an unsigned image. # - def self.verify_disk_image(path:, expected_authority:, verify_notarization:) + def self.verify_disk_image(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:) + UI.important("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if verify_hardened_runtime + # Said up front because `sh` logs a non-zero exit in red regardless of it being handled, # which reads as a broken build in the CI log of an otherwise passing job. UI.message("Checking whether #{path} is signed. Disk images usually aren't, so a `codesign` failure due to the image being unsigned is expected and tolerated (other signature failures will still fail).") if signed?(path) - verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil? + verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: false) verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=2', path) if verify_notarization else UI.important("#{path} is not signed — skipping its signature checks. We expect that the app it contains is the one carrying the signature.") @@ -63,9 +65,9 @@ def self.verify_disk_image(path:, expected_authority:, verify_notarization:) # Notarization is checked online, since a bare binary can't carry a stapled ticket, so it can # fail for a binary notarized only moments ago. # - def self.verify_binary(path:, expected_authority:, verify_notarization:) + def self.verify_binary(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:) UI.user_error!("#{path} is not signed at all") unless signed?(path) - verify_authority!(path: path, expected_authority: expected_authority) unless expected_authority.nil? + verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: verify_hardened_runtime) # `--type execute` rejects any bare binary, notarized or not, as `does not seem to be an app`. verify!("#{path} was rejected by Gatekeeper", 'spctl', '--assess', '--type', 'open', '--context', 'context:primary-signature', '--verbose=2', path) if verify_notarization @@ -93,11 +95,13 @@ def self.verify!(error_message, *command) sh(*command, error_callback: ->(_) { UI.user_error!(error_message) }) end - def self.verify_authority!(path:, expected_authority:) - details = sh('codesign', '--display', '--verbose=2', path) - return if details.include?("Authority=#{expected_authority}") + def self.verify_signature_details!(path:, expected_authority:, verify_hardened_runtime:) + return if expected_authority.nil? && !verify_hardened_runtime - UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}") + details = sh('codesign', '--display', '--verbose=2', path) + UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}") unless expected_authority.nil? || details.include?("Authority=#{expected_authority}") + # The flags list every option the code was signed with, e.g. `flags=0x10002(adhoc,runtime)`. + UI.user_error!("#{path} is not signed with the hardened runtime:\n#{details}") if verify_hardened_runtime && !details.match?(/flags=0x\h+\([^)]*\bruntime\b/) end ##################################################### @@ -118,6 +122,10 @@ def self.details the bundle for execution, and a notarization ticket is stapled to it. - `.dmg` — if the image is signed, the signature is valid (and can be checked against the expected authority) and Gatekeeper accepts opening it; when `verify_notarization` is true, a notarization ticket is stapled to the image. - no extension, for a bare binary — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it as notarized. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission. + + `verify_hardened_runtime` additionally checks that an app bundle or bare binary was signed with the hardened runtime, which notarization requires. + Use it to catch a missing hardened runtime before submitting for notarization, when `verify_notarization` has to be false. + It doesn't apply to disk images, which are skipped with a warning. DETAILS end @@ -139,6 +147,12 @@ def self.available_options optional: true, default_value: nil ), + FastlaneCore::ConfigItem.new( + key: :verify_hardened_runtime, + description: 'Whether to also assert that app bundles and bare binaries are signed with the hardened runtime. Disk images are skipped with a warning', + type: Boolean, + default_value: false + ), FastlaneCore::ConfigItem.new( key: :verify_notarization, description: 'Whether to also assert that the artifact is accepted by Gatekeeper and, unless it is a bare binary, has a notarization ticket stapled to it', diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index 2a95d5ac2..dbb6ed92c 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -29,8 +29,8 @@ def expect_codesign_verify(path, exitstatus: 0, output: '') expect_shell_command('codesign', '--verify', '--strict', '--verbose=2', path, exitstatus: exitstatus, output: output) end - def expect_codesign_display(path, authority:) - expect_shell_command('codesign', '--display', '--verbose=2', path, output: "Executable=#{path}\nAuthority=#{authority}\n") + def expect_codesign_display(path, authority: 'Developer ID Application: Automattic, Inc. (ABCDE12345)', flags: '0x10000(runtime)') + expect_shell_command('codesign', '--display', '--verbose=2', path, output: "Executable=#{path}\nCodeDirectory v=20500 size=1234 flags=#{flags} hashes=30+7 location=embedded\nAuthority=#{authority}\n") end def expect_gatekeeper_assess_execute(path, exitstatus: 0) @@ -130,6 +130,27 @@ def expect_stapler_validate(path, exitstatus: 0) .to raise_error(FastlaneCore::Interface::FastlaneError, /Test\.app has no notarization ticket stapled to it/) end end + + describe '`verify_hardened_runtime`' do + it 'passes when signed with the hardened runtime' do + with_artifacts('Test.app') do |(path)| + expect_codesign_verify_deep(path) + expect_codesign_display(path) + + run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) + end + end + + it 'fails when signed without the hardened runtime' do + with_artifacts('Test.app') do |(path)| + expect_codesign_verify_deep(path) + expect_codesign_display(path, flags: '0x0(none)') + + expect { run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /Test\.app is not signed with the hardened runtime/) + end + end + end end describe 'disk images' do @@ -195,6 +216,16 @@ def expect_stapler_validate(path, exitstatus: 0) run_described_fastlane_action(artifact_path: path, verify_notarization: false) end end + + it 'skips the hardened runtime check with a warning' do + with_artifacts('Test.dmg') do |(path)| + expect_codesign_verify(path) + expect(Open3).not_to receive(:popen2e).with('codesign', '--display', any_args) + expect(FastlaneCore::UI).to receive(:important).with(/Skipping the hardened runtime check for .*Test\.dmg/) + + run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) + end + end end describe 'bare binaries' do @@ -264,6 +295,55 @@ def expect_stapler_validate(path, exitstatus: 0) .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli was rejected by Gatekeeper/) end end + + describe '`verify_hardened_runtime`' do + it 'passes when signed with the hardened runtime' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path) + + run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) + end + end + + it 'passes when the hardened runtime is one of several flags' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path, flags: '0x10002(adhoc,runtime)') + + run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) + end + end + + it 'fails when signed without the hardened runtime' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path, flags: '0x0(none)') + + expect { run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli is not signed with the hardened runtime/) + end + end + + it 'still checks the authority' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path, authority: 'Apple Development: Someone Else (ZZZZZ99999)') + + expect { run_described_fastlane_action(artifact_path: path, expected_authority: authority, verify_hardened_runtime: true, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /is not signed by '#{Regexp.escape(authority)}'/) + end + end + + it 'does not inspect the signature details by default' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect(Open3).not_to receive(:popen2e).with('codesign', '--display', any_args) + + run_described_fastlane_action(artifact_path: path, verify_notarization: false) + end + end + end end it 'verifies every artifact when given a list of paths' do From 3b3d2221b48cfda6a1067fa76a0913e47dfb0f50 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 6 Nov 2026 11:17:12 +1100 Subject: [PATCH 06/14] Add `CHANGELOG.md` entry for hardened runtime check --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9831144a1..e4388d639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ _None_ ### New Features - `macos_verify_code_signing` now verifies bare binaries, identified by having no file extension. [#782] +- `macos_verify_code_signing` has a new `verify_hardened_runtime` option to check that app bundles and bare binaries are signed with the hardened runtime. [#782] ### Bug Fixes From f411b2ce8152322c4e6fbbb6e12a7671e7171c16 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sat, 7 Nov 2026 05:21:53 +1100 Subject: [PATCH 07/14] Delete confusing comment --- .../actions/macos/macos_verify_code_signing.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index a8e176d56..33a88fa92 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -62,9 +62,6 @@ def self.verify_disk_image(path:, expected_authority:, verify_hardened_runtime:, verify!("#{path} has no notarization ticket stapled to it", 'xcrun', 'stapler', 'validate', path) if verify_notarization end - # Notarization is checked online, since a bare binary can't carry a stapled ticket, so it can - # fail for a binary notarized only moments ago. - # def self.verify_binary(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:) UI.user_error!("#{path} is not signed at all") unless signed?(path) verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: verify_hardened_runtime) From 52be58dadf7e4fdcf1f6487d8296cf4efea6220c Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sat, 7 Nov 2026 06:12:58 +1100 Subject: [PATCH 08/14] Note hardened runtime skip on disk images quietly A correctly configured call that lists an app with its `.dmg` should not print a warning. The docs now state outright that notarization implies the hardened runtime, which is why the option is for verifying before submission. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../actions/macos/macos_verify_code_signing.rb | 10 +++++----- spec/macos_verify_code_signing_spec.rb | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 33a88fa92..f1dc115d2 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -46,7 +46,7 @@ def self.verify_app_bundle(path:, expected_authority:, verify_hardened_runtime:, # check that means anything for an unsigned image. # def self.verify_disk_image(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:) - UI.important("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if verify_hardened_runtime + UI.message("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if verify_hardened_runtime # Said up front because `sh` logs a non-zero exit in red regardless of it being handled, # which reads as a broken build in the CI log of an otherwise passing job. @@ -120,9 +120,9 @@ def self.details - `.dmg` — if the image is signed, the signature is valid (and can be checked against the expected authority) and Gatekeeper accepts opening it; when `verify_notarization` is true, a notarization ticket is stapled to the image. - no extension, for a bare binary — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it as notarized. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission. - `verify_hardened_runtime` additionally checks that an app bundle or bare binary was signed with the hardened runtime, which notarization requires. - Use it to catch a missing hardened runtime before submitting for notarization, when `verify_notarization` has to be false. - It doesn't apply to disk images, which are skipped with a warning. + `verify_hardened_runtime` checks that app bundles and bare binaries are signed with the hardened runtime. + Notarization requires it, so `verify_notarization` already covers it implicitly. Use this option to catch a missing hardened runtime before submitting for notarization. + It doesn't apply to disk images. DETAILS end @@ -146,7 +146,7 @@ def self.available_options ), FastlaneCore::ConfigItem.new( key: :verify_hardened_runtime, - description: 'Whether to also assert that app bundles and bare binaries are signed with the hardened runtime. Disk images are skipped with a warning', + description: 'Whether to also assert that app bundles and bare binaries are signed with the hardened runtime. Disk images are skipped', type: Boolean, default_value: false ), diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index dbb6ed92c..6d36559d4 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -217,11 +217,12 @@ def expect_stapler_validate(path, exitstatus: 0) end end - it 'skips the hardened runtime check with a warning' do + it 'skips the hardened runtime check' do with_artifacts('Test.dmg') do |(path)| expect_codesign_verify(path) expect(Open3).not_to receive(:popen2e).with('codesign', '--display', any_args) - expect(FastlaneCore::UI).to receive(:important).with(/Skipping the hardened runtime check for .*Test\.dmg/) + allow(FastlaneCore::UI).to receive(:message) + expect(FastlaneCore::UI).to receive(:message).with(/Skipping the hardened runtime check for .*Test\.dmg/) run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) end From 118364185e5b11d90f3004c449979c133b5d7b5d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 16 Nov 2026 11:55:21 +1100 Subject: [PATCH 09/14] Read signing flags and authority from their lines Both checks searched all of `codesign --display`'s output, which includes the `Executable=` path. A non-hardened binary under a directory named `flags=0x10000(runtime)` passed `verify_hardened_runtime`, and any authority that merely started with the expected one passed `expected_authority`. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../macos/macos_verify_code_signing.rb | 12 ++++++++--- spec/macos_verify_code_signing_spec.rb | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index f1dc115d2..7a990aa30 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -96,9 +96,15 @@ def self.verify_signature_details!(path:, expected_authority:, verify_hardened_r return if expected_authority.nil? && !verify_hardened_runtime details = sh('codesign', '--display', '--verbose=2', path) - UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}") unless expected_authority.nil? || details.include?("Authority=#{expected_authority}") - # The flags list every option the code was signed with, e.g. `flags=0x10002(adhoc,runtime)`. - UI.user_error!("#{path} is not signed with the hardened runtime:\n#{details}") if verify_hardened_runtime && !details.match?(/flags=0x\h+\([^)]*\bruntime\b/) + UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}") unless expected_authority.nil? || details.lines(chomp: true).include?("Authority=#{expected_authority}") + UI.user_error!("#{path} is not signed with the hardened runtime:\n#{details}") if verify_hardened_runtime && !code_directory_flags(details).include?('runtime') + end + + # The flags of the CodeDirectory line, e.g. `%w[adhoc runtime]` for `flags=0x10002(adhoc,runtime)`. + # The `Executable=` line can contain `flags=` too, as part of the path. + # + def self.code_directory_flags(details) + details[/^CodeDirectory\b.*?\bflags=0x\h+\(([^)]*)\)/, 1]&.split(',') || [] end ##################################################### diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index 6d36559d4..aad25ee9a 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -268,6 +268,16 @@ def expect_stapler_validate(path, exitstatus: 0) end end + it 'fails when the expected authority is only a prefix of the actual one' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path, authority: "#{authority} Evil") + + expect { run_described_fastlane_action(artifact_path: path, expected_authority: authority, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /is not signed by '#{Regexp.escape(authority)}'/) + end + end + it 'fails when the signature is not valid' do with_artifacts('test-cli') do |(path)| expect_codesign_verify(path, exitstatus: 1, output: "#{path}: invalid signature (code or signature have been modified)\n") @@ -326,6 +336,16 @@ def expect_stapler_validate(path, exitstatus: 0) end end + it 'ignores a `flags=` that is part of the path' do + with_artifacts('flags=0x10000(runtime)/test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display(path, flags: '0x0(none)') + + expect { run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli is not signed with the hardened runtime/) + end + end + it 'still checks the authority' do with_artifacts('test-cli') do |(path)| expect_codesign_verify(path) From 150c28253968c1b435de0993aa342cb5ffa56035 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 16 Nov 2026 11:56:42 +1100 Subject: [PATCH 10/14] Check every architecture of universal code `codesign --display` shows only the slice matching the host, so a universal binary or app whose other slice lacked the hardened runtime, or had a different authority, passed. Reproduced with a fat binary of a hardened arm64 slice and a non-hardened x86_64 one: it passed before this change and fails after it. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../macos/macos_verify_code_signing.rb | 18 +++++++- spec/macos_verify_code_signing_spec.rb | 43 ++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 7a990aa30..7e3e23f43 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -95,9 +95,23 @@ def self.verify!(error_message, *command) def self.verify_signature_details!(path:, expected_authority:, verify_hardened_runtime:) return if expected_authority.nil? && !verify_hardened_runtime + signature_details(path).each do |details| + UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}") unless expected_authority.nil? || details.lines(chomp: true).include?("Authority=#{expected_authority}") + UI.user_error!("#{path} is not signed with the hardened runtime:\n#{details}") if verify_hardened_runtime && !code_directory_flags(details).include?('runtime') + end + end + + # Each architecture of universal code carries its own signature, but `codesign --display` + # only shows the one matching this Mac's, so the others are displayed one at a time. + # + # @return [Array] The `codesign --display` output for each architecture. + # + def self.signature_details(path) details = sh('codesign', '--display', '--verbose=2', path) - UI.user_error!("#{path} is not signed by '#{expected_authority}':\n#{details}") unless expected_authority.nil? || details.lines(chomp: true).include?("Authority=#{expected_authority}") - UI.user_error!("#{path} is not signed with the hardened runtime:\n#{details}") if verify_hardened_runtime && !code_directory_flags(details).include?('runtime') + architectures = details[/^Format=.*Mach-O universal \(([^)]+)\)/, 1]&.split + return [details] if architectures.nil? + + architectures.map { |architecture| sh('codesign', '--display', '--verbose=2', '--arch', architecture, path) } end # The flags of the CodeDirectory line, e.g. `%w[adhoc runtime]` for `flags=0x10002(adhoc,runtime)`. diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index aad25ee9a..1201e72b3 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -29,8 +29,18 @@ def expect_codesign_verify(path, exitstatus: 0, output: '') expect_shell_command('codesign', '--verify', '--strict', '--verbose=2', path, exitstatus: exitstatus, output: output) end - def expect_codesign_display(path, authority: 'Developer ID Application: Automattic, Inc. (ABCDE12345)', flags: '0x10000(runtime)') - expect_shell_command('codesign', '--display', '--verbose=2', path, output: "Executable=#{path}\nCodeDirectory v=20500 size=1234 flags=#{flags} hashes=30+7 location=embedded\nAuthority=#{authority}\n") + def expect_codesign_display(path, authority: 'Developer ID Application: Automattic, Inc. (ABCDE12345)', flags: '0x10000(runtime)', format: 'Mach-O thin (arm64)', arch: nil) + arch_args = arch.nil? ? [] : ['--arch', arch] + expect_shell_command('codesign', '--display', '--verbose=2', *arch_args, path, output: "Executable=#{path}\nFormat=#{format}\nCodeDirectory v=20500 size=1234 flags=#{flags} hashes=30+7 location=embedded\nAuthority=#{authority}\n") + end + + # `codesign --display` shows the native slice of universal code, so these are its outputs + # for the universal file and then for each slice. + # + def expect_codesign_display_universal(path, x86_64_flags:, arm64_flags: '0x10000(runtime)', format: 'Mach-O universal (x86_64 arm64)') + expect_codesign_display(path, flags: arm64_flags, format: format) + expect_codesign_display(path, flags: x86_64_flags, format: format.sub('universal (x86_64 arm64)', 'thin (x86_64)'), arch: 'x86_64') + expect_codesign_display(path, flags: arm64_flags, format: format.sub('universal (x86_64 arm64)', 'thin (arm64)'), arch: 'arm64') end def expect_gatekeeper_assess_execute(path, exitstatus: 0) @@ -150,6 +160,16 @@ def expect_stapler_validate(path, exitstatus: 0) .to raise_error(FastlaneCore::Interface::FastlaneError, /Test\.app is not signed with the hardened runtime/) end end + + it 'fails when one architecture of a universal app lacks the hardened runtime' do + with_artifacts('Test.app') do |(path)| + expect_codesign_verify_deep(path) + expect_codesign_display_universal(path, x86_64_flags: '0x0(none)', format: 'bundle with Mach-O universal (x86_64 arm64)') + + expect { run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /Test\.app is not signed with the hardened runtime/) + end + end end end @@ -336,6 +356,25 @@ def expect_stapler_validate(path, exitstatus: 0) end end + it 'passes when every architecture of a universal binary has the hardened runtime' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display_universal(path, x86_64_flags: '0x10000(runtime)') + + run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) + end + end + + it 'fails when one architecture of a universal binary lacks the hardened runtime' do + with_artifacts('test-cli') do |(path)| + expect_codesign_verify(path) + expect_codesign_display_universal(path, x86_64_flags: '0x0(none)') + + expect { run_described_fastlane_action(artifact_path: path, verify_hardened_runtime: true, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli is not signed with the hardened runtime:\n.*thin \(x86_64\)/m) + end + end + it 'ignores a `flags=` that is part of the path' do with_artifacts('flags=0x10000(runtime)/test-cli') do |(path)| expect_codesign_verify(path) From 27e0da06834077ff680c9de2af35d6ee0d9ea800 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 16 Nov 2026 11:56:56 +1100 Subject: [PATCH 11/14] Stop passing the runtime flag to disk image checks `verify_disk_image` only took `verify_hardened_runtime` to log that it skips the check, while passing `false` on to the signature details, which read as a value being ignored. The skip is now logged where the artifact type is picked. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../actions/macos/macos_verify_code_signing.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 7e3e23f43..2e77c5944 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -19,7 +19,8 @@ def self.run(params) when '.app' verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) when '.dmg' - verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) + UI.message("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if params[:verify_hardened_runtime] + verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) when '' verify_binary(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) else @@ -45,9 +46,7 @@ def self.verify_app_bundle(path:, expected_authority:, verify_hardened_runtime:, # signature` even when it carries a notarization ticket, so the stapled ticket is the only # check that means anything for an unsigned image. # - def self.verify_disk_image(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:) - UI.message("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if verify_hardened_runtime - + def self.verify_disk_image(path:, expected_authority:, verify_notarization:) # Said up front because `sh` logs a non-zero exit in red regardless of it being handled, # which reads as a broken build in the CI log of an otherwise passing job. UI.message("Checking whether #{path} is signed. Disk images usually aren't, so a `codesign` failure due to the image being unsigned is expected and tolerated (other signature failures will still fail).") From 046f3205b0a8158afa4303b8486f96df9c098173 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 16 Nov 2026 11:57:39 +1100 Subject: [PATCH 12/14] Recognize bare binaries by Mach-O magic, not name A binary named like `tool-v1.2.3` has an extension as far as `File.extname` is concerned, so it was refused as an unknown artifact. The content identifies a bare binary regardless of its name, and still refuses an extensionless file that isn't one, such as a script. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- CHANGELOG.md | 2 +- .../macos/macos_verify_code_signing.rb | 23 +++++-- spec/macos_verify_code_signing_spec.rb | 66 ++++++++++++++----- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4388d639..a1029cb9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ _None_ ### New Features -- `macos_verify_code_signing` now verifies bare binaries, identified by having no file extension. [#782] +- `macos_verify_code_signing` now verifies bare Mach-O binaries, recognized by their content rather than their name. [#782] - `macos_verify_code_signing` has a new `verify_hardened_runtime` option to check that app bundles and bare binaries are signed with the hardened runtime. [#782] ### Bug Fixes diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 2e77c5944..5add31705 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -15,22 +15,31 @@ def self.run(params) UI.message("Verifying #{path}") - case File.extname(path).downcase - when '.app' + extension = File.extname(path).downcase + if extension == '.app' verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) - when '.dmg' + elsif extension == '.dmg' UI.message("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if params[:verify_hardened_runtime] verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) - when '' + elsif mach_o?(path) verify_binary(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) else - UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles, `.dmg` disk images and bare binaries without an extension") + UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles, `.dmg` disk images and Mach-O binaries") end end UI.success("Verified #{paths.length} artifact(s)") end + # Thin 32- and 64-bit, then universal, in both byte orders. + MACH_O_MAGIC_NUMBERS = %w[feedface feedfacf cefaedfe cffaedfe cafebabe cafebabf bebafeca bfbafeca].freeze + + # Recognizes a bare binary by its content, because its name can look like it has an extension, e.g. `tool-v1.2.3`. + # + def self.mach_o?(path) + File.file?(path) && MACH_O_MAGIC_NUMBERS.include?(File.binread(path, 4).to_s.unpack1('H*')) + end + def self.verify_app_bundle(path:, expected_authority:, verify_hardened_runtime:, verify_notarization:) UI.user_error!("#{path} is not signed at all") unless signed?(path, deep: true) verify_signature_details!(path: path, expected_authority: expected_authority, verify_hardened_runtime: verify_hardened_runtime) @@ -132,12 +141,12 @@ def self.details <<~DETAILS Verify that the given macOS artifacts are signed, and optionally notarized. - The checks that apply are picked from the artifact's extension: + The checks that apply are picked from the kind of artifact: - `.app` — the signature is valid and satisfies its designated requirement, Gatekeeper accepts the bundle for execution, and a notarization ticket is stapled to it. - `.dmg` — if the image is signed, the signature is valid (and can be checked against the expected authority) and Gatekeeper accepts opening it; when `verify_notarization` is true, a notarization ticket is stapled to the image. - - no extension, for a bare binary — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it as notarized. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission. + - a bare Mach-O binary, whatever its name — the signature is valid and can be checked against the expected authority, and Gatekeeper accepts it as notarized. A bare binary can't be stapled, so that acceptance relies on an online lookup that can lag a fresh submission. `verify_hardened_runtime` checks that app bundles and bare binaries are signed with the hardened runtime. Notarization requires it, so `verify_notarization` already covers it implicitly. Use this option to catch a missing hardened runtime before submitting for notarization. diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index 1201e72b3..69ffce7f9 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -21,6 +21,21 @@ def with_artifacts(*names) end end + # Like `with_artifacts`, but as files starting with the Mach-O magic number, which is what + # identifies a bare binary. + # + def with_binaries(*names) + in_tmp_dir do |tmp_dir| + paths = names.map do |name| + path = File.join(tmp_dir, name) + FileUtils.mkdir_p(File.dirname(path)) + File.binwrite(path, "\xCF\xFA\xED\xFE") + path + end + yield(paths) + end + end + def expect_codesign_verify_deep(path, exitstatus: 0, output: '') expect_shell_command('codesign', '--verify', '--deep', '--strict', '--verbose=2', path, exitstatus: exitstatus, output: output) end @@ -251,7 +266,7 @@ def expect_stapler_validate(path, exitstatus: 0) describe 'bare binaries' do it 'verifies the signature and Gatekeeper acceptance, without expecting a stapled ticket' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_gatekeeper_assess_open(path) expect(Open3).not_to receive(:popen2e).with('xcrun', any_args) @@ -260,8 +275,27 @@ def expect_stapler_validate(path, exitstatus: 0) end end + it 'recognizes a binary whose name looks like it has an extension' do + with_binaries('test-cli-v1.2.3') do |(path)| + expect_codesign_verify(path) + expect_gatekeeper_assess_open(path) + + run_described_fastlane_action(artifact_path: path) + end + end + + it 'fails on a file without an extension that is not a Mach-O binary' do + in_tmp_dir do |tmp_dir| + path = File.join(tmp_dir, 'test-script') + File.write(path, "#!/bin/sh\n") + + expect { run_described_fastlane_action(artifact_path: path) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /Don't know how to verify .*test-script/) + end + end + it 'skips Gatekeeper when `verify_notarization` is `false`' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect(Open3).not_to receive(:popen2e).with('spctl', any_args) @@ -270,7 +304,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'passes when signed by the expected authority' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path, authority: authority) @@ -279,7 +313,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'fails when signed by a different authority' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path, authority: 'Apple Development: Someone Else (ZZZZZ99999)') @@ -289,7 +323,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'fails when the expected authority is only a prefix of the actual one' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path, authority: "#{authority} Evil") @@ -299,7 +333,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'fails when the signature is not valid' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path, exitstatus: 1, output: "#{path}: invalid signature (code or signature have been modified)\n") expect { run_described_fastlane_action(artifact_path: path) } @@ -309,7 +343,7 @@ def expect_stapler_validate(path, exitstatus: 0) # Unlike a disk image, there is no container whose contents could carry the signature instead. it 'fails when it is not signed at all' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path, exitstatus: 1, output: "#{path}: code object is not signed at all\n") expect { run_described_fastlane_action(artifact_path: path) } @@ -318,7 +352,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'fails when Gatekeeper rejects it' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_gatekeeper_assess_open(path, exitstatus: 3) @@ -329,7 +363,7 @@ def expect_stapler_validate(path, exitstatus: 0) describe '`verify_hardened_runtime`' do it 'passes when signed with the hardened runtime' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path) @@ -338,7 +372,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'passes when the hardened runtime is one of several flags' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path, flags: '0x10002(adhoc,runtime)') @@ -347,7 +381,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'fails when signed without the hardened runtime' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path, flags: '0x0(none)') @@ -357,7 +391,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'passes when every architecture of a universal binary has the hardened runtime' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display_universal(path, x86_64_flags: '0x10000(runtime)') @@ -366,7 +400,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'fails when one architecture of a universal binary lacks the hardened runtime' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display_universal(path, x86_64_flags: '0x0(none)') @@ -376,7 +410,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'ignores a `flags=` that is part of the path' do - with_artifacts('flags=0x10000(runtime)/test-cli') do |(path)| + with_binaries('flags=0x10000(runtime)/test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path, flags: '0x0(none)') @@ -386,7 +420,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'still checks the authority' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect_codesign_display(path, authority: 'Apple Development: Someone Else (ZZZZZ99999)') @@ -396,7 +430,7 @@ def expect_stapler_validate(path, exitstatus: 0) end it 'does not inspect the signature details by default' do - with_artifacts('test-cli') do |(path)| + with_binaries('test-cli') do |(path)| expect_codesign_verify(path) expect(Open3).not_to receive(:popen2e).with('codesign', '--display', any_args) From 9d5bb5ca8c7ab9efe4ce70b66c62a89a797b08e0 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 17 Nov 2026 12:21:43 +1100 Subject: [PATCH 13/14] Detect Mach-O before dispatching by extension A bare binary named like a disk image took the `.dmg` path, where an unsigned artifact is tolerated. With `verify_notarization: false`, an unsigned binary then passed, `expected_authority` and `verify_hardened_runtime` notwithstanding. Raised by Copilot: https://github.com/wordpress-mobile/release-toolkit/pull/782#discussion_r4586490563 `.app` bundles are directories, so `mach_o?` is false for them and they still reach their own branch. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- .../actions/macos/macos_verify_code_signing.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb index 5add31705..ffbaf9d54 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/macos/macos_verify_code_signing.rb @@ -16,13 +16,13 @@ def self.run(params) UI.message("Verifying #{path}") extension = File.extname(path).downcase - if extension == '.app' + if mach_o?(path) + verify_binary(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) + elsif extension == '.app' verify_app_bundle(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) elsif extension == '.dmg' UI.message("Skipping the hardened runtime check for #{path}: it only applies to code, not to a disk image.") if params[:verify_hardened_runtime] verify_disk_image(path: path, expected_authority: params[:expected_authority], verify_notarization: params[:verify_notarization]) - elsif mach_o?(path) - verify_binary(path: path, expected_authority: params[:expected_authority], verify_hardened_runtime: params[:verify_hardened_runtime], verify_notarization: params[:verify_notarization]) else UI.user_error!("Don't know how to verify #{path}. Supported artifacts are `.app` bundles, `.dmg` disk images and Mach-O binaries") end From 7d15e31137e976c832827c575aaa29f5fb8a10c0 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 17 Nov 2026 12:21:43 +1100 Subject: [PATCH 14/14] Spec a Mach-O binary named like a disk image Fails on the previous dispatch order, where the unsigned binary passed as an unsigned `.dmg`. --- Generated with the help of Claude Code (Opus 5.5), https://code.claude.com --- spec/macos_verify_code_signing_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/macos_verify_code_signing_spec.rb b/spec/macos_verify_code_signing_spec.rb index 69ffce7f9..6650cdf8d 100644 --- a/spec/macos_verify_code_signing_spec.rb +++ b/spec/macos_verify_code_signing_spec.rb @@ -284,6 +284,15 @@ def expect_stapler_validate(path, exitstatus: 0) end end + it 'verifies a binary named like a disk image as a binary' do + with_binaries('test-cli.dmg') do |(path)| + expect_codesign_verify(path, exitstatus: 1, output: "#{path}: code object is not signed at all") + + expect { run_described_fastlane_action(artifact_path: path, verify_notarization: false) } + .to raise_error(FastlaneCore::Interface::FastlaneError, /test-cli\.dmg is not signed at all/) + end + end + it 'fails on a file without an extension that is not a Mach-O binary' do in_tmp_dir do |tmp_dir| path = File.join(tmp_dir, 'test-script')