Class: DeviceAPI::IOS::Signing

Inherits:
Execution
  • Object
show all
Defined in:
lib/device_api/ios/signing.rb

Overview

Namespace for all methods encapsulating idevice calls

Class Method Summary collapse

Class Method Details

.get_entitlements(app_path) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/device_api/ios/signing.rb', line 66

def self.get_entitlements(app_path)
  app_path = unpack_ipa(app_path) if is_ipa?(app_path)
  result = execute("codesign -d --entitlements - #{app_path}")

  require 'pry'
  binding.pry
  if result.exit != 0
    raise SigningCommandError.new(result.stderr)
  end
  return result.stdout
end

.get_signing_certsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/device_api/ios/signing.rb', line 52

def self.get_signing_certs
  result = execute('security find-identity -p codesigning -v')

  raise SigningCommandError.new(result.stderr) if result.exit != 0

  certs = []
  result.stdout.split("\n").each do |line|
    if /\)\s*(\S*)\s*"(.*)"/.match(line)
      certs << { id: Regexp.last_match[1], name: Regexp.last_match[2] }
    end
  end
  certs
end

.is_app_signed?(app_path) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/device_api/ios/signing.rb', line 29

def self.is_app_signed?(app_path)
  app_path = unpack_ipa(app_path) if is_ipa?(app_path)
  result = execute("codesign -d -vvvv '#{app_path}'")

  if result.exit != 0
    return false if /is not signed/.match(result.stderr)
    raise SigningCommandError.new(result.stderr)
  end

  true
end

.is_ipa?(path) ⇒ Boolean

Check to see if the path is an IPA

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/device_api/ios/signing.rb', line 11

def self.is_ipa?(path)
  return true if (File.extname path).downcase == '.ipa'
  false
end

.sign_app(options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/device_api/ios/signing.rb', line 41

def self.sign_app(options = {})
  cert          = options[:cert]
  entitlements  = options[:entitlements]
  app           = options[:app]

  result = execute("codesign --force --sign #{cert} --entitlements #{entitlements} '#{app}'")

  raise SigningCommandError.new(result.stderr) if result.exit != 0

end

.unpack_ipa(path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/device_api/ios/signing.rb', line 16

def self.unpack_ipa(path)
  folder = File.dirname(path)
  target = (File.basename path, (File.extname path))

  # Check to see if the target has already been unzipped
  return Dir["#{folder}/#{target}/Payload/*.app"].first if File.exists? ("#{folder}/#{target}/Payload/")

  result = execute("unzip '#{path}' -d '#{folder}/#{target}'")
  raise SigningCommandError.new(result.stderr) if result.exit != 0

  Dir["#{folder}/#{target}/Payload/*.app"].first
end