Working, signed, notarized app will not run on another system

I recently asked a question about how to sign manually without using xcode. I was provided a link about signing a Daemon with a Restricted Entitlement (https://developer.apple.com/documentation/xcode/signing-a-daemon-with-a-restricted-entitlement). This works, and I have manually signed everything in my DaemonInAppsClothing.app, and it runs. The problem, however, is that when I copy this to another mac running 10.15, it will not load. The output from the log stream is:

2022-03-02 10:53:50.370834-0700 0x910e     Activity    0x38f                128    0    amfid: (Security) SecTrustEvaluateIfNecessary
2022-03-02 10:53:50.373382-0700 0x910e     Activity    0xac80               128    0    amfid: (Security) SecTrustEvaluateIfNecessary
2022-03-02 10:53:50.375773-0700 0x910e     Default     0x0                  128    0    amfid: [com.apple.MobileFileIntegrity:amfid] Requirements for restricted entitlements failed to validate, error -67050, requirements: '<private>', error: (null)
2022-03-02 10:53:50.375806-0700 0x910e     Default     0x0                  128    0    amfid: [com.apple.MobileFileIntegrity:amfid] Restricted entitlements not validated, bailing out. Error: (null)
2022-03-02 10:53:50.375917-0700 0x910e     Default     0x0                  128    0    amfid: /Library/Application Support/DaemonInAppsClothing/DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing signature not valid: -67050
2022-03-02 10:53:50.375989-0700 0x91de     Default     0x0                  0      0    kernel: (AppleMobileFileIntegrity) AMFI: code signature validation failed.
2022-03-02 10:53:50.375999-0700 0x91de     Default     0x0                  0      0    kernel: (AppleMobileFileIntegrity) AMFI: bailing out because of restricted entitlements.
2022-03-02 10:53:50.376023-0700 0x91de     Default     0x0                  0      0    kernel: mac_vnode_check_signature: /Library/Application Support/DaemonInAppsClothing/DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing: code signature validation failed fatally: When validating /Library/Application Support/DaemonInAppsClothing/DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing:  Code has restricted entitlements, but the validation of its code signature failed.
Unsatisfied Entitlements:
2022-03-02 10:53:50.376053-0700 0x91de     Default     0x0                  0      0    kernel: proc 1674: load code signature error 4 for file "DaemonInAppsClothing"
2022-03-02 10:53:50.376528-0700 0x91df     Default     0x0                  0      0    kernel: (AppleSystemPolicy) ASP: Sleep interrupted, signal 0x100
2022-03-02 10:53:50.376541-0700 0x91df     Default     0x0                  0      0    kernel: (AppleSystemPolicy) ASP: Security policy would not allow process: 1674, /Library/Application Support/DaemonInAppsClothing/DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing
2022-03-02 10:53:50.376611-0700 0x91df     Default     0x0                  0      0    kernel: DaemonInAppsClothing[1674] Corpse allowed 1 of 5
2022-03-02 10:53:50.379313-0700 0x9118     Activity    0x6dd4               135    0    syspolicyd: (Security) SecTrustEvaluateIfNecessary
2022-03-02 10:53:50.381449-0700 0x9118     Activity    0x6dd5               135    0    syspolicyd: (Security) SecTrustEvaluateIfNecessary
2022-03-02 10:53:50.385619-0700 0x9118     Default     0x0                  135    0    syspolicyd: [com.apple.syspolicy.exec:default] GK evaluateScanResult: 2, PST: (vuid: 261312F5-D32F-4491-9E10-21D820BDAD32), (objid: 7500674), (team: AMLU8UA7F6), (id: (null)), (bundle_id: (null)), 0, 0, 1, 0, 8, 0
2022-03-02 10:53:50.385798-0700 0x8dd0     Error       0x0                  135    0    syspolicyd: [com.apple.syspolicy.exec:default] failed to call driver: 0x3
2022-03-02 10:53:50.385783-0700 0x8dd0     Default     0x0                  0      0    kernel: (AppleSystemPolicy) ASP: Could not find reference 17, process must have died
2022-03-02 10:53:50.387227-0700 0x8dd1     Default     0x0                  213    0    ReportCrash: Parsing corpse data for pid 1674
2022-03-02 10:53:50.387466-0700 0x8dd1     Default     0x0                  213    0    ReportCrash: Parsing corpse data for process DaemonInAppsClot [pid 1674]
2022-03-02 10:53:52.487053-0700 0x8dd1     Default     0x0                  213    0    ReportCrash: _dyld_process_info_create failed
2022-03-02 10:53:54.987270-0700 0x8dd1     Default     0x0                  213    0    ReportCrash: (CoreSymbolication) Failed to read dyld info for process 1674 (6)
2022-03-02 10:53:54.987969-0700 0x8dd1     Default     0x0                  213    0    ReportCrash: Failed to create CSSymbolicatorRef for <private>[1674]

I have tried to verify the entitlements, but I get this output:

Executable=/Library/Application Support/DaemonInAppsClothing/DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing
<?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.endpoint-security.client</key>
        <true/>
        <key>com.apple.security.cs.allow-jit</key>
        <true/>
</dict>
</plist>
sh-3.2# security cms -D -i DaemonInAppsClothing.app/Contents/embedded.provisionprofile
security: cert import failed: A default keychain could not be found.
security: problem decoding

Any help would be appreciated

sh-3.2# security cms -D …

This suggests that you’re doing things from a root shell. Is that because you’ve enabled the root account, logged in as root, and are doing everything from there? Or are you spinning up a root shell using sudo -s or similar techniques? I recommend against the latter because sudo only changes part of your execution context [1].

I have tried to verify the entitlements, but I get this output:

That’s problematic. When you use a restricted entitlement, like com.apple.developer.endpoint-security.client, you must also have an App ID entitlement so that the trusted execution system can match up your code with your provisioning profile. For more background on this, see What exactly is a provisioning profile?

Xcode should have added that entitlement for you. Indeed, Signing a Daemon with a Restricted Entitlement has code that prints the entitlements and an example of its output:

2021-08-04 16:24:10.979941+0100 DaemonInAppsClothing[50219:4886989] entitlements: {
    "com.apple.application-identifier" = "SKMME9E2Y8.com.example.apple-samplecode.DaemonInAppsClothing";
    "com.apple.developer.networking.custom-protocol" = 1;
    "com.apple.developer.team-identifier" = SKMME9E2Y8;
    "com.apple.security.get-task-allow" = 1;
}

Are you still building this code with Xcode? Or have you transitioned over to your own build system?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] For more details on execution contexts in macOS, see the Execution Contexts section of Technote 2083 Daemons and Agents.

  • I am using sudo -su
  • I did not add "com.apple.developer.team-identifier" to my entitlements.
  • I am using xcode to build and archive, but I am manually signing and notarizing. I created a disk image using a script I found in another of your posts: (Manual Code Signing Example)

