Add pure-Ruby ad-hoc signing#997
Open
MikeMcQuaid wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a pure-Ruby implementation of ad-hoc code signing for Mach-O binaries, removing the runtime dependency on invoking /usr/bin/codesign and enabling signature repair after Mach-O modifications (notably for Homebrew bottle relocation on Apple Silicon).
Changes:
- Introduces a new
MachO::CodeSigningimplementation that can build and embed XNU-compatibleSuperBlob/CodeDirectorysignatures (with SHA-256 and conditional SHA-1 agility). - Extends
MachOFileandFatFilewith#codesign!, updatingLC_CODE_SIGNATURE, resizing__LINKEDIT, and rebuilding fat slice offsets/sizes as needed. - Adds regression tests and documentation for ad-hoc signing behavior and compatibility boundaries.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/test_code_signing.rb | Adds regression coverage for unsigned/signed, fat/thin, metadata preservation, and failure-safety behaviors. |
| README.md | Documents the new pure-Ruby ad-hoc signing behavior, constraints, and scope. |
| lib/macho/macho_file.rb | Adds MachOFile#codesign! and improves low_fileoff handling for segments without sections. |
| lib/macho/load_commands.rb | Makes LC_CODE_SIGNATURE modifiable; adds serialization for LinkeditDataCommand and parsing helper for embedded signatures. |
| lib/macho/fat_file.rb | Adds FatFile#codesign! and a rebuild path for resized slices with updated offsets/sizes. |
| lib/macho/code_signing.rb | Implements code-signing structures (Blob/SuperBlob/CodeDirectory) and the ad-hoc signer logic. |
| lib/macho.rb | Switches MachO.codesign! to use the in-library implementation and normalizes error handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- remove the `/usr/bin/codesign` dependency from `MachO.codesign!` so Homebrew can repair bottle signatures on Apple Silicon using Ruby - parse and build XNU-compatible `SuperBlob` and `CodeDirectory` data so replacement signatures can retain security-relevant metadata - add or replace `LC_CODE_SIGNATURE`, resize `__LINKEDIT` and rebuild fat offsets so every page hash describes the final on-disk layout - use SHA-256 with legacy SHA-1 agility only for old deployment targets because XNU accepts the open `ld64` ad-hoc format without an identity - preserve non-linker requirements, entitlements, flags and runtime metadata while deliberately replacing linker-generated metadata - reject malformed `CodeDirectory` hash arrays before exposing offsets and validate before in-place writes to retain hard links and leave failed inputs unchanged - cover thin, fat, byte-order, metadata and macOS verification paths with regression tests, and document the compatibility boundaries
f1bfb7e to
d6a9829
Compare
Member
Author
|
Working as expected from Homebrew/brew#23047 |
1 task
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
/usr/bin/codesigndependency fromMachO.codesign!so Homebrew can repair bottle signatures on Apple Silicon using RubySuperBlobandCodeDirectorydata so replacement signatures can retain security-relevant metadataLC_CODE_SIGNATURE, resize__LINKEDITand rebuild fat offsets so every page hash describes the final on-disk layoutld64ad-hoc format without an identityFixes #262