apple_certs_info 0.1.6 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c31c885d87acfafec09d0e05c5394bdb8171cb0b7e8d0a8123fdba45fbe4e6cd
4
- data.tar.gz: 1b32182ba8b37d81e9b046c231d21101c53bfe9195c305b4154e8e0321944e82
3
+ metadata.gz: 68d3c3b54444d29ee89642ab3cc5a4c140d4ebd8d3285109c8f58ce523dec0fc
4
+ data.tar.gz: affc1729365659a246ae3af13ce77883eefb74b35d51938dd750733584e75bd2
5
5
  SHA512:
6
- metadata.gz: 6fd35aa677a7f1bf80a423c88e1f88ef76f83c9a0ca2805c3517863004cc91aa7342fed8bc0bf205c466c3d8ca18ff4e86b46bdd82db86fe53b9cc58faa847e8
7
- data.tar.gz: 54c6186d19b49ca1b4ae87f61d6d8813b578ae69f6f0c9ba5cf55af80f8880da6591f488c08982bce63b3ceda82984e3e2e90e219b20db018c330c013ef520bb
6
+ metadata.gz: d62764bd66bf50b64c9ef1749ab36a0c187448e180b63545d25df0f5f525daf0b8054940dc6cbf32a7bcdda338bf1f639596473637bf242289561547fc8b5b00
7
+ data.tar.gz: 14a074228da2d5cb4f69147df2bd14c69136a9645dcce6f12cf38cffe16a682b0e8d6f9338c209b8c9722391e05f24cce0d6b0e400a00c0c3446c4ee8e29cd72
@@ -108,28 +108,28 @@
108
108
  </library>
109
109
  </orderEntry>
110
110
  <orderEntry type="module-library">
111
- <library name="rspec-mocks (vbundled(3.10.1)) [path][gem]" type="rubylib">
111
+ <library name="rspec-mocks (vbundled(3.10.2)) [path][gem]" type="rubylib">
112
112
  <properties>
113
113
  <option name="version" value="4" />
114
114
  </properties>
115
115
  <CLASSES>
116
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.10.1/lib" />
116
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.10.2/lib" />
117
117
  </CLASSES>
118
118
  <SOURCES>
119
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.10.1/lib" />
119
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.10.2/lib" />
120
120
  </SOURCES>
121
121
  </library>
122
122
  </orderEntry>
123
123
  <orderEntry type="module-library">
124
- <library name="rspec-support (vbundled(3.10.1)) [path][gem]" type="rubylib">
124
+ <library name="rspec-support (vbundled(3.10.2)) [path][gem]" type="rubylib">
125
125
  <properties>
126
126
  <option name="version" value="4" />
127
127
  </properties>
128
128
  <CLASSES>
129
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.1/lib" />
129
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.2/lib" />
130
130
  </CLASSES>
131
131
  <SOURCES>
132
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.1/lib" />
132
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.2/lib" />
133
133
  </SOURCES>
134
134
  </library>
135
135
  </orderEntry>
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apple_certs_info (0.1.6)
4
+ apple_certs_info (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -17,10 +17,10 @@ GEM
17
17
  rspec-expectations (3.10.1)
18
18
  diff-lcs (>= 1.2.0, < 2.0)
19
19
  rspec-support (~> 3.10.0)
20
- rspec-mocks (3.10.1)
20
+ rspec-mocks (3.10.2)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
22
  rspec-support (~> 3.10.0)
23
- rspec-support (3.10.1)
23
+ rspec-support (3.10.2)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
data/README.md CHANGED
@@ -40,7 +40,7 @@ AppleCertsInfo.certificate_distribution_list_limit_days_for(days: 10)
40
40
 
41
41
  ## Contributing
42
42
 
43
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apple_certs_info. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/apple_certs_info/blob/master/CODE_OF_CONDUCT.md).
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tarappo/apple_certs_info. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tarappo/apple_certs_info/blob/master/CODE_OF_CONDUCT.md).
44
44
 
45
45
 
46
46
  ## License
@@ -49,4 +49,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
49
49
 
50
50
  ## Code of Conduct
51
51
 
52
- Everyone interacting in the AppleCertsInfo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/apple_certs_info/blob/master/CODE_OF_CONDUCT.md).
52
+ Everyone interacting in the AppleCertsInfo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tarappo/apple_certs_info/blob/master/CODE_OF_CONDUCT.md).
@@ -3,7 +3,7 @@ require_relative 'lib/apple_certs_info/version'
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "apple_certs_info"
5
5
  spec.version = AppleCertsInfo::VERSION
6
- spec.authors = ["Toshiyuki Hirata"]
6
+ spec.authors = ["tarappo"]
7
7
  spec.email = ["tarappo@gmail.com"]
8
8
 
9
9
  spec.summary = %q{Apple Certificate files and Provisioning Profile information.}
@@ -13,72 +13,74 @@ module AppleCertsInfo
13
13
  @debug_log
14
14
  end
