25

I am tying building a php/bash/mysql system for automating adhoc distribution for iPhone apps. But I want to read the application-identifier key in mobileprovision file of projects and change it info.plist file according to that.

I can currently build ipa files from php IF the cfbundleidentifer key is same as its provision file.

I found a code like this https://gist.github.com/711794 but I want bash script to integrate it to my system.

Thanks

egiray
  • 1,169
  • 1
  • 12
  • 17
  • Asking a question usually help get an answer. What you want? – clt60 Jun 18 '11 at 21:37
  • 2
    I've read much worse questions than this. I think @egray is asking how 'to read the application-identifier key in mobileprovision file of projects and change it info.plist file'. Cordially! – shellter Jun 18 '11 at 21:41

6 Answers6

55

If your running this on a machine with mac os x, you can use the following:

/usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' /dev/stdin <<< $(security cms -D -i path_to_mobileprovision)
0xced
  • 25,219
  • 10
  • 103
  • 255
jlawrie
  • 666
  • 6
  • 3
  • 1
    Oh! thanks for the `security cms -D -i path_to_mobileprovision` tip! I was getting a lot of `Unexpected character 0 at line 1` errors before – Felipe Sabino Aug 18 '16 at 20:35
29

If you want to extract the plist from the mobileprovision in a proper way and not rely on grepping/sedding/etc., you can use OpenSSL as follow:

openssl smime -inform der -verify -noverify -in file.mobileprovision

A complete example in your case could be:

openssl smime -inform der -verify -noverify -in file.mobileprovision > tmp.plist
/usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' tmp.plist

The OpenSSL part should work on any platform, although I've only done that on a Mac so far. PlistBuddy is only on Mac, but other utilities can be found to read/write property list files.

olivierypg
  • 291
  • 3
  • 2
14

I created a bash function based on jlawrie's answer to list all .mobileprovision's bundle IDs from the ~/Library/MobileDevice/Provisioning Profiles folder.

Save this into your .bash_profile and just call it with list_xcode_provisioning_profiles from a terminal.

list_xcode_provisioning_profiles() {
    while IFS= read -rd '' f; do
        2> /dev/null /usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' /dev/stdin \
            <<< $(security cms -D -i "$f")

    done < <(find "$HOME/Library/MobileDevice/Provisioning Profiles" -name '*.mobileprovision' -print0)
}
hyperknot
  • 13,454
  • 24
  • 98
  • 153
  • Works perfectly.Thanks! – joan Feb 02 '18 at 16:25
  • 3
    For those who don't know how to insert that on `.bash_profile`, `touch ~/.bash_profile; open ~/.bash_profile`, copy and paste the source provided, save it, restart the terminal window and them just use `list_xcode_provisioning_profiles` like suggested. – giovannipds Jun 20 '18 at 13:44
  • default shell changed to zsh, so add it to `~/.zshrc` – Lars Mar 12 '21 at 19:48
6

One solution among many...

Use egrep with the -a option, which treats binary files like text files and '-A 2' which will display the two lines after the string you want to match: ApplicationIdentifierPrefix.

After that, trim the line of brackets and whitespace using sed.

Using a series of pipes:

egrep -a -A 2 ApplicationIdentifierPrefix file.mobileprovision | grep string | sed -e 's/<string>//' -e 's/<\/string>//' -e 's/ //'
dneff
  • 61
  • 1
  • 4
0

I used the code from mobileprovision-read repository to be able to pull information from the mobileprovision file. This uses macOS APIs to read the file.

Here is the usage from running the generated program:

mobileprovision-read -- mobileprovision files querying tool.

USAGE
mobileprovision-read -f fileName [-o option]

OPTIONS
    type – prints mobileprovision profile type (debug, ad-hoc, enterprise, appstore)
    appid – prints application identifier
Will print raw provision's plist if option is not specified.
You can also use key path as an option.

EXAMPLES
mobileprovision-read -f test.mobileprovision -o type
    Prints profile type

mobileprovision-read -f test.mobileprovision -o UUID
    Prints profile UUID

mobileprovision-read -f test.mobileprovision -o ProvisionedDevices
    Prints provisioned devices UDIDs

mobileprovision-read -f test.mobileprovision -o Entitlements.get-task-allow
    Prints 0 if profile doesn't allow debugging 1 otherwise
chrish
  • 2,352
  • 1
  • 17
  • 32
0

It is mildly tedious, since a .mobileprovision is "PKCS #7 signed data" or so.

Fortunately, you can probably get away with using grep :)

tc.
  • 33,468
  • 5
  • 78
  • 96