-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add managed MachO signing #108992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add managed MachO signing #108992
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
8901e5e
Add managed MachO signing
jtschuster 10fc3b3
Add managed MachO signing
jtschuster f2f8402
Merge branch 'MachSigning' of https://github.com/jtschuster/runtime i…
jtschuster 65a5a46
PR feedback, use different memory map file workaround
jtschuster c4425e9
Set enableMacOSCodesign=true in singlefile test
jtschuster 622b32c
Make NameBuffer constants more readable
jtschuster b69eafd
Update src/installer/managed/Microsoft.NET.HostModel/MachO/MachMagicE…
jtschuster ed70909
Update src/installer/managed/Microsoft.NET.HostModel/MachO/MachMagicE…
jtschuster 72e2ccf
PR Feedback:
jtschuster f92c9fa
Handle folders in the test data package
jtschuster 6784db8
PR feedback
jtschuster 4be00c2
Merge branch 'main' of https://github.com/dotnet/runtime into MachSig…
jtschuster 9c6b1bc
Fix test issues
jtschuster 5d8fe8e
Merge branch 'main' of https://github.com/dotnet/runtime into MachSig…
jtschuster 3a2351b
Move BinaryFormat files and Enums to separate folders and add notes a…
jtschuster 5eafdcb
Extend the AppHost template on disk before modifying and signing. Rem…
jtschuster f58574e
Use new MachO types in MachOUtils.cs
jtschuster b551128
Fix comments, use explicit types, update darc dependencies
jtschuster 58f5144
Use unsafe and sizeof instead of Marshal.SizeOf, fix format nits
jtschuster 4b77556
Rename signatureLC to signatureLoadCommand, remove unnecessary methods
jtschuster 4a1f133
Remove extra 'unsafe' blocks
jtschuster 78605a0
Revert arguments string change
jtschuster 272f0e5
Re-add ResourceUpdater to HostWriter
jtschuster 4a46cb9
Move CodeSignature to a nested type within MachObjectFile, move signa…
jtschuster e81000a
Merge branch 'main' of https://github.com/dotnet/runtime into MachSig…
jtschuster 3cdc7ce
Set file length after memory mapped file is disposed
jtschuster a18cb1b
Close memory mapped file in test signing method.
jtschuster 5320d1f
PR Feedback
jtschuster 71cadf4
Merge branch 'main' of https://github.com/dotnet/runtime into MachSig…
jtschuster 2a36163
Revert local testing change that enabled codesigning always.
jtschuster 980c755
Revert extra change in TestApp.cs
jtschuster 2cf8e41
Remove license from ThirdPartyNotices
jtschuster a8956b3
Add more definitions links, fix test nits.
jtschuster 0c7e528
Merge branch 'main' of https://github.com/dotnet/runtime into MachSig…
jtschuster 753c73c
Add comment explaining why the file must be written to create signatu…
jtschuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/installer/managed/Microsoft.NET.HostModel/AssemblyAttributes.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("Microsoft.NET.HostModel.Tests, PublicKey=" | ||
| + "00240000048000009400000006020000" | ||
| + "00240000525341310004000001000100" | ||
| + "b5fc90e7027f67871e773a8fde8938c8" | ||
| + "1dd402ba65b9201d60593e96c492651e" | ||
| + "889cc13f1415ebb53fac1131ae0bd333" | ||
| + "c5ee6021672d9718ea31a8aebd0da007" | ||
| + "2f25d87dba6fc90ffd598ed4da35e44c" | ||
| + "398c454307e8e33b8426143daec9f596" | ||
| + "836f97c8f74750e5975c64e2189f45de" | ||
| + "f46b2a2b1247adc3652bf5c308055da9")] | ||
|
|
||
| [assembly: InternalsVisibleTo("Microsoft.NET.HostModel.MachO.Tests, PublicKey=" | ||
jtschuster marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + "00240000048000009400000006020000" | ||
| + "00240000525341310004000001000100" | ||
| + "b5fc90e7027f67871e773a8fde8938c8" | ||
| + "1dd402ba65b9201d60593e96c492651e" | ||
| + "889cc13f1415ebb53fac1131ae0bd333" | ||
| + "c5ee6021672d9718ea31a8aebd0da007" | ||
| + "2f25d87dba6fc90ffd598ed4da35e44c" | ||
| + "398c454307e8e33b8426143daec9f596" | ||
| + "836f97c8f74750e5975c64e2189f45de" | ||
| + "f46b2a2b1247adc3652bf5c308055da9")] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/installer/managed/Microsoft.NET.HostModel/Bundle/Codesign.cs
jtschuster marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.DotNet.CoreSetup | ||
| { | ||
| public class Codesign | ||
| { | ||
| private const string CodesignPath = @"/usr/bin/codesign"; | ||
jtschuster marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public static bool IsAvailable => File.Exists(CodesignPath); | ||
|
|
||
| public static (int ExitCode, string StdErr) Run(string args, string appHostPath) | ||
| { | ||
| Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); | ||
| Debug.Assert(IsAvailable); | ||
|
|
||
| var psi = new ProcessStartInfo() | ||
| { | ||
| Arguments = $"{args} \"{appHostPath}\"", | ||
jtschuster marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FileName = CodesignPath, | ||
| RedirectStandardError = true, | ||
| UseShellExecute = false, | ||
| }; | ||
|
|
||
| using (var p = Process.Start(psi)) | ||
| { | ||
| if (p == null) | ||
| return (-1, "Failed to start process"); | ||
| p.WaitForExit(); | ||
| return (p.ExitCode, p.StandardError.ReadToEnd()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/installer/managed/Microsoft.NET.HostModel/MachO/BlobIndex.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.NET.HostModel.MachO; | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct BlobIndex | ||
| { | ||
| private readonly CodeDirectorySpecialSlot _slot; | ||
| private readonly uint _offset; | ||
|
|
||
| public CodeDirectorySpecialSlot Slot => (CodeDirectorySpecialSlot)((uint)_slot).ConvertFromBigEndian(); | ||
| public uint Offset => _offset.ConvertFromBigEndian(); | ||
|
|
||
| public BlobIndex(CodeDirectorySpecialSlot slot, uint offset) | ||
| { | ||
| _slot = (CodeDirectorySpecialSlot)((uint)slot).MakeBigEndian(); | ||
| _offset = offset.MakeBigEndian(); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/installer/managed/Microsoft.NET.HostModel/MachO/BlobMagic.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.NET.HostModel.MachO; | ||
|
|
||
| internal enum BlobMagic : uint | ||
| { | ||
| Requirements = 0xfade0c01, | ||
| CodeDirectory = 0xfade0c02, | ||
| EmbeddedSignature = 0xfade0cc0, | ||
| CmsWrapper = 0xfade0b01, | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/installer/managed/Microsoft.NET.HostModel/MachO/CmsBlob.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.NET.HostModel.MachO; | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct CmsWrapperBlob | ||
jtschuster marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| private BlobMagic _magic; | ||
| private uint _length; | ||
|
|
||
| public static CmsWrapperBlob Empty = new CmsWrapperBlob | ||
| { | ||
| _magic = (BlobMagic)((uint)BlobMagic.CmsWrapper).MakeBigEndian(), | ||
| _length = 8u.MakeBigEndian() | ||
| }; | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
src/installer/managed/Microsoft.NET.HostModel/MachO/CodeDirectoryFlags.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.NET.HostModel.MachO; | ||
|
|
||
| internal enum CodeDirectoryFlags : uint | ||
| { | ||
| Adhoc = 2, | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.