How to sandbox a command line tool?

后端 未结 4 1749
灰色年华
灰色年华 2020-12-25 08:17

I\'ve a simple unix tool made by me that launches the main cocoa app from a shell.

I need to sandbox it but when I run it, it crashes with error \"Illegal instructio

相关标签:
4条回答
  • 2020-12-25 08:39

    I was having this exact problem, and it went away when I added an embedded Info.plist.

    Try these clang flags (assuming you have info.plist in the build directory):

    -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker info.plist

    0 讨论(0)
  • 2020-12-25 08:43

    Is the console application launched directly from console or is it called from a main sandboxed application? I received a similar error when trying to sandbox some binaries and I was just able to make it work by using only the below entitlements:

    <dict>                                                                                                                                                                       
      <key>com.apple.security.app-sandbox</key>                                                                                                                                  
      <true/>                                                                                                                                                                    
      <key>com.apple.security.inherit</key>                                                                                                                                      
      <true/>                                                                                                                                                                    
    </dict> 
    

    Of course, after that you can only call the binary from a parent process that is already sandboxed (that is why I asked how your binary was called :)).

    0 讨论(0)
  • 2020-12-25 08:53

    It seems if you sign an executable with com.apple.security.inherit it can only be called by another application that is already sandboxed. So you can't call it from cmdline anymore after you ran codesign.

    0 讨论(0)
  • 2020-12-25 09:05

    While @Nick Moore's answer is perfectly fine, there's an option for this in today's Xcode under Packaging - Create Info.plist Section in Binary (CREATE_INFOPLIST_SECTION_IN_BINARY). All that's needed is setting thue to Yes.

    0 讨论(0)
提交回复
热议问题