'Getting Code Signature Invalid when opening signed electron app

I'm dealing with this issue for almost two weeks. When I build my electron app in a DMG file, everything works perfect, but when I try to build the app in pkg format to upload to AppStore, I get the following error when opening:

EXC_CRASH (SIGKILL (Code Signature Invalid))

Full report: ( I don't get any idea reading this, but could you please tell me if there is anythin useful here?)

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Incident Identifier: 672ED1C3-54FF-4FC5-A724-C9BBFA324FF7
CrashReporter Key:   CEADA8D8-D266-0222-B9C5-DB0AB2503CC1
Hardware Model:      MacBookPro17,1
Process:             Foo [29494]
Path:                /Applications/Foo.app/Contents/MacOS/Foo
Identifier:          com.domain.foo
Version:             1.1.4 (1.1.4)
Code Type:           X86-64 (Native)
Role:                Default
Parent Process:      launchd [1]
Coalition:           com.domain.foo [17341]

Date/Time:           2021-12-12 16:55:38.4248 -0300
Launch Time:         2021-12-12 16:55:38.3359 -0300
OS Version:          macOS 12.0.1 (21A559)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGKILL (Code Signature Invalid))
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Termination Reason: CODESIGNING 1 

Triggered by Thread:  0

Thread 0 Crashed:
0                                       0x7ff7ffce2a2c 0x7ff7ffcdf000 + 14892


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x0000000000000000   x9: 0x0000000000000000  x10: 0x0000000000000000  x11: 0x0000000000000000
   x12: 0x0000000000000000  x13: 0x0000000000000000  x14: 0x0000000000000000  x15: 0x0000000000000000
   x16: 0x0000000000000000  x17: 0x0000000000000000  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x0000000000000000  x21: 0x0000000000000000  x22: 0x0000000000000000  x23: 0x0000000000000000
   x24: 0x0000000000000000  x25: 0x0000000000000000  x26: 0x0000000000000000  x27: 0x0000000000000000
   x28: 0x0000000000000000   fp: 0x0000000000000000   lr: 0x0000000000000000
    sp: 0x000000030a078bb0   pc: 0x00007ff7ffce2a2c cpsr: 0x00000000
   far: 0x0000000000000000  esr: 0x00000000  Address size fault

Binary Images:
    0x7ff7ffcdf000 -     0x7ff7ffd0efff  (*) <9f5d65be-d8d0-3979-bb05-e651a67e785c> ???

Error Formulating Crash Report:
dyld_process_snapshot_get_shared_cache failed

EOF

-----------
Full Report
-----------

