How to determine at run-time if app is for development, app store or ad hoc distribution?

后端 未结 5 539
半阙折子戏
半阙折子戏 2020-12-07 09:00

Is there a way to determine programmatically if the currently running app was built and signed for development only or whether it was built for distribution? And can one det

5条回答
  •  死守一世寂寞
    2020-12-07 09:07

    The easiest way to check is to look at embedded.mobileprovision ([[NSBundle mainBundle] pathForResource:@"embedded.mobileprovision" ofType:nil]):

    • It's a bit of a pain to parse since it's a signed plist (PKCS#7 signed data, according to openssl asn1parse -inform der), but a bad hack is to just look for and .
    • Development contains UDIDs and get-task-allow
    • Ad Hoc distribution contains UDIDs (and get-task-allow=false)
    • App Store distribution contains no UDIDs.

    The other thing you can check is the entitlements embedded in the executable (otool -l lists it as LC_CODE_SIGNATURE). Parsing this is even more tedious (you need to parse the Mach-O header and load commands, and for "universal" binaries which are now the default, you'll need to check the currently-loaded architecture or all architectures).

    • Development builds contain get-task-allow
    • Ad Hoc and App Store builds contain get-task-allow

    I don't think the entitlements distinguish between Ad Hoc and App Store builds.

    Apart from those and the certificate it's signed with, there's no difference between Development/Ad Hoc/App Store apps (there are a few other things in the entitlements/provisioning profile, but nothing more reliable that I can think of).

    Security considerations

    Neither of these are that difficult to circumvent. For the first method, the app could just "swizzle" -[NSBundle pathForResource:ofType:]. The second method is a bit more difficult depending on what API you use to read the file.

提交回复
热议问题