class Fastlane::Helper::IpaAnalyzeHelper

Public Class Methods

analyze(ipa_path) click to toggle source
# File lib/fastlane/plugin/ipa_info/helper/ipa_analyze_helper.rb, line 12
def self.analyze(ipa_path)
  # TODO: need to refactoring => only mkdir temp_dir
  return {
      provisiong_info: self.analyze_file_with_unzip(ipa_path, "embedded.mobileprovision"),
      plist_info: self.analyze_file_with_unzip(ipa_path, "Info.plist"),
      certificate_info: analyze_file_with_unzip(ipa_path, "")
  }
end
analyze_file_with_unzip(ipa_path, target_file_name) click to toggle source

unzip ipa file and analyze file

# File lib/fastlane/plugin/ipa_info/helper/ipa_analyze_helper.rb, line 79
def self.analyze_file_with_unzip(ipa_path, target_file_name)
  tempdir = Dir.pwd + "/tmp-#{SecureRandom.hex(10)}"
  target_file_path = find_app_folder_path_in_ipa(ipa_path) + "/#{target_file_name}"
  temp_file_path = "#{tempdir}/#{target_file_name}"
  original_file_path = "#{tempdir}/#{target_file_path}"

  begin
    _, error, = Open3.capture3("unzip -o -d #{tempdir} #{ipa_path}")
    UI.user_error!(error) unless error.empty?

    copy_cmd = "#{original_file_path} #{temp_file_path}"

    case target_file_name
    when "Info.plist" then
      self.copy_file(copy_cmd)
      return self.analyze_info_plist(temp_file_path)
    when "embedded.mobileprovision" then
      self.copy_file(copy_cmd)
      return self.analyze_mobileprovisioning(temp_file_path)
    when "" then
      return self.codesigned(original_file_path)
    end
  rescue StandardError => e
    FileUtils.rm_r(tempdir)
    UI.user_error!(e.message)
  ensure
    FileUtils.rm_r(tempdir)
  end

  return nil
end
analyze_info_plist(tempfile) click to toggle source

Info plist

# File lib/fastlane/plugin/ipa_info/helper/ipa_analyze_helper.rb, line 22
def self.analyze_info_plist(tempfile)
  result = {}

  begin
    UI.user_error!("Failed to convert binary Plist to XML") unless system("plutil -convert xml1 '#{tempfile}'")

    plist = Plist.parse_xml(tempfile)
    plist.each do |key, value|
      parse_value = value.class == Hash || value.class == Array ? value : value.to_s

      result[key] = parse_value
    end
  rescue StandardError => e
    UI.user_error!(e.message)
  ensure
    FileUtils.rm_r(tempfile)
  end

  result
end
analyze_mobileprovisioning(tempfile) click to toggle source

mobileprovisioning

# File lib/fastlane/plugin/ipa_info/helper/ipa_analyze_helper.rb, line 44
def self.analyze_mobileprovisioning(tempfile)
  result = {}

  begin
    mobileprovisioning = Plist.parse_xml(`security cms -D -i #{tempfile}`)
    mobileprovisioning.each do |key, value|
      next if key == 'DeveloperCertificates'

      parse_value = value.class == Hash || value.class == Array ? value : value.to_s

      result[key] = parse_value
    end
  rescue StandardError => e
    UI.user_error!(e.message)
  ensure
    FileUtils.rm_r(tempfile)
  end

  result
end
codesigned(temp_file_path) click to toggle source

certificate

# File lib/fastlane/plugin/ipa_info/helper/ipa_analyze_helper.rb, line 66
def self.codesigned(temp_file_path)
  result = {}

  cmd = "codesign -dv #{temp_file_path}"
  _stdout, stderr, _status = Open3.capture3(cmd)
  codesigned_flag = stderr.include?("Signed Time")

  result["CodeSigned"] = codesigned_flag

  return result
end
copy_file(cmd) click to toggle source

copy

# File lib/fastlane/plugin/ipa_info/helper/ipa_analyze_helper.rb, line 112
def self.copy_file(cmd)
  cmd = "cp #{cmd}"
  _, error, = Open3.capture3(cmd)
  UI.user_error!(error) unless error.empty?
end

Private Class Methods

find_app_folder_path_in_ipa(ipa_path) click to toggle source

return app folder path

# File lib/fastlane/plugin/ipa_info/helper/ipa_analyze_helper.rb, line 119
def self.find_app_folder_path_in_ipa(ipa_path)
  return "Payload/*.app"
end