Here is some more information on the executable:

#codesign -dv --verbose=4 ./DaemonInAppsClothing
Executable=/Library/Application Support/DaemonInAppsClothing/DaemonInAppsClothing.app/Contents/MacOS/DaemonInAppsClothing
Identifier=Fidelis.DaemonInAppsClothing
Format=app bundle with Mach-O thin (x86_64)
CodeDirectory v=20500 size=1032 flags=0x10000(runtime) hashes=21+7 location=embedded
VersionPlatform=1
VersionMin=786688
VersionSDK=786688
Hash type=sha256 size=32
CandidateCDHash sha256=8a7f854608607af4862cc81643c9a694e645b990
CandidateCDHashFull sha256=8a7f854608607af4862cc81643c9a694e645b990a283366dce26b3000f6bff05
Hash choices=sha256
CMSDigest=8a7f854608607af4862cc81643c9a694e645b990a283366dce26b3000f6bff05
CMSDigestType=2
Executable Segment base=0
Executable Segment limit=32768
Executable Segment flags=0x1
Page size=4096
CDHash=8a7f854608607af4862cc81643c9a694e645b990
Signature size=9003
Authority=Developer ID Application: Fidelis Cybersecurity, INC (AMLU8UA7F6)
Authority=Developer ID Certification Authority
Authority=Apple Root CA
Timestamp=Feb 28, 2022 at 10:12:08 AM
Info.plist entries=20
TeamIdentifier=AMLU8UA7F6
Runtime Version=12.1.0
Sealed Resources version=2 rules=13 files=944
Internal requirements count=1 size=64

So I think somehow it does know my identity, but something I changed recently won't let it run on 11.X. It now tells me I need version 12.1 or newer for this app.

I am using sudo -su

Do not do this as a matter of course. Our tools are set up so that they work when you log in as a normal user. If you then switch to a root shell you end up running the tools in a non-standard environment, which exposes you to all sorts of potential weirdness.

I am using Xcode to build and archive, but I am manually signing and notarizing.

Xcode should have set up your entitlements correctly. I recommend that you dump the entitlements of the program in the Xcode archive to see how Xcode did it.

Also remember that the code in your Xcode archive should be signed with an Apple Development identity. If you re-sign it with Developer ID, you must also apply a new profile. I go into this in some detail in Creating Distribution-Signed Code for Mac.

So I think somehow it does know my identity

What you showed there is not sufficient to confirm that. You also need to dump the entitlements (by adding --entitlements - to you command). The TeamIdentifier property in the code signature is important, but it’s the App ID in the entitlements that controls whether the system can find your provisioning profile.

It now tells me I need version 12.1 or newer for this app.

Check the deployment target in your Xcode project.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Where can I get these samples?

There isn’t a sample associated with that doc, but the instructions in the doc should be sufficient for you to create your own project from scratch.

when I switched out main.swift for my c++ code, and added in the dylib files, they do not end up in the archive

OK, those are two separate things.

To investigate the main issue, I recommend that you replace main.swift with a main.m from my old DevForums version of this doc. That’ll confirm that the packaging side of things is working for C-like code. And converting that code to C++ shouldn’t be hard.

As to your dynamic libraries, once you have a working app-like project then you add dynamic libraries to the project as you would in an app, that is:

  1. Drag the library into your project.

  2. Select the target in question.

  3. Go to the General tab.

  4. Add the libraries to the Frameworks and Libraries list.

  5. Flip the Embed popup to Embed & Sign.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Working, signed, notarized app will not run on another system
 
 
Q