Search code examples
objective-cmacossandboxcode-signingfinder

OSX Code Signature Invalid Exception when launched from Service on


MyApp is a sondboxed application with service feature for Files & Folders. Application works fine when i launched it normally but when it is invoked by Service it makes Finder sort of unresponsive for few seconds and than crashes

Console log gives the following crash

Process:               MyApp [4453]
Path:                  /Users/USER/Library/Developer/Xcode/Archives/2015-02-02/MyApp 02-02-2015 6.02 pm.xcarchive/Products/Applications/MyApp.app/Contents/MacOS/MyApp
Identifier:            com.Company.MyApp
Version:               ???
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           MyApp [4453]
User ID:               501

Date/Time:             2015-02-05 11:06:20.391 +0500
OS Version:            Mac OS X 10.10.2 (14C109)
Report Version:        11
Anonymous UUID:        2B8F252E-AA04-6181-CCE8-379AB367F5EE


Time Awake Since Boot: 3600 seconds

Crashed Thread:        0

Exception Type:        EXC_CRASH (Code Signature Invalid)
Exception Codes:       0x0000000000000000, 0x0000000000000000

kernel messages:

VM Regions Near 0x7fff799630a8 (cr2):
    __LINKEDIT             00007fff63e95000-00007fff63ea9000 [   80K] r--/rwx SM=COW  /usr/lib/dyld
--> Submap                 00007fff70000000-00007fff80000000 [256.0M] r--/rwx SM=PRV  process-only VM submap
    unused shlib __DATA    00007fff775f9000-00007fff79b9c000 [ 37.6M] rw-/rw- SM=COW  system shared lib __DATA not used by this process

Thread 0 Crashed:
0   dyld                            0x00007fff63e26000 _dyld_start + 0

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x000000000000000d  rbx: 0x0000000000000000  rcx: 0x0000000000000000  rdx: 0x0000000000000000
  rdi: 0x0000000000000000  rsi: 0x0000000000000000  rbp: 0x0000000000000000  rsp: 0x00007fff586a1aa8
   r8: 0x0000000000000000   r9: 0x0000000000000000  r10: 0x0000000000000000  r11: 0x0000000000000000
  r12: 0x0000000000000000  r13: 0x0000000000000000  r14: 0x0000000000000000  r15: 0x0000000000000000
  rip: 0x00007fff63e26000  rfl: 0x0000000000000201  cr2: 0x00007fff799630a8

Logical CPU:     0
Error Code:      0x020000f4
Trap Number:     133


Binary Images:
    0x7fff63e25000 -     0x7fff63e5b837  dyld (???) <65DCCB06-339C-3E25-9702-600A28291D0E> /usr/lib/dyld

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 5435
    thread_create: 0
    thread_set_state: 93

VM Region Summary:
ReadOnly portion of Libraries: Total=300K resident=300K(100%) swapped_out_or_unallocated=0K(0%)
Writable regions: Total=8416K written=0K(0%) resident=12K(0%) swapped_out=0K(0%) unallocated=8404K(100%)

REGION TYPE                      VIRTUAL
===========                      =======
STACK GUARD                        56.0M
Stack                              8192K
VM_ALLOCATE                           8K
__DATA                              228K
__LINKEDIT                           80K
__TEXT                              220K
mapped file                         872K
shared memory                         4K
===========                      =======
TOTAL                              65.4M

Which clearly states that it has some code signing issue

Exception Type: EXC_CRASH (Code Signature Invalid)

Next natural step should be to check its signing so i used spctl and it returns

$ sudo spctl --assess --verbose=4 /Applications/MyApp.app
/Applications/MyApp.app: accepted
source=Developer ID

I have no idea what is missing here.

Update


I created a new account on my machine and run the application, and did not get any codesign error/exception.

So it was something to do with the state of the user account or probably a bug with OSX.


Solution

  • I suspect your service was launching an unsigned copy of your app which was inside your development directory.

    Your first crash indicated that the path was:

    /Users/USER/Library/Developer/Xcode/Archives/2015-02-02/MyApp 02-02-2015 6.02 pm.xcarchive/Products/Applications/MyApp.app/Contents/MacOS/MyApp
    

    The spctl command you posted checked the signature on:

    /Applications/MyApp.app.  
    

    It may be that when you are logged in as the developer account, the service picks up the unsigned app from inside you Xcode/Archive directory and fails. A manual launch of the installed version in /Applications, or an spctl check on that version, would both succeed. The service might find the version in /Applications when using a different user account.