Skip to content

Instantly share code, notes, and snippets.

@command-tab
Created April 12, 2012 20:17
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save command-tab/2370710 to your computer and use it in GitHub Desktop.
Save command-tab/2370710 to your computer and use it in GitHub Desktop.
Extract Certificate Subject from a Provisioning Profile
# Parse a provisioning profile
# Extract the first DeveloperCertificates <data> entry
# Remove any leading whitespace
# Remove any blank lines
# Base64 decode the blob
# Parse the .cer with OpenSSL
# Extract the first line, which is the certificate subject (the rest is the cert blob)
# End up with a string like: subject= /UID=AABBCCDDEE/CN=iPhone Developer: First Last (FFGGHHIIJJ)/C=US
# Note: Uses xmlstarlet to parse the plist, but you could probably use PlistBuddy or grep, too
security cms -D -i "/path/to/some.mobileprovision" | \
xml sel -t -v "/plist/dict/key[. = 'DeveloperCertificates']/following-sibling::array[1]/data[1]" | \
awk '{print $1}' | sed '/^$/d' | base64 -D | openssl x509 -subject -inform der | head -n 1
@punksta
Copy link

punksta commented Jul 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment