【问题标题】:CFMessagePort and sandboxingCFMessagePort 和沙盒
【发布时间】:2012-03-27 12:03:59
【问题描述】:

我正在调整 MacOS 应用程序以使用沙盒。当我尝试在控制台中使用“拒绝 mach-lookup”消息调用 CFMessagePortCreateRemote 时,它​​使用了一个帮助应用程序(同一个包中的一个 exe)。

我可以看到com.apple.security.temporary-exception.mach-lookup.global-name 授权密钥可以解决这个问题,但这只是暂时的。

有没有办法在沙盒应用程序中通过 mach 端口实现两个应用程序之间的通信?

错误:

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'

【问题讨论】:

    标签: macos sandbox appstore-sandbox


    【解决方案1】:

    对于目标应用程序和帮助程序 exe:

    • 启用沙盒
    • 添加一个以你的 teamid 为前缀的公共组

      Z123456789.com.example.app-group

    使用您的 teamID ex 命名您的 mach 端口:

    Z123456789.com.example.app-group.Port_of_Kobe

    Apple documentation link

    【讨论】:

    • 请注意在创建 Mach 端口字符串时在 App Group ID 末尾添加额外的 .Port_of_Kobe 字符串!很重要。您不能只使用您的应用组 ID。
    【解决方案2】:

    CFMessagePortCreateLocal 中使用错误的CFStringRef name 参数时,我对CFMessagePortCreateRunLoopSource 的调用崩溃了。

    我使用的是我的应用组的名称,XXXYYYZZZZ.MyAppGroupName

    阅读Apple文档后,我将其更改为XXXYYYZZZZ.MyAppGroupName.someOtherString,并且崩溃消失了。

    Mach 端口名称必须以应用程序组标识符开头,后跟一个句点 (.),然后是您选择的名称。

    例如,如果您的应用程序组的名称是 Z123456789.com.example.app-group,您可以创建一个名为 Z123456789.com.example.app-group.Port_of_Kobe 的 Mach 端口。

    https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW24

    编辑:

    第二天早上,我尝试运行相同的代码。这一次,我遇到了崩溃 相同的附加".someOtherString",我昨晚使用。如果我更改为一些 other 字符串,它工作正常。这令人沮丧,因为我不知道该字符串何时/如何变得无效。

    线程 1:EXC_BAD_ACCESS(代码=1,地址=0x8)

    *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xcd07, name = 'XXXYYYZZZZ.MyAppGroupName.someOtherString'

    编辑 2:

    我再次遇到崩溃,这次是使用新字符串。除了我的 Xcode 构建文件夹中的版本之外,此问题可能与运行 /Applications/ 文件夹中的应用程序版本有关。

    端口名称在当前用户上下文中通常应该是唯一的;否则,您可能会遇到冲突。

    https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html

    【讨论】:

      猜你喜欢
      • 2014-08-18
      • 2023-04-07
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2014-10-03
      • 2011-05-31
      相关资源
      最近更新 更多