可可沙箱嵌入式命令行不起作用

Posted

技术标签:

【中文标题】可可沙箱嵌入式命令行不起作用【英文标题】:cocoa sandbox embedded command line not work 【发布时间】:2014-05-10 05:36:17 【问题描述】:

我有一个第三方命令行工具,它从一个主要的 cocoa 应用程序启动,该应用程序将在 Mac App Store 中分发。

我需要沙箱第三方命令行工具,但是当我运行它(使用 NSTask)时,它崩溃并出现错误

“应用程序特定签名:容器对象初始化失败:未能获取应用程序 XXX 的 bundleid”

(在控制台中我可以看到以下错误消息)。 这是我在主可可应用程序中所做的:

NSTask* task          = [[NSTask alloc]init];
NSString* commandPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"command"];
task.launchPath       = commandPath;
[task setArguments:args];
[task launch];

每次我运行它时,都会出现一个弹出窗口,其中显示“OS X 需要修复您的库才能运行应用程序。输入您的密码以允许此操作。”我已经使用以下命令签署了这个命令行工具:

codesign --entitlements ./XXX.entitlements -s "3rd Party Mac Developer Application: XXX" ./commandlinetool 

为确保,我使用此命令仔细检查了它:

codesign --display --entitlements - ./commandlinetool  

这里是信息:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.files.downloads.read-write</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>
</dict>
</plist>

我也检查了这个命令:

codesign --display --verbose=4 XXX

并获得了以下信息:

Identifier=com.XXX.XXX.XXX
Format=Mach-O thin (x86_64)
CodeDirectory v=20100 size=75902 flags=0x0(none) hashes=3786+5 location=embedded
Hash type=sha1 size=20
CDHash=24fdcb9b5444a91f60xxxxx3a66bafa7030109e63fb1c
Signature size=4347
Authority=3rd Party Mac Developer Application: XXX
Authority=Apple Worldwide Developer Relations Certification Authority
Authority=Apple Root CA
Signed Time=May 10, 2014, 12:04:34 PM
Info.plist=not bound
Sealed Resources=none
Internal requirements count=1 size=216

我也尝试在命令行工具中添加一个info.plist文件,按本章步骤enter link description here但没有任何反应,Info.plist的结果仍然是“没有绑定”。

如何沙盒第三方命令行工具以及如何将info.plist文件添加到命令行工具?我错过了什么? 有人可以帮助我吗?任何帮助或指点将不胜感激。

【问题讨论】:

该应用是与 Mac App Store 一起分发的吗? 是的,有问题吗? 一点也不。我相应地更改了标签,以使您的问题更具可见性。 非常感谢!我真的很感激。 我建议查看其他 MAS 应用程序在类似情况下所做的示例。您是否使用任何应用程序来做您想做的事情? 【参考方案1】:

好久没注意到这个问题,还是有人问我怎么办。

根据 Apple 开发文档。

If your app employs a child process created with either the posix_spawn function or the NSTask class, you can configure the child process to inherit the sandbox of its parent. However, using a child process does not provide the security afforded by using an XPC service.

因此,您应该使用以下权利对您的嵌入式命令行进行签名:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.inherit</key>
    <true/>
</dict>
</plist>

现在您的应用可以运行了!

【讨论】:

以上是关于可可沙箱嵌入式命令行不起作用的主要内容,如果未能解决你的问题,请参考以下文章

SQLite 删除特定行不起作用

贝宝沙箱通知不起作用

java spring中的ipn沙箱不起作用

贝宝沙箱不起作用

引导表单组行不起作用

UIPickerView 选择行不起作用 ios7