Module: AppleCertsInfo

Defined in:
lib/apple_certs_info.rb,
lib/apple_certs_info/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.certificate_development_listObject

All iPhone Developer and Apple Development List



52
53
54
# File 'lib/apple_certs_info.rb', line 52

def self.certificate_development_list
  certificate_list_for(name: "iPhone Developer") + certificate_list_for(name: "Apple Development")
end

.certificate_development_list_limit_days_for(days:) ⇒ Object

Check Certificate file for iPhone Developer /Apple Development in the KeyChain @return:

expire_datetime: deadline
limit_days: limit days
cname: CN

Parameters:

  • days:

    limit days



23
24
25
26
# File 'lib/apple_certs_info.rb', line 23

def self.certificate_development_list_limit_days_for(days:)
  raise "do not set days param" if days.nil?
  filtering_limit_days_for(list: certificate_development_list.uniq, days: days)
end

.certificate_distribution_listObject

All iPhone Distribution and Apple Distribution List



57
58
59
# File 'lib/apple_certs_info.rb', line 57

def self.certificate_distribution_list
  certificate_list_for(name: "iPhone Distribution") + certificate_list_for(name: "Apple Distribution")
end

.certificate_distribution_list_limit_days_for(days:) ⇒ Object

Check Certificate file for iPhone/Apple Distribution in the KeyChain @return:

expire_datetime: deadline
limit_days: limit days
cname: CN

Parameters:

  • days:

    limit days



34
35
36
37
# File 'lib/apple_certs_info.rb', line 34

def self.certificate_distribution_list_limit_days_for(days:)
  raise "do not set days param" if days.nil?
  filtering_limit_days_for(list: certificate_distribution_list.uniq, days: days)
end

.certificate_info_for(name:) ⇒ Object

Certificate Information for target name

Returns:

  • expire_datetime: deadline limit_days: limit days cname: CN



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/apple_certs_info.rb', line 104

def self.certificate_info_for(name:)
  raise "do not set name param" if name.nil?

  info = []
  temp_pem_file = certificate_exchange_pem_file_for(name: name)
  begin
    result = `openssl crl2pkcs7 -nocrl -certfile #{Shellwords.escape(temp_pem_file.path)} | openssl pkcs7 -print_certs -text -noout`

    expire_datetime_match = result.scan(/.*Not After :(.*)/)
    raise "not exists expire date" if expire_datetime_match.empty?

    cname_match = result.match(/Subject: .* CN=(.*), OU=.*/)
    raise "not exists cname:#{result}" if cname_match.nil?

    expire_datetime_match.each do |original_datetime|
      expire_datetime = Time.parse(original_datetime.first)
      limit_days = calc_limit_days(datetime: expire_datetime)
      cname = cname_match[1] # cname is same

      info << {
          :expire_datetime => expire_datetime,
          :limit_days => limit_days,
          :cname => cname,
      }
    end
  ensure
    temp_pem_file.close!
  end

  return info
end

.debug_logObject



13
14
15
# File 'lib/apple_certs_info.rb', line 13

def self.debug_log
  @debug_log
end

.provisioning_profile_list(dir: "~/Library/MobileDevice/Provisioning\\ Profiles/*.mobileprovision") ⇒ Object

Provisioning Profile List



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/apple_certs_info.rb', line 62

def self.provisioning_profile_list(dir: "~/Library/MobileDevice/Provisioning\\ Profiles/*.mobileprovision")
  list = []
  Dir.glob("#{File.expand_path(dir)}") do |file|
    file_name_match =  file.match(/.*\/(.*)\.mobileprovision/)
    raise "not exists Provisioning Profile" if file_name_match.nil?

    file_name = file_name_match[1]
    temp_plist_file = Tempfile.new(::File.basename(file_name))
    plist_file = temp_plist_file.path

    begin
      # exchange plist file
      unless system("security cms -D -i #{Shellwords.escape(file)} > #{Shellwords.escape(plist_file)}")
        raise "failed to decode Provisioning Profile: #{file}"
      end

      # checking plist file
      expire_datetime = Time.parse(`/usr/libexec/PlistBuddy -c 'Print ExpirationDate' #{Shellwords.escape(plist_file)}`)
      app_identifier = `/usr/libexec/PlistBuddy -c 'Print Entitlements:application-identifier' #{Shellwords.escape(plist_file)}`.chomp
      app_id_name = `/usr/libexec/PlistBuddy -c 'Print AppIDName' #{Shellwords.escape(plist_file)}`.chomp

      limit_days = calc_limit_days(datetime: expire_datetime)
    ensure
      temp_plist_file.close!
    end

    list << {
        :expire_datetime => expire_datetime,
        :limit_days => limit_days,
        :app_identifier => app_identifier,
        :app_id_name => app_id_name,
        :file_path => file_name_match[0]
    }
  end
  return list
end

.provisioning_profile_list_limit_days_for(days:) ⇒ Object

Check Provisioning Profiles in the Directory that is ~/Library/MobileDevice/Provisioning Profiles/ @return:

expire_datetime: deadline
limit_days: limit days
app_identifier: Bundle Identifier
app_id_name => App ID Name

Parameters:

  • days:

    limit days



46
47
48
49
# File 'lib/apple_certs_info.rb', line 46

def self.provisioning_profile_list_limit_days_for(days:)
  raise "do not set days param" if days.nil?
  filtering_limit_days_for(list: provisioning_profile_list.uniq, days: days)
end

.set_debug_log(flag) ⇒ Object



10
11
12
# File 'lib/apple_certs_info.rb', line 10

def self.set_debug_log(flag)
  @debug_log = flag
end