Skip to content

Instantly share code, notes, and snippets.

@punksta
Last active July 3, 2016 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save punksta/0468b0174659d86065ebff766cb89796 to your computer and use it in GitHub Desktop.
Save punksta/0468b0174659d86065ebff766cb89796 to your computer and use it in GitHub Desktop.
Ruby function returns public key certificate from iOS provision profile. Returns OpenSSL::X509::Certificate object.
require 'openssl'
require 'open3'
require 'plist'
PROVISIONS = "#{Dir.home}/Library/MobileDevice/Provisioning\ Profiles/".freeze
def get_cert(uuid)
path = File.join PROVISIONS, "#{uuid}.mobileprovision"
o, e, s = Open3.capture3("security cms -D -i '#{path}'")
if s.exitstatus != 0
raise "Can't extract plist from provision profile\n" + e
end
provision_plist = Plist.parse_xml(o)
cert_data = provision_plist['DeveloperCertificates'][0].string
cert = OpenSSL::X509::Certificate.new(cert_data)
return cert
end
@punksta
Copy link
Author

punksta commented Jul 3, 2016

and when...

puts cert.to_text

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