Class: AgentSmith::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/agent_smith.rb

Instance Method Summary collapse

Instance Method Details

#delete_allObject



14
15
16
17
18
19
20
21
# File 'lib/agent_smith.rb', line 14

def delete_all
	prov_profiles = Dir["#{PROVISIONING_PATH}/*.mobileprovision"]
	prov_profiles.each do |file|
		system "rm \"#{file}\""
		puts "#{File.basename(file)} removed"
	end
	puts "done"
end

#installObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/agent_smith.rb', line 33

def install
	Dir.mktmpdir do |dir| 
		
		system "git clone #{options[:repo]} #{dir} &> /dev/null"
		certificate = open(APPLE_ROOT_CERTIFICATE_URL).read()

		prov_profiles = Dir["#{dir}/*.mobileprovision"]
		puts "#{prov_profiles.count} provisioning profiles found"

		prov_profiles.each do |prov_profile|


			prov_profile_content = File.read(prov_profile)
			p7 = OpenSSL::PKCS7.new(prov_profile_content)
			store = OpenSSL::X509::Store.new
			
			cert = OpenSSL::X509::Certificate.new(certificate)
			store.add_cert(cert)
			verification = p7.verify([cert], store)

			if verification
				plist = Plist::parse_xml(p7.data)
				uuid = plist["UUID"]
				system "cp #{prov_profile} #{PROVISIONING_PATH.gsub(" ","\\ ")}#{uuid}.mobileprovision"
				puts "#{File.basename(prov_profile)} installed"
			else
				puts "#{File.basename(prov_profile)} is not valid"
			end

		end
	end
end