{"app_name":"domain","timestamp":"2021-12-12 16:55:38.00 -0300","app_version":"1.1.4","slice_uuid":"ab3cb5d1-eb3f-388f-8c63-416a00da1aaa","build_version":"1.1.4","platform":0,"bundleID":"com.domain.foo","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 12.0.1 (21A559)","incident_id":"672ED1C3-54FF-4FC5-A724-C9BBFA324FF7","name":"domain"}
{
  "uptime" : 190000,
  "procLaunch" : "2021-12-12 16:55:38.3359 -0300",
  "procRole" : "Default",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro17,1",
  "procStartAbsTime" : 4762359345462,
  "coalitionID" : 17341,
  "osVersion" : {
    "train" : "macOS 12.0.1",
    "build" : "21A559",
    "releaseType" : "User"
  },
  "captureTime" : "2021-12-12 16:55:38.4248 -0300",
  "incident" : "672ED1C3-54FF-4FC5-A724-C9BBFA324FF7",
  "bug_type" : "309",
  "pid" : 29494,
  "procExitAbsTime" : 4762361449260,
  "translated" : true,
  "cpuType" : "X86-64",
  "procName" : "domain",
  "procPath" : "\/Applications\/domain.app\/Contents\/MacOS\/domain",
  "bundleInfo" : {"CFBundleShortVersionString":"1.1.4","CFBundleVersion":"1.1.4","CFBundleIdentifier":"com.domain.foo"},
  "storeInfo" : {"deviceIdentifierForVendor":"9A6CD500-5E91-538F-B2B1-0E710ECC4FDF","thirdParty":true},
  "parentProc" : "launchd",
  "parentPid" : 1,
  "coalitionName" : "com.domain.foo",
  "crashReporterKey" : "CEADA8D8-D266-0222-B9C5-DB0AB2503CC1",
  "wakeTime" : 3593,
  "sleepWakeUUID" : "1E5033D3-F82F-4C6E-B325-1B31313C3DBB",
  "sip" : "enabled",
  "isCorpse" : 1,
  "exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGKILL (Code Signature Invalid)"},
  "termination" : {"namespace":"CODESIGNING","flags":66,"code":1},
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":1348663,"threadState":{"x":[{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0}],"flavor":"ARM_THREAD_STATE64","lr":{"value":0},"cpsr":{"value":0},"fp":{"value":0},"sp":{"value":13053168560},"esr":{"value":0,"description":" Address size fault"},"pc":{"value":140703125350956,"matchesCrashFrame":1},"far":{"value":0}},"frames":[{"imageOffset":14892,"imageIndex":0}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 140703125336064,
    "size" : 196608,
    "uuid" : "9f5d65be-d8d0-3979-bb05-e651a67e785c",
    "name" : ""
  }
],
  "vmSummary" : "ReadOnly portion of Libraries: Total=816K resident=0K(0%) swapped_out_or_unallocated=816K(100%)\nWritable regions: Total=21.0M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=21.0M(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nSTACK GUARD                       56.0M        1 \nStack                             8176K        1 \nVM_ALLOCATE                       13.0M        4 \n__DATA                              80K        3 \n__DATA_CONST                        48K        1 \n__LINKEDIT                         240K        4 \n__TEXT                             624K        2 \nmapped file                        5.9G       29 \n===========                     =======  ======= \nTOTAL                              6.0G       45 \n",
  "legacyInfo" : {
  "threadTriggered" : {

  }
},
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "607844aa04477260f58a8077",
      "factorPackIds" : {
        "SIRI_MORPHUN_ASSETS" : "6103050cbfe6dc472e1c982a"
      },
      "deploymentId" : 240000066
    },
    {
      "rolloutId" : "60da5e84ab0ca017dace9abf",
      "factorPackIds" : {

      },
      "deploymentId" : 240000008
    },
    {
      "rolloutId" : "601d9415f79519000ccd4b69",
      "factorPackIds" : {
        "SIRI_TEXT_TO_SPEECH" : "6194416dea7ed64a7812a429"
      },
      "deploymentId" : 240000322
    },
    {
      "rolloutId" : "5fc94383418129005b4e9ae0",
      "factorPackIds" : {

      },
      "deploymentId" : 240000174
    },
    {
      "rolloutId" : "602ad4dac86151000cf27e46",
      "factorPackIds" : {
        "SIRI_DICTATION_ASSETS" : "61ae8d06da72d16a4beb762e"
      },
      "deploymentId" : 240000290
    },
    {
      "rolloutId" : "5ffde50ce2aacd000d47a95f",
      "factorPackIds" : {

      },
      "deploymentId" : 240000081
    }
  ],
  "experiments" : [

  ]
},
  "reportNotes" : [
  "dyld_process_snapshot_get_shared_cache failed"
]
}

Model: MacBookPro17,1, BootROM 7429.41.5, proc 8:4:4 processors, 8 GB, SMC 
Graphics: Apple M1, Apple M1, Built-In
Display: Color LCD, 2560 x 1600 Retina, Main, MirrorOff, Online
Memory Module: LPDDR4
AirPort: Wi-Fi, wl0: Sep 13 2021 21:06:59 version 18.20.310.14.7.8.119 FWID 01-9d72ee4a
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB31Bus
USB Device: USB31Bus
Thunderbolt Bus: MacBook Pro, Apple Inc.
Thunderbolt Bus: MacBook Pro, Apple Inc.

package.json

