daily pastebin goal
17%
SHARE
TWEET

codeCheck for Obj-C

applehelpwriter Feb 19th, 2018 (edited) 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(BOOL)codeCheck
  2. {
  3.     CFErrorRef errors = NULL;
  4.     SecCodeRef myCode = NULL;
  5.     SecRequirementRef requirement = NULL;
  6.     OSStatus status = errSecSuccess;
  7.     status = SecCodeCopySelf(kSecCSDefaultFlags, &myCode);
  8.     if (status != errSecSuccess)
  9.     {
  10.          NSLog(@"SecCodeCopySelf failed with status code: %ld", (long)status);
  11.     }
  12.    
  13.     NSString *entitlement = @"anchor apple generic and identifier = \"com.yourapp.example\" and certificate leaf[subject.OU] = Y0URTEAM1D";
  14.    
  15.     status = SecRequirementCreateWithStringAndErrors((__bridge CFStringRef)entitlement, kSecCSDefaultFlags, &errors, &requirement);
  16.     if (status != errSecSuccess)
  17.     {
  18.         NSLog(@"SecRequirements failed with status code %i", status);
  19.         // optionally unpack errors here
  20.     } else
  21.     {
  22.         status = SecCodeCheckValidity(myCode, kSecCSDefaultFlags, requirement);
  23.         if (status != errSecSuccess)
  24.         {
  25.             NSLog(@"SecCodeCheckValidity failed with status code %i", status);
  26.         } else {
  27.             return YES;
  28.         }
  29.     }
  30.     return NO;
  31. }
RAW Paste Data
Top