尝试使用 codesign 命令进行沙箱时出错

Mik*_*012 5 macos sandbox codesign code-signing-entitlements

我正在尝试使用该codesign命令将我的 OS X 应用程序沙箱化(这是一个常见的 lisp 应用程序,不使用 Xcode)。我创建了一个非常基本的权利 plist,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<plist version="1.0">
    <dict>
        <key>com.apple.security.app-sandbox</key>
        <true/>
    </dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

我正在调用codesign命令:

codesign -s - -f --entitlements "/path/to/my/app/MyApp.app/Contents/entitlements.plist" "/path/to/my/app/MyApp.app/"
Run Code Online (Sandbox Code Playgroud)

但该命令返回以下错误:

/path/to/my/app/MyApp.app/Contents/entitlements.plist: cannot read entitlement data
Run Code Online (Sandbox Code Playgroud)

这个错误是否意味着我使用了错误的命令?如果是这样,命令有什么问题?

War*_*ton 1

Xcode 生成的 plist 是二进制格式,对于相当标准的有限沙箱设置如下所示:

<?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.developer.ubiquity-container-identifiers</key>
    <array>
        <string>$(TeamIdentifierPrefix)com.company.appanme</string>
    </array>
    <key>com.apple.developer.ubiquity-kvstore-identifier</key>
    <string>$(TeamIdentifierPrefix)com.company.appname</string>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.assets.movies.read-only</key>
    <true/>
    <key>com.apple.security.assets.music.read-only</key>
    <true/>
    <key>com.apple.security.assets.pictures.read-only</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>
    <key>com.apple.security.print</key>
    <true/>
    <key>com.apple.security.files.bookmarks.document-scope</key>
    <true/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

我所能建议的就是使用 Xcode 构建 plist 并手动删除那些您不需要的键。就你而言...

<?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.files.user-selected.read-write</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

我只是想知道!DOCTYPE签名工具是否因某种原因需要该元素,并且编码属性应该为大写。

我还留下了一些可能需要的键,即使正如你所说,它是一个基本的 Lisp 应用程序,特别com.apple.security.files.user-selected.read-write是可以让你的进程文件访问的键。

  • 你是对的,创建 plist 的方式应该没有任何区别,但在苹果游乐场玩意味着通常使用他们的玩具。:-( (2认同)