Class: DeployGate::Builds::Ios::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/deploygate/builds/ios/export.rb

Constant Summary collapse

AD_HOC =
'ad-hoc'
ENTERPRISE =
'enterprise'
SUPPORT_EXPORT_METHOD =
[AD_HOC, ENTERPRISE]
PROFILE_EXTNAME =
'.mobileprovision'

Class Method Summary collapse

Class Method Details

.adhoc?(profile_path) ⇒ Boolean

Parameters:

  • profile_path (String)

Returns:

  • (Boolean)


119
120
121
122
# File 'lib/deploygate/builds/ios/export.rb', line 119

def adhoc?(profile_path)
  profile = profile_to_plist(profile_path)
  !profile['Entitlements']['get-task-allow'] && profile['ProvisionsAllDevices'].nil?
end

.codesigning_identity(profile_path) ⇒ String

Parameters:

  • profile_path (String)

Returns:

  • (String)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/deploygate/builds/ios/export.rb', line 88

def codesigning_identity(profile_path)
  profile = profile_to_plist(profile_path)
  identity = nil

  profile['DeveloperCertificates'].each do |cert|
    certificate_str = cert.read
    certificate =  OpenSSL::X509::Certificate.new certificate_str
    id = OpenSSL::Digest::SHA1.new(certificate.to_der).to_s.upcase!

    available = `security find-identity -v -p codesigning`
    available.split("\n").each do |current|
      next if current.include? "REVOKED"
      begin
        search = current.match(/.*\) (.*) \"(.*)\"/)
        identity = search[2] if id == search[1]
      rescue
      end
    end
  end

  identity
end

.find_local_data(bundle_identifier, uuid = nil) ⇒ Hash

Parameters:

  • bundle_identifier (String)
  • uuid (String) (defaults to: nil)

Returns:

  • (Hash)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/deploygate/builds/ios/export.rb', line 14

def find_local_data(bundle_identifier, uuid = nil)
  result_profiles = {}
  teams = {}
  profile_paths = load_profile_paths
  profiles = profile_paths.map{|p| profile_to_plist(p)}
  profiles.reject! {|profile| profile['UUID'] != uuid} unless uuid.nil?

  profiles.each do |profile|
    entities = profile['Entitlements']
    unless entities['get-task-allow']
      team = entities['com.apple.developer.team-identifier']
      application_id = entities['application-identifier']
      application_id.slice!(/^#{team}\./)
      application_id = '.' + application_id if application_id == '*'
      if bundle_identifier.match(application_id) &&
          DateTime.now < profile['ExpirationDate'] &&
          installed_certificate?(profile['Path'])

        teams[team] = profile['TeamName'] if teams[team].nil?
        result_profiles[team] = [] if result_profiles[team].nil?
        result_profiles[team].push(profile['Path'])
      end
    end
  end

  {
      :teams => teams,
      :profiles => result_profiles
  }
end

.inhouse?(profile_path) ⇒ Boolean

Parameters:

  • profile_path (String)

Returns:

  • (Boolean)


126
127
128
129
# File 'lib/deploygate/builds/ios/export.rb', line 126

def inhouse?(profile_path)
  profile = profile_to_plist(profile_path)
  !profile['Entitlements']['get-task-allow'] && !profile['ProvisionsAllDevices'].nil?
end

.installed_certificate?(profile_path) ⇒ Boolean

Parameters:

  • profile_path (String)

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
# File 'lib/deploygate/builds/ios/export.rb', line 47

def installed_certificate?(profile_path)
  profile = profile_to_plist(profile_path)
  certs = profile['DeveloperCertificates'].map do |cert|
    certificate_str = cert.read
    certificate =  OpenSSL::X509::Certificate.new certificate_str
    id = OpenSSL::Digest::SHA1.new(certificate.to_der).to_s.upcase!
    installed_identies.include?(id)
  end
  certs.include?(true)
end

.installed_identiesArray

Returns:

  • (Array)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/deploygate/builds/ios/export.rb', line 59

def installed_identies
  available = `security find-identity -v -p codesigning`
  ids = []
  available.split("\n").each do |current|
    next if current.include? "REVOKED"
    begin
      (ids << current.match(/.*\) (.*) \".*/)[1])
    rescue
      # the last line does not match
    end
  end

  ids
end

.load_profile_pathsObject



131
132
133
134
# File 'lib/deploygate/builds/ios/export.rb', line 131

def load_profile_paths
  profiles_path = File.expand_path("~") + "/Library/MobileDevice/Provisioning Profiles/*.mobileprovision"
  Dir[profiles_path]
end

.method(profile_path) ⇒ String

Parameters:

  • profile_path (String)

Returns:

  • (String)


113
114
115
# File 'lib/deploygate/builds/ios/export.rb', line 113

def method(profile_path)
  adhoc?(profile_path) ? AD_HOC : ENTERPRISE
end

.profile_to_plist(profile_path) ⇒ Hash

Parameters:

  • profile_path (String)

Returns:

  • (Hash)


138
139
140
141
142
143
144
145
146
# File 'lib/deploygate/builds/ios/export.rb', line 138

def profile_to_plist(profile_path)
  File.open(profile_path) do |profile|
    asn1 = OpenSSL::ASN1.decode(profile.read)
    plist_str = asn1.value[1].value[0].value[2].value[1].value[0].value
    plist = Plist.parse_xml plist_str.force_encoding('UTF-8')
    plist['Path'] = profile_path
    return plist
  end
end

.select_profile(profile_paths) ⇒ String

Parameters:

  • profile_paths (Array)

Returns:

  • (String)


76
77
78
79
80
81
82
83
84
# File 'lib/deploygate/builds/ios/export.rb', line 76

def select_profile(profile_paths)
  select = nil

  profile_paths.each do |path|
    select = path if adhoc?(path) && select.nil?
    select = path if inhouse?(path)
  end
  select
end