lib/app_info/ipa/mobile_provision.rb in app-info-2.0.0 vs lib/app_info/ipa/mobile_provision.rb in app-info-2.1.0

- old
+ new

@@ -1,8 +1,10 @@ # frozen_string_literal: true +require 'openssl' require 'cfpropertylist' +require 'app_info/util' module AppInfo # .mobileprovision file parser class MobileProvision def initialize(path) @@ -43,23 +45,23 @@ def entitlements mobileprovision.try(:[], 'Entitlements') end - def method_missing(method_name, *args, &block) - key = if method_name.to_s.include?('_') - method_name.to_s - .split('_') - .map(&:capitalize) - .join('') - else - method_name.to_s - end + def developer_certs + certs = mobileprovision.try(:[], 'DeveloperCertificates') + return if certs.empty? - mobileprovision.try(:[], key) + certs.each_with_object([]) do |cert, obj| + obj << DeveloperCertificate.new(cert) + end end + def [](key) + mobileprovision.try(:[], key.to_s) + end + def empty? mobileprovision.nil? end def mobileprovision @@ -71,10 +73,22 @@ @mobileprovision = CFPropertyList.native_types(list) rescue CFFormatError @mobileprovision = nil end + def method_missing(method_name, *args, &block) + mobileprovision.try(:[], Util.format_key(method_name)) || + mobileprovision.send(method_name) || + super + end + + def respond_to_missing?(method_name, *args) + mobileprovision.key?(Util.format_key(method_name)) || + mobileprovision.respond_to?(method_name) || + super + end + private def bplist?(raw) raw[0..5] == 'bplist' end @@ -82,8 +96,29 @@ def strip_plist_wrapper(raw) end_tag = '</plist>' start_point = raw.index('<?xml version=') end_point = raw.index(end_tag) + end_tag.size - 1 raw[start_point..end_point] + end + + # Developer Certificate + class DeveloperCertificate + attr_reader :raw + + def initialize(data) + @raw = OpenSSL::X509::Certificate.new(data) + end + + def name + @raw.subject.to_a.find { |name, _, _| name == 'CN' }[1] + end + + def created_date + @raw.not_after + end + + def expired_date + @raw.not_before + end end end end