Skip to content

Single-file: Facilitate signing on mac #3671

Closed

Description

@swaroop-sridhar

The single-file bundler adds additional contents (the apps's dependencies) at the end of the host-binary. This violates the strict consistency checks performed by codesign tool in MAC.

This work item track the effort to make the MAC bundle amenable to signing.

Original issue

dotnet/core#2811

Repro stesps

  1. Create a console "Hello world" executable on macOS.
  2. Generate a single file executable followed: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#single-file-executables
  3. run codesign with this exe.

You will get error message: main executable failed strict validation

If you add --no-strict option in codesign, you will get more detailed error messages:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: the __LINKEDIT segment does not cover the end of the file (can't be processed) in: /Volumes/Data/temp/HelloDotNet/bin/Release/netcoreapp3.0/osx.10.12-x64/publish/MacOS/HelloDotNet
/Volumes/Data/temp/HelloDotNet/bin/Release/netcoreapp3.0/osx.10.12-x64/publish/MacOS/HelloDotNet: the codesign_allocate helper tool cannot be found or used

Activity

  1. swaroop-sridhar commented on Jul 5, 2019

    @swaroop-sridhar
    ContributorAuthor

    Here's an attempt to fixup the __LINKEDIT section to accommodate the SingleFile blob at the end of the file: https://github.com/dotnet/core-setup/compare/master...swaroop-sridhar:mac?expand=1

    There are some downsides to doing this fixup:

    1. We cannot just fixup the size on disk, we also need to increase the vmsize of __LINKEDIT section (that is, the size as loaded). This means that the entire single-file is loaded by the OS loader when the program starts up.
      • In the current scheme of things, this leads to loading all the bundle contents twice, which is wasteful
      • When bundle contents are processed directly from disk, I think this scheme can be used more natuarally.
    2. With the above change, the __LINKEDIT section is loaded, and the program run successfully. However, the codesign tool is still not happy because it sees that there's no __LINKEDIT data that's referring to the content at the end of the section. Adding a reference to this data involves complex fixup with possible cascading effects for VM-addresses. The fixup for this is rather brittle without support from the native linker.
  2. MarcWils commented on Jul 17, 2019

    @MarcWils

    Any update about when this will be fixed or available in a preview release?

    We want to distribute a .NET Core 3.0 (preview6) app on MacOS. Code siging is mandatory.

    Is there any workaround to publish a signed .NET Core MacOS application?

  3. pavelkhrulev commented on Oct 21, 2019

    @pavelkhrulev

    @MarcWils Did you find some way to publish signed MacOS application?

  4. swaroop-sridhar commented on Oct 21, 2019

    @swaroop-sridhar
    ContributorAuthor

    @MarcWils @pavelkhrulev

    After dotnet/core-setup#8590, I have a better understanding of the file layout; I'll try out another fix for this issue to extend the __LINKEDIT section to cover the single-exe metadata.

  5. MarcWils commented on Oct 22, 2019

    @MarcWils

    @MarcWils Did you find some way to publish signed MacOS application?

    No I didn't. We reverted to building a native macOS app.

  6. swaroop-sridhar commented on Nov 2, 2019

    @swaroop-sridhar
    ContributorAuthor

    The MAC codesign tool places several restrictions on the layout

    • The __LINKEDIT segment must be the last one
    • The __LINKEDIT segment must cover the end of the file
    • All bytes in the __LINKEDIT segment are used by other linkage commands (ex: symbol/string table, dynamic load information etc)

    In order to circumvent these restrictions, I implemented a change that:

    • Extends the __LINKEDIT segment to include the bundle-data
    • Extends the string table to include all the bundle-data
      (that is, the bundle-data appear as strings to the loader/codesign tool).

    This method has certain limitations:

    • The bytes for the bundler may be unnecessarily loaded at startup
    • Tools that process the string table may be confused (although unindexed bytes in the string table should be OK)
    • The string table size is limited to 4GB. Bundles larger than that size cannot be accomodated by this utility.

    Here's a change that implements the fix: https://github.com/dotnet/core-setup/compare/master...swaroop-sridhar:macsign?expand=1

  7. swaroop-sridhar commented on Nov 2, 2019

    @swaroop-sridhar
    ContributorAuthor

    The fix is somewhat fragile in the long run, because it relies on the current behavior and checks implemented in codesign tool. It may break if the tool introduces more checks (ex: check that all bytes in the string table are referenced).

    The reliable way to generate an image is to use the native tool chain, but this involves substantial support in and beyond the .net core SDK.

  8. swaroop-sridhar commented on Nov 2, 2019

    @swaroop-sridhar
    ContributorAuthor
  9. swaroop-sridhar commented on Nov 2, 2019

    @swaroop-sridhar
    ContributorAuthor
  10. transferred this issue fromdotnet/core-setupon Jan 30, 2020
  11. added this to the 5.0 milestone on Jan 30, 2020
  12. rlalance commented on Feb 6, 2020

    @rlalance

    ok, this is going to block distribution of the app. Not cool.

  13. richardlalancetteyoui commented on Feb 6, 2020

    @richardlalancetteyoui

    What is my alternative to start sharing my dotnet 3.1 application with my clients?

  14. 32 remaining items

  15. vitek-karas commented on Nov 16, 2020

    @vitek-karas
    Member

    Related work in mono: mono/mono#17881

  16. self-assigned this
    on Jan 4, 2021
  17. ghost added
    in-pr
    on Jan 13, 2021
  18. ghost removed
    in-pr
    on Jan 14, 2021
  19. VSadov commented on Jan 14, 2021

    @VSadov
    Member

    Fixed in #46558

  20. Jmales commented on Jan 18, 2021

    @Jmales

    Hey guys. Not sure how to solve my problem, even after @VSadov fix.

    I have a singleFile bundle inside another App and when I sign the whole contents of the App it always fails in the singleFile bundle binary with the mentioned error. I'm failing to understand how to fix the issue...

  21. vitek-karas commented on Jan 18, 2021

    @vitek-karas
    Member

    As mentioned above by @VSadov this has been fixed for .NET 6 here: #46558. As far as I know we don't have plans to try to backport this to .NET 5.

  22. Jmales commented on Jan 18, 2021

    @Jmales

    This single-file was our workaround to: #46990

    Everything worked well, except for the signing of the SingleFile binary/bundle. Now we have no idea on how to tackle the problem at hands.

  23. VSadov commented on Jan 20, 2021

    @VSadov
    Member

    @Jmales - I am a bit confused. Did you have a problem signing a .NET 6.0 singlefile app?

    I wonder what was the SDK build number. The fix is fairly recent and it takes some time for a fix to make it from the development branch to the published installers. Maybe the fix was not there yet.

  24. rlalance commented on Jan 21, 2021

    @rlalance

    Really looking for this. This was a pretty major roadblock for my team.

  25. agocke commented on Jan 21, 2021

    @agocke
    Member

    Note that at the moment we have no plans to backport the fix to 5.0 -- are you OK with relying on a preview version or waiting for 6.0?

  26. VSadov commented on Feb 1, 2021

    @VSadov
    Member

    Recent 6.0 and 6.0.preview1 SDK builds should contain the fix.
    @richardlalancette - could you check if the fix is sufficient for your scenario?

  27. rlalance commented on Feb 1, 2021

    @rlalance

    I'm still on .net 5.0 here.

    Is the 6.0 preview SDK good enough for production apps?

  28. ghost locked as resolved and limited conversation to collaborators on Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

os-macos

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions