Skip to content

Instantly share code, notes, and snippets.

@pudquick pudquick/codesign.py
Last active May 11, 2019

Embed
What would you like to do?
Obtain codesigning information with pyobjc
import objc
from Foundation import NSBundle, NSURL
Security = NSBundle.bundleWithIdentifier_('com.apple.security')
class StaticCodeError(Exception):
pass
class SigningInfoError(Exception):
pass
kSecCSDefaultFlags = 0
kSecCSSigningInformation = 1 << 1
kSecCSRequirementInformation = 1 << 2
kSecCSCalculateCMSDigest = 1 << 6
_f = [
('SecStaticCodeCreateWithPath', 'i@Io^@'),
('SecCodeCopySigningInformation', 'i@Io^@'),
]
objc.loadBundleFunctions(Security, globals(), _f)
def codesign_info(path):
url = NSURL.fileURLWithPath_(path)
err, codeobj = SecStaticCodeCreateWithPath(url, kSecCSDefaultFlags, None)
if err != 0:
raise StaticCodeError('unable to create SecCodeRef with provided path')
flags = kSecCSSigningInformation | kSecCSRequirementInformation | kSecCSCalculateCMSDigest
err, codeinfo = SecCodeCopySigningInformation(codeobj, flags, None)
if err != 0:
raise SigningInfoError('unable to retrieve signing information for SecCodeRef')
return codeinfo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.