15
15
 
16
+ # Remove duplicate certificate
17
+ # remove first data
18
+ def self.remove_duplicate_certificate
19
+ list = certificate_development_list.concat(certificate_distribution_list)
20
+
21
+ duplicate_cname = list.group_by{ |e| e[:cname] }.select { |k, v| v.size > 1 }.map(&:first)
22
+ duplicate_cname.each do |cname|
23
+ delete_first_match_keychain(name: cname)
24
+ end
25
+ end
26
+
16
27
  # Check Certificate file for iPhone Developer /Apple Development in the KeyChain
17
28
  # @param days: limit days
29
+ # @return:
30
+ # expire_datetime: deadline
31
+ # limit_days: limit days
32
+ # cname: CN
18
33
  def self.certificate_development_list_limit_days_for(days:)
19
34
  raise "do not set days param" if days.nil?
20
- limit_days_for(days: days, type: "certificate_development")
35
+ filtering_limit_days_for(list: certificate_development_list.uniq, days: days)
21
36
  end
22
37
 
23
38
  # Check Certificate file for iPhone/Apple Distribution in the KeyChain
39
+ # @param days: limit days
40
+ # @return:
41
+ # expire_datetime: deadline
42
+ # limit_days: limit days
43
+ # cname: CN
24
44
  def self.certificate_distribution_list_limit_days_for(days:)
25
45
  raise "do not set days param" if days.nil?
26
- limit_days_for(days: days, type: "certificate_distribution")
46
+ filtering_limit_days_for(list: certificate_distribution_list.uniq, days: days)
27
47
  end
28
48
 
29
49
  # Check Provisioning Profiles in the Directory that is ~/Library/MobileDevice/Provisioning Profiles/
50
+ # @param days: limit days
51
+ # @return:
52
+ # expire_datetime: deadline
53
+ # limit_days: limit days
54
+ # app_identifier: Bundle Identifier
55
+ # app_id_name => App ID Name
30
56
  def self.provisioning_profile_list_limit_days_for(days:)
31
57
  raise "do not set days param" if days.nil?
32
- limit_days_for(days: days, type: "provisioning_profile")
58
+ filtering_limit_days_for(list: provisioning_profile_list.uniq, days: days)
33
59
  end
34
60
 
61
+ # All iPhone Developer and Apple Development List
35
62
  def self.certificate_development_list
36
63
  list = []
37
- list = certificate_list_for(name: "iPhone Developer")
38
- list << certificate_list_for(name: "Apple Development")
64
+ iphone_list = certificate_list_for(name: "iPhone Developer")
65
+ apple_list = certificate_list_for(name: "Apple Development")
66
+ list.concat(iphone_list)
67
+ list.concat(apple_list)
68
+ return list
39
69
  end
40
70
 
71
+ # All iPhone Distribution and Apple Distribution List
41
72
  def self.certificate_distribution_list
42
73
  list = []
43
- list = certificate_list_for(name: "iPhone Distribution")
44
- list << certificate_list_for(name: "Apple Distribution")
45
- end
46
-
47
- def self.certificate_info_for(name:)
48
- raise "do not set name param" if name.nil?
49
-
50
- temp_pem_file = Tempfile.new(::File.basename("temp_pem"))
51
-
52
- begin
53
- `security find-certificate -a -c "#{name}" -p > #{temp_pem_file.path}`
54
- result = `openssl x509 -text -fingerprint -noout -in #{temp_pem_file.path}`
55
-
56
- expire_datetime_match = result.match(/.*Not After :(.*)/)
57
- raise "not exits expire date" if expire_datetime_match.nil?
58
-
59
- expire_datetime = Time.parse(expire_datetime_match[1])
60
-
61
- cname_match = result.match(/Subject: .* CN=(.*), OU=.*/)
62
- raise "not exists cname:#{result}" if cname_match.nil?
63
- cname = cname_match[1]
64
-
65
- limit_days = calc_limit_days(datetime: expire_datetime)
66
-
67
- rescue StandardError => e
68
- raise(e.message)
69
- ensure
70
- temp_pem_file.close && temp_pem_file.unlink
71
- end
72
-
73
- return {
74
- :expire_datetime => expire_datetime,
75
- :limit_days => limit_days,
76
- :cname => cname
77
- }
74
+ iphone_list = certificate_list_for(name: "iPhone Distribution")
75
+ apple_list = certificate_list_for(name: "Apple Distribution")
76
+ list.concat(iphone_list)
77
+ list.concat(apple_list)
78
+ return list
78
79
  end
79
80
 
80
- def self.provisioning_profile_list_info(dir: "~/Library/MobileDevice/Provisioning\\ Profiles/*.mobileprovision")
81
- info = []
81
+ # Provisioning Profile List
82
+ def self.provisioning_profile_list(dir: "~/Library/MobileDevice/Provisioning\\ Profiles/*.mobileprovision")
83
+ list = []
82
84
  Dir.glob("#{File.expand_path(dir)}") do |file|
