I am adapting a MacOS application to use sandboxing. It uses a helper application (an exe in the same bundle) that fails when I try calling CFMessagePortCreateRemote with a 'deny mach-lookup' message in the console.
I can see the com.apple.security.temporary-exception.mach-lookup.global-name
entitlement key could solve this, but it is only temporary.
Is there a way to achieve a communication between two apps with a mach port in a sandboxed application?
Errors:
let port = CFMessagePortCreateLocal(nil, "XXXYYYZZZZ.MyAppGroupName" as CFString, Callback, nil, nil)
let runLoopSource = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, port, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)
*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x14807, name = 'XXXYYYZZZZ.MyAppGroupName'
For both targets app and helper exe :
Name your mach port using your teamID ex :
Apple documentation link
My call to
CFMessagePortCreateRunLoopSource
was crashing when using the wrongCFStringRef name
parameter inCFMessagePortCreateLocal
.I was using the name of my app group,
XXXYYYZZZZ.MyAppGroupName
.After reading the Apple documentation, I changed it to
XXXYYYZZZZ.MyAppGroupName.someOtherString
and the crash went away.https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW24
Edit:
The following morning, I'm trying to run the same code. This time, I'm getting the crash with the same appended
".someOtherString"
that I was using last night. It works fine if I change to some other string. This is frustrating, as I have no idea when/how that string becomes invalid.Edit 2:
I hit the crash again, this time with the new string. The issue is possibly related to running a version of the app from the
/Applications/
folder in addition to a version from my Xcode build folder.https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html