Class: MotionProvisioning::MobileProvision

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-provisioning/mobileprovision.rb

Overview

Represents a .mobileprobision file on disk

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MobileProvision

Returns a new instance of MobileProvision.

Parameters:

  • path (String)

    : Path to the .mobileprovision file



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/motion-provisioning/mobileprovision.rb', line 8

def initialize(path)
  file = File.read(path)
  start_index = file.index("<?xml")
  end_index = file.index("</plist>") + 8
  length = end_index - start_index
  self.hash = Plist::parse_xml(file.slice(start_index, length))
  self.certificates = []
  self.enabled_services = []

  entitlements_keys = hash['Entitlements'].keys
  Service.constants.each do |constant_name|
    service = Service.const_get(constant_name)
    keys = service.mobileprovision_keys
    if (keys - entitlements_keys).empty?
      self.enabled_services << service
    end
  end

  hash['DeveloperCertificates'].each do |certificate|
    self.certificates << certificate.read
  end
end

Instance Attribute Details

#certificatesObject

Returns the value of attribute certificates.



5
6
7
# File 'lib/motion-provisioning/mobileprovision.rb', line 5

def certificates
  @certificates
end

#enabled_servicesObject

Returns the value of attribute enabled_services.



5
6
7
# File 'lib/motion-provisioning/mobileprovision.rb', line 5

def enabled_services
  @enabled_services
end

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/motion-provisioning/mobileprovision.rb', line 5

def hash
  @hash
end

Instance Method Details

#devicesObject



35
36
37
# File 'lib/motion-provisioning/mobileprovision.rb', line 35

def devices
  hash['ProvisionedDevices'].map(&:downcase)
end

#nameObject



31
32
33
# File 'lib/motion-provisioning/mobileprovision.rb', line 31

def name
  hash['Name']
end

#valid?(certificate, app_entitlements) ⇒ Boolean

Checks wether the .mobileprovision file is valid by checking its expiration date, entitlements and certificates

Parameters:

  • certificate (String)

    : Path to the certificate file

  • app_entitlements (Hash)

    : A hash containing the app’s entitlements

Returns:

  • (Boolean)

    Boolean



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/motion-provisioning/mobileprovision.rb', line 44

def valid?(certificate, app_entitlements)
  return false if hash['ExpirationDate'] < DateTime.now

  # entitlements = hash['Entitlements']
  # # Remove entitlements that are not relevant for
  # # Always true in development mobileprovision
  # entitlements.delete('get-task-allow')
  # # Always true in distribution mobileprovision
  # entitlements.delete('beta-reports-active')
  # entitlements.delete('application-identifier')
  # entitlements.delete('com.apple.developer.team-identifier')
  # # Always present, usually "$teamidentifier.*"
  # entitlements.delete('keychain-access-groups')
  # entitlements.delete('aps-environment')

  # if app_entitlements != entitlements
  #   missing_in_app = entitlements.to_a - app_entitlements.to_a
  #   if missing_in_app.any?
  #     Utils.log("Error", "These entitlements are present in the provisioning profile but not in your app configuration:")
  #     puts missing_in_app
  #   end

  #   missing_in_profile = app_entitlements.to_a - entitlements.to_a
  #   if missing_in_profile.any?
  #     Utils.log("Error", "These entitlements are present in your app configuration but not in your provisioning profile:")
  #     puts missing_in_profile
  #   end

  #   return false
  # end

  if !certificates.include?(File.read(certificate))
    Utils.log("Warning", "Your provisioning profile does not include your certificate. Repairing...")
    return false
  end

  true
end