applecert 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27a0f9ed8ded62f11a7bd7c14b1063a7ad0a478c
4
+ data.tar.gz: 22e9d864adfb79ae24a51f0f1cefd3637b72d289
5
+ SHA512:
6
+ metadata.gz: f60ea233942071f9442fbed8aa4a0ec81377442bb0a75b9bcde4d192a15e2d6e79146b23d7f80e6c1e79f404c6f3cb9b4f57e8ce0d5c1665b02ec4ebacf63a77
7
+ data.tar.gz: a4ffeacdec39a16d96e5123346835b1c52960b2135db42756f20d1bf1f721ad03077306f23c5fe303d2a523b006fb44aa4a22086a4946fcbe02c840c9c4abbf8
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "AppleCert"
4
+
5
+
6
+
@@ -0,0 +1,8 @@
1
+ require "AppleCert/version"
2
+ require File.expand_path('../AppleCert/Command/init', __FILE__)
3
+ module AppleCert
4
+ # Your code goes here...
5
+ end
6
+
7
+
8
+ AppleCert::Command::Init.start(ARGV)
@@ -0,0 +1,25 @@
1
+
2
+ require 'thor'
3
+ require File.expand_path('../../Core/Provision/provisioning',__FILE__)
4
+ module AppleCert
5
+ class Command
6
+ class Init < Thor
7
+ desc "prov [command]", "for manager provisioning, can be -d, -f. -de"
8
+ option :d, :desc => "Delete file by UUID"
9
+ option :f, :desc => "Show info for UUID"
10
+ option :de, :desc => "Delete Expired"
11
+ def prov()
12
+ man = AppleCert::Provisioning.new()
13
+ if !options[:f].nil?
14
+ man.showInfo(options[:f])
15
+ elsif !options[:d].nil?
16
+ man.removefile(options[:d])
17
+ elsif !options[:de].nil?
18
+ man.removeExpired
19
+ else
20
+ man.list
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,212 @@
1
+ require 'openssl'
2
+ require 'plist'
3
+ require 'colorize'
4
+ require 'nokogiri'
5
+
6
+ class PROV_TYPE
7
+ DEV='Develop'
8
+ ADHOC='AdHoc'
9
+ APPSTORE='AppStore'
10
+ INHOUSE='InHouse'
11
+ end
12
+
13
+ module AppleCert
14
+ class Provisioning
15
+ FOLDER_PATH = ENV['HOME']+ "/Library/MobileDevice/Provisioning Profiles"
16
+
17
+ def list
18
+ result = self.getAllProfileInfo(FOLDER_PATH)
19
+ self.printlist(result)
20
+ end
21
+
22
+
23
+ def get_profile_info(provisioning_profile_path)
24
+ profile_contents = File.open(provisioning_profile_path).read
25
+ profile_contents = profile_contents.slice(profile_contents.index('<?'), profile_contents.length)
26
+ info = {}
27
+ keys = ['UUID','application-identifier','Name','CreationDate','aps-environment','ExpirationDate']
28
+ doc = Nokogiri.XML(profile_contents)
29
+ # puts "#{doc}"
30
+ keys.each do |key|
31
+ value = doc.xpath("\/\/key[text()=\"#{key}\"]")[0]
32
+ if value.to_s.length>0
33
+ value = value.next_element.text
34
+ info[key] = value
35
+ end
36
+ end
37
+
38
+ keys = ['ProvisionedDevices','DeveloperCertificates']
39
+ keys.each do |key|
40
+ node = doc.xpath("\/\/key[text()=\"#{key}\"]")[0]
41
+ arr = Array.new()
42
+ if node.to_s.length>0
43
+ node.next_element.children.each do |nodes|
44
+ if nodes.text.strip.to_s.length > 0
45
+ arr.push(nodes.text.strip)
46
+ end
47
+ end
48
+ end
49
+ info[key] = arr
50
+ end
51
+
52
+ isEnterprise = false
53
+ key = 'ProvisionsAllDevices'
54
+ if node = doc.xpath("\/\/key[text()=\"#{key}\"]")[0]
55
+ if node.to_s.length>0
56
+ if node.next_element.name.downcase == 'true'
57
+ isEnterprise = true
58
+ end
59
+ end
60
+ end
61
+
62
+ certlist = Array.new()
63
+ if !info['DeveloperCertificates'].nil?
64
+ values = info['DeveloperCertificates']
65
+ index = 0
66
+ values.each do |item|
67
+ decode_base64_content = Base64.decode64(item)
68
+ cert = OpenSSL::X509::Certificate.new(decode_base64_content)
69
+ certlist.push(cert.subject.to_s)
70
+ if index == 0
71
+ if cert.subject.to_s.match('/CN=iPhone Developer')
72
+ info[:cert_type] = PROV_TYPE::DEV
73
+ elsif !info['ProvisionedDevices'].nil? && info['ProvisionedDevices'].length > 0
74
+ info[:cert_type] = PROV_TYPE::ADHOC
75
+ elsif isEnterprise
76
+ info[:cert_type] = PROV_TYPE::INHOUSE
77
+ else
78
+ info[:cert_type] = PROV_TYPE::APPSTORE
79
+ end
80
+ regex = /\/O=(.*)\/C/
81
+ name = cert.subject.to_s.scan(regex)
82
+ if name.length > 0 && name[0].length > 0
83
+ info[:team_name] = name.first.first
84
+ else
85
+ info[:team_name] = ""
86
+ end
87
+ end
88
+ index += 1
89
+ end
90
+ info['DeveloperCertificates'] = certlist
91
+ end
92
+ return info
93
+ end
94
+
95
+ def getAllProfileInfo(path)
96
+ result = {}
97
+ list = Dir["#{path}/*"]
98
+ list.each do |profilePath|
99
+ obj = get_profile_info(profilePath)
100
+ app_id = obj['application-identifier']
101
+ cert_type_dict = {}
102
+ if !result[app_id].nil?
103
+ cert_type_dict = result[app_id]
104
+ end
105
+ arr = Array.new()
106
+ cert_type = obj[:cert_type]
107
+ if !cert_type_dict[cert_type].nil?
108
+ arr = cert_type_dict[cert_type]
109
+ end
110
+ arr.push(obj)
111
+ cert_type_dict[cert_type] = arr
112
+ result[app_id] = cert_type_dict
113
+ end
114
+ return result
115
+ end
116
+
117
+ def showInfo(uuid)
118
+ profilePath = "#{FOLDER_PATH}/#{uuid.downcase}.mobileprovision"
119
+ if File.exist? profilePath
120
+ obj = get_profile_info(profilePath)
121
+ self.printAProvision(obj)
122
+ else
123
+ puts "provisioning for #{uuid} not exist".red
124
+ abort("")
125
+ end
126
+ end
127
+
128
+ def removeExpired()
129
+ expiredlist = Array.new()
130
+ result = getAllProfileInfo(FOLDER_PATH)
131
+ result.keys.sort.each.each do |app_id|
132
+ cert_type_dict = result[app_id]
133
+ cert_type_dict.each do |type, arr|
134
+ arr.each do |info|
135
+ dateStr = info['ExpirationDate']
136
+ if DateTime.now > DateTime.parse(dateStr)
137
+ expiredlist.push(info)
138
+ end
139
+ end
140
+ end
141
+ end
142
+ expiredlist.each do |info|
143
+ puts "#{info["ExpirationDate"]}\t#{info["application-identifier"]}\t#{info[:cert_type]}\t#{info["UUID"]}\t#{info["Name"]}\t#{info[:team_name]}"
144
+ self.removefile(info["UUID"])
145
+ end
146
+ end
147
+
148
+ def removefile(uuid)
149
+ profilePath = "#{FOLDER_PATH}/#{uuid.downcase}.mobileprovision"
150
+ if File.exist? profilePath
151
+ File.delete(profilePath)
152
+ else
153
+ puts "provisioning for #{uuid} not exist".red
154
+ abort("")
155
+ end
156
+ end
157
+
158
+ def printlist(result)
159
+ result.keys.sort.each.each do |app_id|
160
+ cert_type_dict = result[app_id]
161
+ puts "=========== #{app_id} ===========".green
162
+ cert_type_dict.each do |type, arr|
163
+ puts "#{type} :: #{arr[0][:team_name]}"
164
+ arr = arr.sort {|a,b| a["ExpirationDate"] <=> b["ExpirationDate"]}
165
+ arr.each do |info|
166
+ if info["aps-environment"].to_s.length>0
167
+ has_push = "[HAS_PUSH]"
168
+ end
169
+ puts " #{info["ExpirationDate"]}\t #{info["UUID"]}\t#{info["Name"]} #{has_push}"
170
+ end
171
+ end
172
+ puts ""
173
+ end
174
+ end
175
+
176
+ def printAProvision(info)
177
+ puts "=====================================".green
178
+ puts "UUID: #{info["UUID"]}"
179
+ puts "AppId: #{info['application-identifier']}"
180
+ puts "Provisioning Name: #{info['Name']}"
181
+ puts "Team Name: #{info[:team_name]}"
182
+ puts "Cert Type: #{info[:cert_type]}"
183
+ puts "ExpirationDate: #{info['ExpirationDate']}"
184
+ has_push = false
185
+ if info["aps-environment"].to_s.length>0
186
+ has_push = true
187
+ end
188
+ puts "Has Push: #{has_push}"
189
+
190
+ puts "DeveloperCertificates: "
191
+ info['DeveloperCertificates'].each do |item|
192
+ puts " #{item}"
193
+ end
194
+ if !info['ProvisionedDevices'].nil?
195
+ puts "ProvisionedDevices: "
196
+ info['ProvisionedDevices'].each do |item|
197
+ puts " #{item}"
198
+ end
199
+ end
200
+
201
+ end
202
+ end
203
+ end
204
+
205
+
206
+ # man = AppleCert::Provisioning.new()
207
+ # man.li
208
+ # man.removeExpired
209
+ # uuid = '69bb2234-82a1-44b4-bee2-f78c56e007f9'
210
+ # uuid = '4951f5cb-820b-44af-b766-67a042fbf386'
211
+ # uuid = '4ee2632b-2048-497d-978e-f62d1356436f'
212
+ # man.showInfo(uuid)
@@ -0,0 +1,3 @@
1
+ module AppleCert
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: applecert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kennix
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.19.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.19.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.7'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: plist
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: openssl
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ description: mac tools for manage apple cert and provisioing
126
+ email:
127
+ - kennixdev@gmail.com
128
+ executables:
129
+ - applecert
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - exe/applecert
134
+ - lib/AppleCert.rb
135
+ - lib/AppleCert/Command/init.rb
136
+ - lib/AppleCert/Core/Provision/provisioning.rb
137
+ - lib/AppleCert/version.rb
138
+ homepage: https://github.com/kennixdev/applecert
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.5.1
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: for manage apple cert and provisioing
162
+ test_files: []