Ensure we sign the app bundle's main executable last
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 21 Nov 2024 16:36:25 +0000 (00:36 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 21 Nov 2024 16:36:25 +0000 (00:36 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
admin/osx/mac-crafter/Sources/Utils/Codesign.swift

index a3fb29d827531724d3c9fc756ee731a8b5bfb193..405371f1106d4636439a931e89bb4af1eaecde88 100644 (file)
@@ -145,6 +145,15 @@ func codesignClientAppBundle(
     }
 
     // Now we do the final codesign bit
+    let binariesDir = "\(clientContentsDir)/MacOS"
     print("Code-signing Nextcloud Desktop Client binaries...")
-    try recursivelyCodesign(path: "\(clientContentsDir)/MacOS/", identity: codeSignIdentity)
+    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)")
 }