Quinn, you've often suggested that to validate the other side of an XPC connection, we should use the audit token. But that's not available from the XPC object, whereas the PID is. So everyone uses the PID.
While looking for something completely unrelated, I found this in the SecCode.h file
OSStatus SecCodeCreateWithXPCMessage(xpc_object_t message, SecCSFlags flags,
SecCodeRef * __nonnull CF_RETURNS_RETAINED target);
Would this be the preferred way to do this now? At least from 11.0 and up.
Like I said, I was looking for something completely unrelated and found this and don't have the cycles right now to try it. But it looks promising from the description and I wanted to check in with you about it in case you can say yes or no before I get a chance to test it.
Thanks
I’m posting this summary so that I can mark it as Apple Recommended and (finally!) put this issue to bed. So:
-
If you’re using
NSXPCConnection
, use-setCodeSigningRequirement:
method to solve this problem. This was introduced with macOS 13. -
If you’re using the XPC C API, use the
xpc_connection_set_peer_code_signing_requirement
API to solve this problem. This was introduced with macOS 12.Both of these APIs take a code signing requirement. For more information on that topic, see TN3127 Inside Code Signing: Requirements.
-
Alternatively, use the
xpc_connection_set_peer_lightweight_code_requirement
API added in macOS 14.4. You can read its documentation here, but I also recommend that you read the doc comments in<xpc/connection.h>
. -
If you’re using the XPC C API on macOS 11, use
SecCodeCreateWithXPCMessage
for this. There’s currently no documentation but there are good doc comments in<Security/SecCode.h>
. -
If none of the above apply, there isn’t a great solution. Various options have been discussed here, including on the older thread referenced above, but there’s nothing I’m fully confident in.
ps If you have follow-up questions about this stuff, please don’t put them in the comments. As I mentioned in Quinn’s Top Ten DevForums Tips, I’m not notified of those. Rather, reply here or, better yet, start a new thread with all the details. Make sure to tag your new thread with XPC so that I see it.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Revision History
-
2024-03-13 Added an entry for
xpc_connection_set_peer_lightweight_code_requirement
. As a postscript about follow-up questions. Made other minor editorial changes. -
2022-07-09 First posted.