-
Notifications
You must be signed in to change notification settings - Fork 32
persist: re-sign mac app bundle #127
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
Draft
slice
wants to merge
8
commits into
moonlight-mod:main
Choose a base branch
from
slice:skip/darwin-persist
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4cd8c2c
persist: re-sign mac app bundle
slice 72a7af6
darwin: add module comment
slice 049b128
darwin: lowercase cert name
slice 80e1baf
darwin: move to `core/src/util`
slice 8025fae
persist: rename `persistAsar` to `hookUpdaterForPersistence`
slice 629be24
darwin: make codesigning utils sync, properly hook them
slice da5646e
injector: remove straggling `await`
slice 4d86b93
persist: make persist actually sync
slice 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { spawn } from "node:child_process"; | ||
| import Logger from "./util/logger"; | ||
|
|
||
| /** Flags that may be passed to `codesign(1)` regardless of action. */ | ||
| export interface SharedCodesignOptions { | ||
| verbosityLevel?: number; | ||
| } | ||
|
|
||
| /** Flags that may be passed to `codesign(1)` when signing a bundle. */ | ||
| export interface SigningOptions extends SharedCodesignOptions { | ||
| /** | ||
| * Sign nested code items (such as Helper (Renderer).app, Helper (GPU).app, etc.) | ||
| * | ||
| * `--deep` is technically Bad (https://forums.developer.apple.com/forums/thread/129980), | ||
| * but it works for now. | ||
| */ | ||
| deep?: boolean; | ||
|
|
||
| /** Steamrolls any existing code signature present in the bundle. */ | ||
| force?: boolean; | ||
|
|
||
| /** | ||
| * The name of the signing identity to use. Signing identities are automatically queried from the user's keychains. | ||
| * | ||
| * `-` specifies ad-hoc signing, which does not involve an identity at all | ||
| * and is used to sign exactly one instance of code. | ||
| */ | ||
| identity: "-" | (string & {}); // "& {}" prevents TS from unifying the literal. | ||
| } | ||
|
|
||
| const logger = new Logger("core/darwin"); | ||
|
|
||
| async function invokeCodesign(commandLineOptions: string[]) { | ||
| logger.debug("Invoking codesign with args:", commandLineOptions); | ||
| const codesignChild = spawn("/usr/bin/codesign", commandLineOptions, { stdio: "pipe" }); | ||
|
|
||
| codesignChild.on("spawn", () => { | ||
| logger.debug(`Spawned codesign (pid: ${codesignChild.pid})`); | ||
| }); | ||
| codesignChild.stdout.on("data", (data) => { | ||
| logger.debug("codesign stdout:", data.toString()); | ||
| }); | ||
| codesignChild.stderr.on("data", (data) => { | ||
| logger.debug("codesign stderr:", data.toString()); | ||
| }); | ||
|
|
||
| await new Promise<void>((resolve, reject) => { | ||
| codesignChild.on("exit", (code, signal) => { | ||
| if (signal == null && code === 0) { | ||
| logger.debug("codesign peacefully exited"); | ||
| resolve(); | ||
| } else { | ||
| const reason = code != null ? `code ${code}` : `signal ${signal}`; | ||
| reject(`codesign exited with ${reason}`); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function* generateSharedCommandLineOptions(options: SharedCodesignOptions): IterableIterator<string> { | ||
| if (options.verbosityLevel) yield "-" + "v".repeat(options.verbosityLevel); | ||
| } | ||
|
|
||
| export function sign(bundlePath: string, options: SigningOptions): Promise<void> { | ||
| // codesign -s <IDENTITY> [-v] [--deep] [--force] <PATH> | ||
| function* cliOptions(): IterableIterator<string> { | ||
| yield "-s"; | ||
| yield options.identity; | ||
|
|
||
| yield* generateSharedCommandLineOptions(options); | ||
| if (options.deep) yield "--deep"; | ||
| if (options.force) yield "--force"; | ||
|
|
||
| yield bundlePath; | ||
| } | ||
|
|
||
| return invokeCodesign(Array.from(cliOptions())); | ||
| } | ||
|
|
||
| export function verify(bundlePath: string, options: SharedCodesignOptions = {}): Promise<boolean> { | ||
| // codesign --verify [-v] <PATH> | ||
| function* cliOptions(): IterableIterator<string> { | ||
| yield "--verify"; | ||
| yield* generateSharedCommandLineOptions(options); | ||
| yield bundlePath; | ||
| } | ||
|
|
||
| return invokeCodesign(Array.from(cliOptions())).then( | ||
| () => true, | ||
|
|
||
| // we're conflating codesign(1) itself erroring and codesign(1) | ||
| // successfully returning that the bundle is invalid, because it'd exit in | ||
| // an error in either case, but that's probably OK | ||
| () => false | ||
| ); | ||
| } | ||
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
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.