{
    "name": "domain",
    "version": "1.1.4",
    "description": "",
    "main": "main.js",
    "scripts": {
      "start": "electron ./",
      "start:prod": "set NODE_ENV=prod&& electron ./",
      "start:sbx": "set NODE_ENV=sbx&& electron ./",
      "rebuild": "electron-rebuild -f -w",
      "pack": "electron-builder --dir",
      "clean:dist": "rimraf dist",
      "clean:win": "rimraf windows_installer",
      "build:win": "npm run clean:win&& npm run dist&& node build_installer.js",
      "postinstall": "electron-builder install-app-deps",
      "dist": "npm run clean:dist&& electron-builder",
      "dist:prod": "set NODE_ENV=prod&& npm run dist",
      "create-installer-mac": "electron-installer-dmg ./dist/mac/domain.app domain --overwrite --background=./resources/background.png --icon=./resources/icons/domain.icns --out=./dist/mac/"
    },
    "build": {
      "appId": "com.domain.foo",
      "asar": true,
      "cscLink": "build/all-certs.p12",
      "cscKeyPassword": "mypassword",
      "asarUnpack": [
        "build",
        "resources"
      ],
      "mac": {
        "target": "mas"
      },
      "mas": {
        "type": "distribution",
        "category": "public.app-category.productivity",
        "entitlements": "build/entitlements.mas.plist"
      },
      "linux": {
        "target": [
          "AppImage",
          "deb"
        ]
      },
      "win": {
        "target": "nsis",
        "icon": "build/icon.ico"
      },
      "nsis": {
        "deleteAppDataOnUninstall": true,
        "oneClick": false
      }
    },
    "author": "domain <[email protected]>",
    "keywords": [],
    "devDependencies": {
      "appdmg": "^0.6.0",
      "electron": "^13.5.1",
      "electron-builder": "^22.11.7",
      "electron-installer-dmg": "^3.0.0",
      "electron-packager": "^15.2.0",
      "electron-rebuild": "^1.11.0",
      "electron-wix-msi": "^3.2.0",
      "exe-icon-extractor": "^1.0.8"
    },
    "dependencies": {
      "auto-launch": "^5.0.5",
      "axios": "^0.24.0",
      "chokidar": "^3.4.3",
      "electron-log": "^4.3.4",
      "form-data": "^3.0.0",
      "graceful-fs": "^4.2.6",
      "jwt-decode": "^2.2.0",
      "keytar": "^7.4.0",
      "lodash": "^4.17.21",
      "moment": "^2.29.1",
      "nedb": "^1.8.0",
      "nedb-promises": "^4.1.0",
      "os-locale": "^5.0.0",
      "rimraf": "^3.0.2",
      "user-home": "^2.0.0"
    }
  }
  

entitlements.mas.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.application-groups</key>
<string>teamid.com.domain.foo</string>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
</dict>
</plist>

And I building with npm run dist

If I run open -a foo.app I get:

-------------------------------------

Translated Report (Full Report Below)

