main executable failed strict validation when signing binary on macOS

See original GitHub issue

I’m getting an error when code-signing a binary produced by pkg on macOS:

main executable failed strict validation

I couldn’t find much information about this on the web, but some causes can be (from https://developer.apple.com/library/content/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG309):

  • Your Mach-O executable does not conform to modern Mach-O layout rules
  • You may be using a third party development product that hasn’t been brought up to date, or post-processed your file in unsupported ways

Do you know thay may be causing this? codesign succeeds with other binaries.

Steps to reproduce:

git clone https://github.com/resin-io/etcher
cd etcher
make cli-develop
pkg --output etcher -t node6-macos-x64 lib/cli/etcher.js
codesign --sign "<identity>" -fv etcher

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:19
  • Comments:63 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
rmcveycommented, May 6, 2020

FWIW I’ve tried all of them and none of them generate executables that can be signed. I’m skipping the middle man now and just building Node from source (which is what all of these npm packages do), using webpack to compile my app to a single file and dropping it in lib/_third_party_main.js (there are a few C++/JS changes required). Anyway, now I can create an executable that can be properly signed and can add the executable to a .pkg installer and notarize.

Here’s my fork of Node that I’m using.

Like I said, I copy the file generated by webpack to lib/_third_party_main.js and run the following from the node source root:

mkargs=("-j4")
cpu_count=`sysctl hw.physicalcpu | grep -Eo '[0-9]'`

if [ "$cpu_count" -gt "4" ]; then
  mkargs=("-j8")
fi

configure_args=("--without-npm" "--without-inspector")
./configure "${configure_args[@]}" && make "${mkargs[@]}" > /dev/null

Which produces out/Release/node. That file is then moved to my-executable-name for signing. You will also need an entitlements.xml file so you can use the hardened runtime option, here’s mine:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
  </dict>
</plist>

Here is my codesign command:

codesign \
  --options runtime \
  --entitlements "$START/entitlements.xml" \
  --timestamp \
  --keychain "$KEYCHAIN" \
  --sign "$APP_CERT_NAME" \
  --force \
  --verbose \
  $out_exe
4reactions
derek-groupmailcommented, Mar 28, 2019

Nearly two years on from when this issue was first logged, I’m wondering can someone tell us please if there is any progress on this code signing issue with PKG? (I’m getting the same “main executable failed strict validation” issue.)

It’s not an option for us to distribute and install pkg components on client machines without having them code signed, which effectively renders PKG useless for our needs, as far as I can tell.

Is there a valid workaround for this issue? The suggestion by @gimdongwoo to change the extension allows you to code sign an app containing PKG components, but because they’re renamed, they can’t be executed as far as I can tell, as they’re no longer regarded as Unix executables but as documents (which presumably is why they’re now passing validation as the validation rules are different for documents vs executables?).

Is there a way to rename a pkg package and still execute it? In our case, our pkg components are installed inside the application package contents (i.e. show package contents, then within contents\services\<pkg packages here>) so we can’t rename those back to remove the extension after installing. Note that trying to execute them after renaming to include an extension pops up a mac dialogue saying there’s nothing associated with that extension, as the system thinks they’re ‘documents’ rather than an executables.

So, can you at least tell us please if a viable fix is going to be released soon? Or is this an issue that can’t or won’t be fixed, in which case our only option is to look for an alternative packaging system for our node components?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding OS X and iOS Code Signing to Hide Data
This is a talk about all three in regards to Apple OS X and iOS code signing. ... /Applications/Firefox.app: main executable failed strict...
Read more >
Technical Note TN2206: macOS Code Signing In Depth
codesign says my main executable failed strict validation. I wrote some data to the Mach-O file before signing. Is that allowed?
Read more >
macOS Catalina Notarization: "failed strict validation" error ...
I have packaged a Node.js script into an executable using pkg. With the macOS catalina release, all software should be notarized by Apple....
Read more >
MacOS build_apps and code signing, fails with main ...
... I wanted to make sure that I can build and distribute binaries. ... code signing, fails with main executable failed strict validation...
Read more >
Cannot build a macOS App with a provisioning profile
This is what Apple support says: codesign says my main executable failed strict validation. · Select “None” for the OS X build's “Provisioning...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found