83
85
  file_name_match = file.match(/.*\/(.*)\.mobileprovision/)
84
86
  raise "not exists Provisioning Profile" if file_name_match.nil?
@@ -104,47 +106,99 @@ module AppleCertsInfo
104
106
  temp_plist_file.close && temp_plist_file.unlink
105
107
  end
106
108
 
107
- info << {
109
+ list << {
108
110
  :expire_datetime => expire_datetime,
109
111
  :limit_days => limit_days,
110
112
  :app_identifier => app_identifier,
111
113
  :app_id_name => app_id_name
112
114
  }
113
115
  end
114
- return info
116
+ return list
115
117
  end
116
118
 
117
- private
118
- def self.limit_days_for(days:, type:)
119
- case type
120
- when "certificate_development" then
121
- list = certificate_development_list
122
- when "certificate_distribution" then
123
- list = certificate_distribution_list
124
- when "provisioning_profile" then
125
- list = provisioning_profile_list_info
126
- end
127
- puts(list) if @debug_log == true
119
+ # Certificate Information for target name
120
+ # @return
121
+ # expire_datetime: deadline
122
+ # limit_days: limit days
123
+ # cname: CN
124
+ def self.certificate_info_for(name:)
125
+ raise "do not set name param" if name.nil?
128
126
 
129
- danger_list = []
130
- list.each do |info|
131
- danger_list << info if info[:limit_days] <= days
127
+ info = []
128
+ begin
129
+ temp_pem_file = certificate_exchange_pem_file_for(name: name)
130
+ result = `openssl crl2pkcs7 -nocrl -certfile #{temp_pem_file.path} | openssl pkcs7 -print_certs -text -noout`
131
+
132
+ expire_datetime_match = result.scan(/.*Not After :(.*)/)
133
+ raise "not exits expire date" if expire_datetime_match.nil?
134
+
135
+ cname_match = result.match(/Subject: .* CN=(.*), OU=.*/)
136
+ raise "not exists cname:#{result}" if cname_match.nil?
137
+
138
+ expire_datetime_match.each do |original_datetime|
139
+ expire_datetime = Time.parse(original_datetime.first)
140
+ limit_days = calc_limit_days(datetime: expire_datetime)
141
+ cname = cname_match[1] # cname is same
142
+
143
+ info << {
144
+ :expire_datetime => expire_datetime,
145
+ :limit_days => limit_days,
146
+ :cname => cname,
147
+ }
148
+ end
149
+ rescue StandardError => e
150
+ raise(e.message)
151
+ ensure
152
+ temp_pem_file.close && temp_pem_file.unlink
132
153
  end
133
154
 
134
- danger_list
155
+ return info
156
+ end
157
+
158
+
159
+ private
160
+ def self.delete_first_match_keychain(name:)
161
+ result = `security find-certificate -a -c "#{name}" -Z`
162
+ sha_match = result.match(/SHA-1 hash: (.*)/)
163
+ keychain_path = result.match(/keychain: (.*)/)
164
+ raise "not exits sha-1" if sha_match.nil?
165
+ raise "not exits keychain_path" if keychain_path.nil?
166
+ sha1 = sha_match[1]
167
+ puts "Delete #{name} / SHA-1: #{sha1}"
168
+
169
+ result = `security delete-certificate -Z #{sha1} #{keychain_path[1]}`
135
170
  end
136
171
 
137
172
  def self.certificate_list_for(name:)
138
- result = `security find-certificate -a -c "#{name}"`
173
+ result = `security find-certificate -a -c "#{name}" -Z`
139
174
  name_match_list = result.scan(/.*alis".*=\"(.*)\".*/)
140
175
  puts(name_match_list) if @debug_log == true
141
176
 
142
177
  info = []
143
- name_match_list.each do|name_match|
178
+ name_match_list.uniq.each do|name_match|
144
179
  info << certificate_info_for(name:name_match[0])
145
180
  end
146
181
 
147
- info
182
+ info.flatten!
183
+ end
184
+
185
+ # filtering list
186
+ def self.filtering_limit_days_for(list:, days:)
187
+ danger_list = []
188
+ list.each do |info|
189
+ danger_list << info if info[:limit_days].to_i <= days.to_i
190
+ end
191
+
192
+ danger_list
193
+ end
194
+
195
+ # exchange pem file
196
+ # @param name: unique name
197
+ def self.certificate_exchange_pem_file_for(name:)
198
+ temp_pem_file = Tempfile.new(::File.basename("temp_pem"))
199
+ `security find-certificate -a -c "#{name}" -p > #{temp_pem_file.path}`
200
+
201
+ temp_pem_file
148
202
  end
149
203
 
150
204
  def self.calc_limit_days(datetime:)
@@ -1,3 +1,3 @@
1
1
  module AppleCertsInfo
2
- VERSION = "0.1.6"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_certs_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Toshiyuki Hirata
7
+ - tarappo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-13 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: