Advertisement
applehelpwriter

Using SecCodeCheckValidity

Feb 17th, 2018
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.22 KB | None | 0 0
  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.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement