apple_certs_info 0.2.0 → 0.2.1

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: 8919e7f716548ce695171e206e2fb3eeb7c3a27d3bc09165c4aecf09faf921ad
4
- data.tar.gz: b5fd6e5598c774e9213df13956b609bf5f304851712374854a55aca5c78c962d
3
+ metadata.gz: d832e03b2b9b9bc4258931131ac30b37cc98fff25e42566adcecae71b48634c0
4
+ data.tar.gz: ff2ca0720578dc99224e3740e75b9a4d97dff1e4d4694ade8e347f17dfa0b392
5
5
  SHA512:
6
- metadata.gz: 915eafd2ce442ad64472816068ce04b0695c63250981f120fafffcad32981ef430df1ab0611f13cc98a9b497ef53625888d0f3bdb2029fdf60a4244d8a5b796a
7
- data.tar.gz: df12e08a66305f18768cb2770c59a184c6587291d00b1d2dac28d753a535b20d388ba970d2cb232b859ee95072581243bb1985a5420429dbeaecc571c536f8bd
6
+ metadata.gz: 16c615e264bc2867d2cd579dd6e80093b19677cef36747853c01286dfcf3319969d154fbb2e2a203724b6e9c8bd3582c0e609edf9a0c5231efe74130cbc9b9d6
7
+ data.tar.gz: a143ac10d7c70e5ebe9f8f957f83c13b204feac3bbec525c1465fc7b25d2b28f43fa5937b94a29221725597a3d86f63b6a77535ba2a1e3ef1237520463022242
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apple_certs_info (0.2.0)
4
+ apple_certs_info (0.2.1)
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).
@@ -15,76 +15,61 @@ module AppleCertsInfo
15
15
 
16
16
  # Check Certificate file for iPhone Developer /Apple Development in the KeyChain
17
17
  # @param days: limit days
18
+ # @return:
19
+ # expire_datetime: deadline
20
+ # limit_days: limit days
21
+ # cname: CN
18
22
  def self.certificate_development_list_limit_days_for(days:)
19
23
  raise "do not set days param" if days.nil?
20
- limit_days_for(days: days, type: "certificate_development")
24
+ filtering_limit_days_for(list: certificate_development_list.uniq, days: days)
21
25
  end
22
26
 
23
27
  # Check Certificate file for iPhone/Apple Distribution in the KeyChain
28
+ # @param days: limit days
29
+ # @return:
30
+ # expire_datetime: deadline
31
+ # limit_days: limit days
32
+ # cname: CN
24
33
  def self.certificate_distribution_list_limit_days_for(days:)
25
34
  raise "do not set days param" if days.nil?
26
- limit_days_for(days: days, type: "certificate_distribution")
35
+ filtering_limit_days_for(list: certificate_distribution_list.uniq, days: days)
27
36
  end
28
37
 
29
38
  # Check Provisioning Profiles in the Directory that is ~/Library/MobileDevice/Provisioning Profiles/
39
+ # @param days: limit days
40
+ # @return:
41
+ # expire_datetime: deadline
42
+ # limit_days: limit days
43
+ # app_identifier: Bundle Identifier
44
+ # app_id_name => App ID Name
30
45
  def self.provisioning_profile_list_limit_days_for(days:)
31
46
  raise "do not set days param" if days.nil?
32
- limit_days_for(days: days, type: "provisioning_profile")
47
+ filtering_limit_days_for(list: provisioning_profile_list.uniq, days: days)
33
48
  end
34
49
 
50
+ # All iPhone Developer and Apple Development List
35
51
  def self.certificate_development_list
36
52
  list = []
37
53
  iphone_list = certificate_list_for(name: "iPhone Developer")
38
54
  apple_list = certificate_list_for(name: "Apple Development")
39
55
  list.concat(iphone_list)
40
56
  list.concat(apple_list)
41
- return list.uniq
57
+ return list
42
58
  end
43
59
 
60
+ # All iPhone Distribution and Apple Distribution List
44
61
  def self.certificate_distribution_list
45
62
  list = []
46
63
  iphone_list = certificate_list_for(name: "iPhone Distribution")
47
64
  apple_list = certificate_list_for(name: "Apple Distribution")
48
65
  list.concat(iphone_list)
49
66
  list.concat(apple_list)
50
- return list.uniq
51
- end
52
-
53
- def self.certificate_info_for(name:)
54
- raise "do not set name param" if name.nil?
55
-
56
- temp_pem_file = Tempfile.new(::File.basename("temp_pem"))
57
-
58
- begin
59
- `security find-certificate -a -c "#{name}" -p > #{temp_pem_file.path}`
60
- result = `openssl x509 -text -fingerprint -noout -in #{temp_pem_file.path}`
61
-
62
- expire_datetime_match = result.match(/.*Not After :(.*)/)
63
- raise "not exits expire date" if expire_datetime_match.nil?
64
-
65
- expire_datetime = Time.parse(expire_datetime_match[1])
66
-
67
- cname_match = result.match(/Subject: .* CN=(.*), OU=.*/)
68
- raise "not exists cname:#{result}" if cname_match.nil?
69
- cname = cname_match[1]
70
-
71
- limit_days = calc_limit_days(datetime: expire_datetime)
72
-
73
- rescue StandardError => e
74
- raise(e.message)
75
- ensure
76
- temp_pem_file.close && temp_pem_file.unlink
77
- end
78
-
79
- return {
80
- :expire_datetime => expire_datetime,
81
- :limit_days => limit_days,
82
- :cname => cname
83
- }
67
+ return list
84
68
  end
85
69
 
86
- def self.provisioning_profile_list_info(dir: "~/Library/MobileDevice/Provisioning\\ Profiles/*.mobileprovision")
87
- info = []
70
+ # Provisioning Profile List
71
+ def self.provisioning_profile_list(dir: "~/Library/MobileDevice/Provisioning\\ Profiles/*.mobileprovision")
72
+ list = []
88
73
  Dir.glob("#{File.expand_path(dir)}") do |file|
89
74
  file_name_match = file.match(/.*\/(.*)\.mobileprovision/)
90
75
  raise "not exists Provisioning Profile" if file_name_match.nil?
@@ -110,47 +95,87 @@ module AppleCertsInfo
110
95
  temp_plist_file.close && temp_plist_file.unlink
111
96
  end
112
97
 
113
- info << {
98
+ list << {
114
99
  :expire_datetime => expire_datetime,
115
100
  :limit_days => limit_days,
116
101
  :app_identifier => app_identifier,
117
102
  :app_id_name => app_id_name
118
103
  }
119
104
  end
120
- return info
105
+ return list
121
106
  end
122
107
 
123
- private
124
- def self.limit_days_for(days:, type:)
125
- case type
126
- when "certificate_development" then
127
- list = certificate_development_list
128
- when "certificate_distribution" then
129
- list = certificate_distribution_list
130
- when "provisioning_profile" then
131
- list = provisioning_profile_list_info
132
- end
133
- puts(list) if @debug_log == true
108
+ # Certificate Information for target name
109
+ # @return
110
+ # expire_datetime: deadline
111
+ # limit_days: limit days
112
+ # cname: CN
113
+ def self.certificate_info_for(name:)
114
+ raise "do not set name param" if name.nil?
134
115
 
135
- danger_list = []
136
- list.each do |info|
137
- danger_list << info if info[:limit_days].to_i <= days.to_i
116
+ info = []
117
+ begin
118
+ temp_pem_file = certificate_exchange_pem_file_for(name: name)
119
+ result = `openssl crl2pkcs7 -nocrl -certfile #{temp_pem_file.path} | openssl pkcs7 -print_certs -text -noout`
120
+
121
+ expire_datetime_match = result.scan(/.*Not After :(.*)/)
122
+ raise "not exits expire date" if expire_datetime_match.nil?
123
+
124
+ cname_match = result.match(/Subject: .* CN=(.*), OU=.*/)
125
+ raise "not exists cname:#{result}" if cname_match.nil?
126
+
127
+ expire_datetime_match.each do |original_datetime|
128
+ expire_datetime = Time.parse(original_datetime.first)
129
+ limit_days = calc_limit_days(datetime: expire_datetime)
130
+ cname = cname_match[1]
131
+
132
+ info << {
133
+ :expire_datetime => expire_datetime,
134
+ :limit_days => limit_days,
135
+ :cname => cname
136
+ }
137
+ end
138
+ rescue StandardError => e
139
+ raise(e.message)
140
+ ensure
141
+ temp_pem_file.close && temp_pem_file.unlink
138
142
  end
139
143
 
140
- danger_list
144
+ return info
141
145
  end
142
146
 
147
+
148
+ private
143
149
  def self.certificate_list_for(name:)
144
150
  result = `security find-certificate -a -c "#{name}"`
145
151
  name_match_list = result.scan(/.*alis".*=\"(.*)\".*/)
146
152
  puts(name_match_list) if @debug_log == true
147
153
 
148
154
  info = []
149
- name_match_list.each do|name_match|
155
+ name_match_list.uniq.each do|name_match|
150
156
  info << certificate_info_for(name:name_match[0])
151
157
  end
152
158
 
153
- info
159
+ info.flatten!
160
+ end
161
+
162
+ # filtering list
163
+ def self.filtering_limit_days_for(list:, days:)
164
+ danger_list = []
165
+ list.each do |info|
166
+ danger_list << info if info[:limit_days].to_i <= days.to_i
167
+ end
168
+
169
+ danger_list
170
+ end
171
+
172
+ # exchange pem file
173
+ # @param name: unique name
174
+ def self.certificate_exchange_pem_file_for(name:)
175
+ temp_pem_file = Tempfile.new(::File.basename("temp_pem"))
176
+ `security find-certificate -a -c "#{name}" -p > #{temp_pem_file.path}`
177
+
178
+ temp_pem_file
154
179
  end
155
180
 
156
181
  def self.calc_limit_days(datetime:)
@@ -1,3 +1,3 @@
1
1
  module AppleCertsInfo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
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-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: