daily pastebin goal
92%
SHARE
TWEET

Using SecCodeCheckValidity

applehelpwriter Feb 17th, 2018 (edited) 128 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     func codeCheck() -> Bool
  2.     {
  3.         var myCode : SecCode?
  4.         var status : OSStatus?
  5.         var requirement : SecRequirement?
  6.         var errors : Unmanaged<CFError>?
  7.  
  8.         let entitlement = "anchor apple generic and identifier = \"com.yourapp.example\" and certificate leaf[subject.OU] = Y0URTEAM1D"
  9.  
  10.         status = SecRequirementCreateWithStringAndErrors(entitlement as CFString, [], &errors, &requirement)
  11.        
  12.         if status != errSecSuccess
  13.         {
  14.             NSLog("SecRequirements failed with status code \(status).")
  15.         } else
  16.         {
  17.             status = SecCodeCopySelf([], &myCode)
  18.             if status != errSecSuccess
  19.             {
  20.                 NSLog("SecCodeCopySelf failed with status code: \(status).")
  21.             } else
  22.             {
  23.                 status = SecCodeCheckValidity(myCode!, [], requirement)
  24.                 if status != errSecSuccess
  25.                 {
  26.                     NSLog("SecCodeCheckValidity failed with status code: \(status).")
  27.                 } else
  28.                 {
  29.                     NSLog("Codesigning: valid")
  30.                     return true
  31.                 }
  32.             }
  33.            
  34.         }
  35.         return false
  36.     }
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