Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an iOS app read its own entitlements at runtime?

Can an iOS app discover, inspect, or otherwise read its own entitlements at runtime?

Ideally, I could read the whole (processed) contents of my .entitlements file as a plist. Getting just the app identifier prefix would be an acceptable second-best.

Goals here include: allowing the app to be signed with various app identifier prefixes, without needing to make a matching change in code; and to act differently in the presence or absence of shared keychain access groups. This is library code, so the less I impose on the client app's configuration, the better.

like image 867
rgeorge Avatar asked Sep 23 '13 22:09

rgeorge


People also ask

How do iOS entitlements work?

An app stores its entitlements as key-value pairs embedded in the code signature of its binary executable. You configure entitlements for your app by declaring capabilities for a target in Xcode. Xcode records capabilities that you add in a property list file with the . entitlements extension.

How do I check iOS app entitlements?

Check the Entitlements In Your Build Log and App You'll find the name of the provisioning profile Xcode used to sign your app in the invocation of the codesign tool's command-line parameters. This command prints a plist that contains all of the entitlements built into the app.

What is entitlement file in iOS?

Entitlements are special app capabilities and security permissions granted to applications that are correctly configured to use them. In iOS, apps run in a sandbox, which provides a set of rules that limit access between the application and certain system resources or user data.


2 Answers

In short, no. The entitlements file is only used at compile-time and is not copied into the app bundle.

Clarification: During development, the entitlements are written into the embedded.mobileprovision file in the app bundle. When your app is released as an IPA on the App Store, it will not contain a embedded.mobileprovision.

like image 115
neilco Avatar answered Oct 17 '22 04:10

neilco


As others mentioned in comments, the signed executable of your app contains an embedded entitlements plist, which suggests it should be possible.

You will need to use some non-ios-public (but documented) APIs. Try the following code:

// Declare the private SecTask functions in your header file void* (SecTaskCopyValueForEntitlement)(void* task, CFStringRef entitlement, CFErrorRef  _Nullable *error); void* (SecTaskCreateFromSelf)(CFAllocatorRef allocator);   // And call it in your code like this: CFErrorRef err = nil; NSArray* groups = SecTaskCopyValueForEntitlement(SecTaskCreateFromSelf(NULL), CFSTR("com.apple.security.application-groups"), &err); 
like image 26
Elist Avatar answered Oct 17 '22 04:10

Elist