Repository navigation
signer: replace zsign with RCodesign #389
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
Changes from all commits
Commits
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,57 @@ | ||
| import Foundation | ||
| import RCodesign | ||
|
|
||
| public actor RCodesignSigner: Signer { | ||
|
|
||
| public enum Error: LocalizedError { | ||
| case badFilePath | ||
|
|
||
| public var errorDescription: String? { | ||
| switch self { | ||
| case .badFilePath: | ||
| return NSLocalizedString( | ||
| "signer_impl.error.bad_file_path", value: "A bad file path was provided", comment: "" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public init() {} | ||
|
|
||
| public func sign( | ||
| app: URL, | ||
| identity: SignerIdentity, | ||
| entitlementMapping: [URL: Data], | ||
| deep: Bool, | ||
| progress: @escaping @Sendable (Double?) -> Void | ||
| ) throws { | ||
| progress(nil) | ||
| guard app.isFileURL else { throw Error.badFilePath } | ||
| let root = app.standardizedFileURL.pathComponents | ||
| var entitlements: [String: Data] = [:] | ||
| for (bundle, value) in entitlementMapping { | ||
| let components = bundle.standardizedFileURL.pathComponents | ||
| guard bundle.isFileURL, components.starts(with: root) else { throw Error.badFilePath } | ||
| // RCodesign scopes entitlements by bundle-relative path: "" for the | ||
| // app itself and e.g. "PlugIns/Widget.appex" for an extension. Compare | ||
| // path components so a sibling such as App.app-copy cannot match App.app. | ||
| let path = components.dropFirst(root.count).joined(separator: "/") | ||
| guard entitlements[path] == nil else { throw Error.badFilePath } | ||
| entitlements[path] = value | ||
| } | ||
|
|
||
| let signingIdentity: RCodesign.Identity | ||
| switch identity { | ||
| case .real(let certificate, let privateKey): | ||
| signingIdentity = .certificate(certificateDER: try certificate.data(), privateKeyPEM: privateKey.data) | ||
| case .adhoc: | ||
| signingIdentity = .adHoc | ||
| } | ||
| try RCodesign.sign(at: app, identity: signingIdentity, options: .init(entitlements: entitlements, shallow: !deep)) | ||
| } | ||
|
|
||
| public func analyze(executable: URL) throws -> Data? { | ||
| try RCodesign.entitlements(at: executable) | ||
| } | ||
|
|
||
| } | ||
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,50 @@ | ||
| import Foundation | ||
| import Dependencies | ||
|
|
||
| public enum SignerIdentity: Sendable { | ||
| case real(Certificate, PrivateKey) | ||
| case adhoc | ||
| } | ||
|
|
||
| public protocol Signer: Sendable { | ||
| // entitlementMapping is [bundle url] -> [plist data] | ||
| func sign( | ||
| app: URL, | ||
| identity: SignerIdentity, | ||
| entitlementMapping: [URL: Data], | ||
| deep: Bool, | ||
| progress: @escaping @Sendable (Double?) -> Void | ||
| ) async throws | ||
|
|
||
| func analyze(executable: URL) async throws -> Data? | ||
| } | ||
|
|
||
| private enum SignerDependencyKey: DependencyKey { | ||
| static var liveValue: any Signer { RCodesignSigner() } | ||
| static var testValue: any Signer { UnimplementedSigner() } | ||
| } | ||
|
|
||
| extension DependencyValues { | ||
| public var signer: any Signer { | ||
| get { self[SignerDependencyKey.self] } | ||
| set { self[SignerDependencyKey.self] = newValue } | ||
| } | ||
| } | ||
|
|
||
| private struct UnimplementedSigner: Signer { | ||
| func sign( | ||
| app: URL, | ||
| identity: SignerIdentity, | ||
| entitlementMapping: [URL: Data], | ||
| deep: Bool, | ||
| progress: @escaping @Sendable (Double?) -> Void | ||
| ) async throws { | ||
| let operation: () throws -> Void = unimplemented() | ||
| try operation() | ||
| } | ||
|
|
||
| func analyze(executable: URL) async throws -> Data? { | ||
| let operation: () throws -> Data? = unimplemented() | ||
| return try operation() | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: xtool-org/xtool
Length of output: 2716
Script executed:
Repository: xtool-org/xtool
Length of output: 2137
Script executed:
Repository: xtool-org/xtool
Length of output: 1878
Script executed:
Repository: xtool-org/xtool
Length of output: 2894
Script executed:
Repository: xtool-org/xtool
Length of output: 1571
Script executed:
Repository: xtool-org/xtool
Length of output: 2151
Script executed:
Repository: xtool-org/xtool
Length of output: 2577
Script executed:
Repository: xtool-org/xtool
Length of output: 1659
Compare bundle paths by filesystem identity, not by case-sensitive components.
RCodesignSigner.signcomparesstandardizedFileURL.pathComponentsas strings. On a case-insensitive volume, an entitlement URL that names the app with different casing (for example/tmp/app.appfor/tmp/App.app) failscomponents.starts(with: root)and throwsError.badFilePath. The signer should accept such a URL when both paths resolve to the same bundle. The current production callers do not produce this input, so the failure is limited to direct callers of the publicSignerprotocol.