Class: PProf::ProvisioningProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/pprof/provisioning_profile.rb

Overview

Represents the content of a Provisioning Profile file

Constant Summary collapse

DEFAULT_DIR =

The default location where all the Provisioning Profiles are stored on a Mac

"#{ENV['HOME']}/Library/MobileDevice/Provisioning Profiles"

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ProvisioningProfile

Create a new ProvisioningProfile object from a file path or UUID

  • If the parameter given has the form of an UUID, a file named with this UUID and a ‘.mobileprovision` is searched in the default directory `DEFAULT_DIR`

  • Otherwise, the parameter is interpreted as a file path

Parameters:

  • file (String)

    File path or UUID of the ProvisioningProfile



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pprof/provisioning_profile.rb', line 23

def initialize(file)
  path = if file =~ /^[0-9A-F-]*$/i
           "#{PProf::ProvisioningProfile::DEFAULT_DIR}/#{file}.mobileprovision"
         else
           file
         end
  xml = nil
  begin
    pkcs7 = OpenSSL::PKCS7.new(File.read(path))
    pkcs7.verify([], OpenSSL::X509::Store.new)
    xml = pkcs7.data
    raise 'Empty PKCS7 payload' if xml.nil? || xml.empty?
  rescue StandardError
    # Seems like sometimes OpenSSL fails to parse the PKCS7 payload
    # Besides, OpenSSL is deprecated on macOS so might not be up-to-date on all machines
    # So as a fallback, we run the `security` command line.
    # (We could use `security` everytime, but invoking a command line is generally less
    #  efficient than calling the OpenSSL gem if available, so for now it's just used as fallback)
    xml = `security cms -D -i "#{path}" 2> /dev/null`
  end
  @plist = Plist.parse_xml(xml)
  raise "Unable to parse file #{file}." if @plist.nil?
end

Instance Method Details

#app_id_nameString

Note:

This is not the AppID itself, but rather the name you associated to that AppID in your Developer Portal

The name of the Application Identifier associated with this Provisioning Profile

Returns:

  • (String)


67
68
69
# File 'lib/pprof/provisioning_profile.rb', line 67

def app_id_name
  @plist['AppIDName']
end

#app_id_prefixString

The AppID prefix (which is typically the ID of the team)

Returns:

  • (String)


74
75
76
# File 'lib/pprof/provisioning_profile.rb', line 74

def app_id_prefix
  @plist['ApplicationIdentifierPrefix']
end

#creation_dateDateTime

The Creation date of this Provisioning Profile

Returns:

  • (DateTime)


81
82
83
# File 'lib/pprof/provisioning_profile.rb', line 81

def creation_date
  @plist['CreationDate']
end

#developer_certificatesArray<OpenSSL::X509::Certificate>

The list of X509 Developer Certificates associated with this profile

Returns:

  • (Array<OpenSSL::X509::Certificate>)


117
118
119
120
121
# File 'lib/pprof/provisioning_profile.rb', line 117

def developer_certificates
  @plist['DeveloperCertificates'].map do |data|
    OpenSSL::X509::Certificate.new(data.string)
  end
end

#entitlementsEntitlements

All the entitlements associated with this Provisioning Profile

Returns:



126
127
128
# File 'lib/pprof/provisioning_profile.rb', line 126

def entitlements
  PProf::Entitlements.new(@plist['Entitlements'])
end

#expiration_dateDateTime

The expiration date of this Provisioning Profile

Returns:

  • (DateTime)


88
89
90
# File 'lib/pprof/provisioning_profile.rb', line 88

def expiration_date
  @plist['ExpirationDate']
end

#nameString

The name of the Provisioning Profile

Returns:

  • (String)


50
51
52
# File 'lib/pprof/provisioning_profile.rb', line 50

def name
  @plist['Name']
end

#provisioned_devicesArray<String>

The list of devices provisioned with this Provisioning Profile (if any)

Returns:

  • (Array<String>)


133
134
135
# File 'lib/pprof/provisioning_profile.rb', line 133

def provisioned_devices
  @plist['ProvisionedDevices']
end

#provisions_all_devicesBool

Indicates if this Provisioning Profile is provisioned for all devices or only for a list of some specific devices

Returns:

  • (Bool)


141
142
143
# File 'lib/pprof/provisioning_profile.rb', line 141

def provisions_all_devices
  @plist['ProvisionsAllDevices'] || false
end

#team_idsArray<String>

Note:

typically Provisioning Profiles contain only one team

The Team IDs associated with this Provisioning Profile

Returns:

  • (Array<String>)


103
104
105
# File 'lib/pprof/provisioning_profile.rb', line 103

def team_ids
  @plist['TeamIdentifier']
end

#team_nameString

The name of the Team associated with this Provisioning Profile

Returns:

  • (String)


110
111
112
# File 'lib/pprof/provisioning_profile.rb', line 110

def team_name
  @plist['TeamName']
end

#to_hashHash

The hash representation of this Provisioning Profile

Returns:

  • (Hash)


148
149
150
# File 'lib/pprof/provisioning_profile.rb', line 148

def to_hash
  @plist
end

#to_sString

The human-readable string representation of this Provisioning Profile Typically suitable for printing this Provisioning Profile information to the user.

Returns:

  • (String)


156
157
158
159
160
161
162
163
164
165
166
# File 'lib/pprof/provisioning_profile.rb', line 156

def to_s
  lines = %i[name uuid app_id_name app_id_prefix creation_date expiration_date ttl team_ids team_name].map do |key|
    "- #{key}: #{send(key.to_sym)}"
  end +
          [
            "- #{developer_certificates.count} Developer Certificates",
            "- #{provisioned_devices.count} Provisioned Devices",
            '- Entitlements:'
          ] + entitlements.to_hash.map { |key, value| "   - #{key}: #{value}" }
  lines.join("\n")
end

#ttlInt

The Time-To-Live of this Provisioning Profile

Returns:

  • (Int)


94
95
96
# File 'lib/pprof/provisioning_profile.rb', line 94

def ttl
  @plist['TimeToLive'].to_i
end

#uuidString

The UUID of the Provisioning Profile

Returns:

  • (String)


57
58
59
# File 'lib/pprof/provisioning_profile.rb', line 57

def uuid
  @plist['UUID']
end