Class: FastlaneCore::CertChecker
- Inherits:
-
Object
- Object
- FastlaneCore::CertChecker
- Defined in:
- lib/fastlane_core/cert_checker.rb
Overview
This class checks if a specific certificate is installed on the current mac
Class Method Summary collapse
- .install_wwdr_certificate ⇒ Object
- .installed?(path) ⇒ Boolean
- .installed_identies ⇒ Object
-
.is_installed?(path) ⇒ Boolean
Legacy Method, use ‘installed?` instead.
- .list_available_identities ⇒ Object
- .sha1_fingerprint(path) ⇒ Object
- .wwdr_certificate_installed? ⇒ Boolean
- .wwdr_keychain ⇒ Object
Class Method Details
.install_wwdr_certificate ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fastlane_core/cert_checker.rb', line 56 def self.install_wwdr_certificate Dir.chdir('/tmp') do url = 'https://developer.apple.com/certificationauthority/AppleWWDRCA.cer' filename = File.basename(url) keychain = wwdr_keychain keychain = "-k #{keychain.shellescape}" unless keychain.empty? Helper.backticks("curl -O #{url} && security import #{filename} #{keychain}", print: $verbose) UI.user_error!("Could not install WWDR certificate") unless $?.success? end end |
.installed?(path) ⇒ Boolean
4 5 6 7 8 9 10 11 |
# File 'lib/fastlane_core/cert_checker.rb', line 4 def self.installed?(path) UI.user_error!("Could not find file '#{path}'") unless File.exist?(path) ids = installed_identies finger_print = sha1_fingerprint(path) return ids.include? finger_print end |
.installed_identies ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fastlane_core/cert_checker.rb', line 18 def self.installed_identies install_wwdr_certificate unless wwdr_certificate_installed? available = list_available_identities # Match for this text against word boundaries to avoid edge cases around multiples of 10 identities! if /\b0 valid identities found\b/ =~ available UI.error([ "There are no local code signing identities found.", "You can run `security find-identity -v -p codesigning` to get this output.", "This Stack Overflow thread has more information: http://stackoverflow.com/q/35390072/774.", "(Check in Keychain Access for an expired WWDR certificate: http://stackoverflow.com/a/35409835/774 has more info.)" ].join(' ')) end ids = [] available.split("\n").each do |current| next if current.include? "REVOKED" begin (ids << current.match(/.*\) ([[:xdigit:]]*) \".*/)[1]) rescue # the last line does not match end end return ids end |
.is_installed?(path) ⇒ Boolean
Legacy Method, use ‘installed?` instead
14 15 16 |
# File 'lib/fastlane_core/cert_checker.rb', line 14 def self.is_installed?(path) installed?(path) end |
.list_available_identities ⇒ Object
45 46 47 |
# File 'lib/fastlane_core/cert_checker.rb', line 45 def self.list_available_identities `security find-identity -v -p codesigning` end |
.sha1_fingerprint(path) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fastlane_core/cert_checker.rb', line 82 def self.sha1_fingerprint(path) result = `openssl x509 -in "#{path}" -inform der -noout -sha1 -fingerprint` begin result = result.match(/SHA1 Fingerprint=(.*)/)[1] result.delete!(':') return result rescue UI.(result) UI.user_error!("Error parsing certificate '#{path}'") end end |
.wwdr_certificate_installed? ⇒ Boolean
49 50 51 52 53 54 |
# File 'lib/fastlane_core/cert_checker.rb', line 49 def self.wwdr_certificate_installed? certificate_name = "Apple Worldwide Developer Relations Certification Authority" keychain = wwdr_keychain response = Helper.backticks("security find-certificate -c '#{certificate_name}' #{keychain.shellescape}", print: $verbose) return response.include?("attributes:") end |
.wwdr_keychain ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fastlane_core/cert_checker.rb', line 67 def self.wwdr_keychain priority = [ "security list-keychains -d user", "security default-keychain -d user" ] priority.each do |command| keychains = Helper.backticks(command, print: $verbose).split("\n") unless keychains.empty? # Select first keychain name from returned keychains list return keychains[0].strip.tr('"', '') end end return "" end |