Codesign API?

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.

Answered by DTS Engineer in 749906022

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 (and SecCodeCopyDesignatedRequirement, 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.

Accepted Answer

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 (and SecCodeCopyDesignatedRequirement, 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.

Codesign API?
 
 
Q