Is there a Swift to C API that delivers the same functionality as the codesign command?
I would like, given a path to an executable, determine if it has been signed, and if so, extract the TeamIdentifier and Identifier values.
Is there [an] API that delivers the same functionality as the codesign command?
That depends on which aspect’s of the codesign
command you’re using. It has three major subcommons:
-
Signing code (
-s
) -
Verifying code (
-v
) -
Display code signature information (
-d
)
There is no API for the first. For the second and third you can use the SecCode
and SecStaticCode
APIs:
-
For verifying code, use
SecCodeCheckValidity
and its variants. -
For getting information about a code signature, use
SecCodeCopySigningInformation
(andSecCodeCopyDesignatedRequirement
, but that’s much more obscure [1]).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] See TN3127 Inside Code Signing: Requirements.