Skip to content
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

[stable-3.14] Only sign main executable at end (mac-crafter) #7549

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions admin/osx/mac-crafter/Sources/Utils/Codesign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func codesign(identity: String, path: String, options: String = defaultCodesignO
func recursivelyCodesign(
path: String,
identity: String,
options: String = defaultCodesignOptions
options: String = defaultCodesignOptions,
skip: [String] = []
) throws {
let fm = FileManager.default
guard let pathEnumerator = fm.enumerator(atPath: path) else {
Expand All @@ -71,6 +72,10 @@ func recursivelyCodesign(

for case let enumeratedItem as String in pathEnumerator {
let enumeratedItemPath = "\(path)/\(enumeratedItem)"
guard !skip.contains(enumeratedItemPath) else {
print("Skipping \(enumeratedItemPath)...")
continue
}
let isExecutableFile = try isExecutable(enumeratedItemPath)
guard isLibrary(enumeratedItem) || isAppExtension(enumeratedItem) || isExecutableFile else {
continue
Expand Down Expand Up @@ -147,13 +152,14 @@ func codesignClientAppBundle(
// Now we do the final codesign bit
let binariesDir = "\(clientContentsDir)/MacOS"
print("Code-signing Nextcloud Desktop Client binaries...")
try recursivelyCodesign(path: binariesDir, identity: codeSignIdentity)

guard let appName = clientAppDir.components(separatedBy: "/").last, clientAppDir.hasSuffix(".app") else {
throw AppBundleSigningError.couldNotEnumerate("Failed to determine main executable name.")
}

// Sign the main executable last
let mainExecutableName = String(appName.dropLast(".app".count))
try codesign(identity: codeSignIdentity, path: "\(binariesDir)/\(mainExecutableName)")
let mainExecutablePath = "\(binariesDir)/\(mainExecutableName)"
try recursivelyCodesign(path: binariesDir, identity: codeSignIdentity, skip: [mainExecutablePath])
try codesign(identity: codeSignIdentity, path: mainExecutablePath)
}
Loading