Last active
July 3, 2016 07:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and when...
puts cert.to_text