SHARE
TWEET

Untitled

a guest May 21st, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import objc
  2. from Foundation import NSBundle, NSURL
  3. Security = NSBundle.bundleWithIdentifier_('com.apple.security')
  4.  
  5. class StaticCodeError(Exception):
  6.     pass
  7.  
  8. class SigningInfoError(Exception):
  9.     pass
  10.  
  11. kSecCSDefaultFlags           = 0
  12. kSecCSSigningInformation     = 1 << 1
  13. kSecCSRequirementInformation = 1 << 2
  14. kSecCSCalculateCMSDigest     = 1 << 6
  15.  
  16. _f = [
  17.       ('SecStaticCodeCreateWithPath',   'i@Io^@'),
  18.       ('SecCodeCopySigningInformation', 'i@Io^@'),
  19.      ]
  20.  
  21. objc.loadBundleFunctions(Security, globals(), _f)
  22.  
  23. def codesign_info(path):
  24.     url = NSURL.fileURLWithPath_(path)
  25.     err, codeobj  = SecStaticCodeCreateWithPath(url, kSecCSDefaultFlags, None)
  26.     if err != 0:
  27.         raise StaticCodeError('unable to create SecCodeRef with provided path')
  28.     flags = kSecCSSigningInformation | kSecCSRequirementInformation | kSecCSCalculateCMSDigest
  29.     err, codeinfo = SecCodeCopySigningInformation(codeobj, flags, None)
  30.     if err != 0:
  31.         raise SigningInfoError('unable to retrieve signing information for SecCodeRef')
  32.     return codeinfo
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top