Incident Identifier: 759B0A7D-D47E-4B91-A628-E86E95B44C05 CrashReporter Key: CEADA8D8-D266-0222-B9C5-DB0AB2503CC1 Hardware Model: MacBookPro17,1 Process: MyApp [3889] Path: /Users/USER/Documents/*/Foo.app/Contents/MacOS/Foo Identifier: com.foo.app Version: 1.1.10 (1.1.10) Code Type: X86-64 (Native) Role: Default Parent Process: launchd [1] Coalition: com.foo.app [1296]

Date/Time: 2022-01-04 22:14:57.5140 -0400 Launch Time: 2022-01-04 22:14:57.0231 -0400 OS Version: macOS 12.0.1 (21A559) Release Type: User Report Version: 104

Exception Type: EXC_CRASH (SIGKILL (Code Signature Invalid)) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Termination Reason: CODESIGNING 1

Highlighted by Thread: 0

Backtrace not available

No thread state (register information) available

Binary Images: Binary images description not available

Error Formulating Crash Report: dyld_process_info_create failed with 6 dyld_process_snapshot_get_shared_cache failed Failed to create CSSymbolicatorRef - corpse still valid ¯_(ツ)

EOF


Full Report

{"app_name":"Foo","timestamp":"2022-01-04 22:14:59.00 -0400","app_version":"1.1.10","slice_uuid":"ab3cb5d1-eb3f-388f-8c63-416a00da1aaa","build_version":"1.1.10","platform":0,"bundleID":"com.foo.app","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 12.0.1 (21A559)","incident_id":"759B0A7D-D47E-4B91-A628-E86E95B44C05","name":"Foo"} { "uptime" : 13000, "procLaunch" : "2022-01-04 22:14:57.0231 -0400", "procRole" : "Default", "version" : 2, "userID" : 501, "deployVersion" : 210, "modelCode" : "MacBookPro17,1", "procStartAbsTime" : 317693807800, "coalitionID" : 1296, "osVersion" : { "train" : "macOS 12.0.1", "build" : "21A559", "releaseType" : "User" }, "captureTime" : "2022-01-04 22:14:57.5140 -0400", "incident" : "759B0A7D-D47E-4B91-A628-E86E95B44C05", "bug_type" : "309", "pid" : 3889, "procExitAbsTime" : 317703364649, "translated" : true, "cpuType" : "X86-64", "procName" : "Foo", "procPath" : "/Users/USER/Documents/*/Foo.app/Contents/MacOS/Foo", "bundleInfo" : {"CFBundleShortVersionString":"1.1.10","CFBundleVersion":"1.1.10","CFBundleIdentifier":"com.foo.app"}, "storeInfo" : {"deviceIdentifierForVendor":"9A6CD500-5E91-538F-B2B1-0E710ECC4FDF","thirdParty":true}, "parentProc" : "launchd", "parentPid" : 1, "coalitionName" : "com.foo.app", "crashReporterKey" : "CEADA8D8-D266-0222-B9C5-DB0AB2503CC1", "wakeTime" : 160, "sleepWakeUUID" : "FAF63016-AF61-41CB-AEA8-1FF7BED9295E", "sip" : "enabled", "isCorpse" : 1, "exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGKILL (Code Signature Invalid)"}, "termination" : {"namespace":"CODESIGNING","flags":66,"code":1}, "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0}, "legacyInfo" : { "threadHighlighted" : 0 }, "trialInfo" : { "rollouts" : [ { "rolloutId" : "607844aa04477260f58a8077", "factorPackIds" : { "SIRI_MORPHUN_ASSETS" : "6103050cbfe6dc472e1c982a" }, "deploymentId" : 240000066 }, { "rolloutId" : "60da5e84ab0ca017dace9abf", "factorPackIds" : {

  },
  "deploymentId" : 240000008
},
{
  "rolloutId" : "602ad4dac86151000cf27e46",
  "factorPackIds" : {
    "SIRI_DICTATION_ASSETS" : "61ae8d06da72d16a4beb762e"
  },
  "deploymentId" : 240000290
},
{
  "rolloutId" : "5ffde50ce2aacd000d47a95f",
  "factorPackIds" : {

  },
  "deploymentId" : 240000090
},
{
  "rolloutId" : "601d9415f79519000ccd4b69",
  "factorPackIds" : {
    "SIRI_TEXT_TO_SPEECH" : "61c0d3122be4e338e11ae9e1"
  },
  "deploymentId" : 240000357
},
{
  "rolloutId" : "5fc94383418129005b4e9ae0",
  "factorPackIds" : {

  },
  "deploymentId" : 240000196
}

], "experiments" : [

] }, "reportNotes" : [ "dyld_process_info_create failed with 6", "dyld_process_snapshot_get_shared_cache failed", "Failed to create CSSymbolicatorRef - corpse still valid ¯\(ツ)_/¯" ] }

Model: MacBookPro17,1, BootROM 7429.41.5, proc 8:4:4 processors, 8 GB, SMC Graphics: Apple M1, Apple M1, Built-In Display: Color LCD, 2560 x 1600 Retina, Main, MirrorOff, Online Memory Module: LPDDR4 AirPort: Wi-Fi, wl0: Sep 13 2021 21:06:59 version 18.20.310.14.7.8.119 FWID 01-9d72ee4a Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports Network Service: Wi-Fi, AirPort, en0 USB Device: USB31Bus USB Device: USB31Bus Thunderbolt Bus: MacBook Pro, Apple Inc. Thunderbolt Bus: MacBook Pro, Apple Inc.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source