Class: Provisioning

Inherits:
Object
  • Object
show all
Defined in:
lib/provisinfo/provisioning.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ Provisioning

by default, it will load the first .mobileprovision file in current directory



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/provisinfo/provisioning.rb', line 26

def initialize(filename = nil)   
  if filename.nil?
   @filename = self.class.list_provisioning_files().first 
 else
    @filename = filename
  end	   

  if @filename
   self.load_from_file()  	    
  else
    @name ="Unknown"
  end
 
end

Instance Attribute Details

#appIDObject

Returns the value of attribute appID.



19
20
21
# File 'lib/provisinfo/provisioning.rb', line 19

def appID
  @appID
end

#expirationDateObject

Returns the value of attribute expirationDate.



22
23
24
# File 'lib/provisinfo/provisioning.rb', line 22

def expirationDate
  @expirationDate
end

#filenameObject

Returns the value of attribute filename.



21
22
23
# File 'lib/provisinfo/provisioning.rb', line 21

def filename
  @filename
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/provisinfo/provisioning.rb', line 16

def name
  @name
end

#teamIDObject

Returns the value of attribute teamID.



20
21
22
# File 'lib/provisinfo/provisioning.rb', line 20

def teamID
  @teamID
end

#typeObject

Returns the value of attribute type.



17
18
19
# File 'lib/provisinfo/provisioning.rb', line 17

def type
  @type
end

#uuidObject

Returns the value of attribute uuid.



18
19
20
# File 'lib/provisinfo/provisioning.rb', line 18

def uuid
  @uuid
end

Class Method Details

.list_provisioning_filesObject



54
55
56
57
58
59
60
# File 'lib/provisinfo/provisioning.rb', line 54

def self.list_provisioning_files()
  provisioning_file_paths = []
 Dir.entries('.').each do |path|
   provisioning_file_paths << path if path=~ /.*\.mobileprovision$/
 end
 provisioning_file_paths
end

Instance Method Details

#is_expiredObject



62
63
64
65
# File 'lib/provisinfo/provisioning.rb', line 62

def is_expired()
  now = DateTime.now
  return self.expirationDate < now
end

#load_from_fileObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/provisinfo/provisioning.rb', line 43

def load_from_file()    
  xml_raw = `security cms -D -i #{@filename}` 
 xml_parsed = Plist::parse_xml(xml_raw)   
  @teamID = xml_parsed['Entitlements']['com.apple.developer.team-identifier']
 @name = xml_parsed['Name']
 @uuid = xml_parsed['UUID']    
 @appID = xml_parsed['Entitlements']['application-identifier']
  @expirationDate = xml_parsed['ExpirationDate']

end

#matches_certificate?(certificate_filename, password) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/provisinfo/provisioning.rb', line 76

def matches_certificate?(certificate_filename, password)

  if certificate_filename.nil? or not File.exists?(certificate_filename)
    abort("can't find the certificate file.")
  end

  profile = File.read(self.filename)
  certificate = File.read(certificate_filename)
  p7 = OpenSSL::PKCS7.new(profile)
  cert = OpenSSL::PKCS12.new(certificate, password)
  store = OpenSSL::X509::Store.new
  p7.verify([], store)

  plist = REXML::Document.new(p7.data)
  plist.elements.each('/plist/dict/key') do |ele|
  if ele.text == "DeveloperCertificates"
    keys = ele.next_element
    key = keys.get_elements('//array/data')[0].text

    key = key.scan(/.{1,64}/).join("\n")

    profile_cert = "-----BEGIN CERTIFICATE-----\n" + key.gsub(/\t/, "") + "\n-----END CERTIFICATE-----\n"
    
    @provisioning_cert = OpenSSL::X509::Certificate.new(profile_cert)
  end
end

return @provisioning_cert.to_s != cert.certificate.to_s
end

#show_infoObject



67
68
69
70
71
72
73
74
# File 'lib/provisinfo/provisioning.rb', line 67

def show_info()
  puts "Name:"+self.name
  puts "UUDID:"+self.uuid 
  puts "AppID:"+self.appID 
  puts "TeamID:"+self.teamID
  puts "ExpirationDate:"+self.expirationDate.strftime("%c")
  
end