question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code-sign and notarize all binaries on macOS

See original GitHub issue

Summary of the new feature/enhancement

Starting on macOS Catalina, all native binaries (command-line and GUI application), as well as all .pkg installer files, must be both code-signed and notarized by Apple, or the system will refuse to run them. Notarizing the .pkg file is easy, since it is already being signed. Notarizing the pwsh command-line tool, as well as the PowerShell.app wrapper application, will be harder. Note that while notarization is optional on macOS Mojave, it is still supported on that version. We do not (and, IMHO, should not) wait for Catalina’s release to start work on this important change.

Proposed technical implementation details

We will need to do the following:

  1. Code-sign the pwsh apphost binary with a Developer ID certificate. For notarization to succeed, we must also enable Hardened Runtime on that binary by passing the -o runtime flag to the signing tool. We must also use an entitlements file (the correct contents of which are attached at the end of this issue), or else Hardened Runtime will disallow the binary from jitting code or loading third-party dynamic libraries.
  2. Code-sign all *.dylib files with the Developer ID certificate that is used to sign the apphost binary. No other special steps are required here.
  3. Code-sign the *.app launcher with the same Developer ID certificate, and enable Hardened Runtime on it as well. While no entitlements are required for the launcher app, we must rewrite the launcher’s main executable (which is currently a shell script) in Objective-C, as the macOS code signing process does not support applications with shell scripts as main executables.
  4. Notarize all dylibs, the apphost binary, and the launcher app before including them into the installer. You can use xcrun altool and xcrun stapler to do this.
  5. Notarize the *.pkg installer once it has been signed.

Note that the code-signing process is completely independent of the .NET build process, and can easily be run on a .NET CLI-generated apphost binary, as long as the apphost binary in question has been stamped with the appropriate path before it is signed. (After signing, any changes to the binary will invalidate the signature and render the file un-runnable.)

Entitlements for pwsh tool

<?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/>
	<key>com.apple.security.cs.disable-library-validation</key>
	<true/>
</dict>
</plist>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
TravisEz13commented, Feb 2, 2023

@calebkiage Feel free to contact me on teams. I don’t believe anyone outside Microsoft can do this work.

0reactions
calebkiagecommented, Jan 30, 2023

@TravisEz13, I’ve recently added code signing and notarization to a .NET executable. Do you need assistance to add signing and notarization to PowerShell?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Signing/notarizing command line tools not build using Xcode
I have an Apple Developer certificate, and I've been able to codesign executables and shared libraries, and ship them off to be checked...
Read more >
Notarizing macOS software before distribution
Beginning in macOS 10.15, all software built after June 1, 2019, and distributed with Developer ID must be notarized. However, you aren't required...
Read more >
macos - Codesigning and notarizing executable file for OSX
I'm trying to codesign + notarize from the command line a small executable file generated out of a javascript file without success. This...
Read more >
How to code sign and notarize macOS audio plugins in CI
Rule #1 of notarization: Only notarize the outermost container — the zip , the pkg , the dmg .
Read more >
Code Signing and Notarization on macOS
Notarization is a kind of two-factor authentication for code signing - after you sign your software, you send a copy of it to...
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