-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprovisioning_profile.rb
More file actions
104 lines (87 loc) · 3.14 KB
/
provisioning_profile.rb
File metadata and controls
104 lines (87 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'date'
require 'time'
require 'plist'
class ProvisioningProfile
def initialize(path)
@file_path = path
@parsed_data = Hash.new
@serials = Array.new
end
def read
return @parsed_data if @parsed_data.any?
cmd = ['security', 'cms', '-D', '-i', @file_path]
begin
stdout_and_stderr, exit_status = Open3.capture2e(*cmd)
unless exit_status.success?
$file_logger.error "Error while reading provisioning profile: #{stdout_and_stderr}"
raise CollectorError
end
@parsed_data = Plist::parse_xml(stdout_and_stderr)
return @parsed_data
rescue StandardError => err
$file_logger.error "Failed to read provisioning profile #{@file_path}: #{err.message}"
raise CollectorError
end
end
def is_expired
profile_data = read
profile_expires_on = profile_data["ExpirationDate"]
$file_logger.debug "Profile expires on #{profile_expires_on.strftime("%Y/%m/%d")}"
if profile_expires_on.nil? and not profile_expires_on.instance_of?(DateTime)
$file_logger.error "Failed to parse expiry date from provisioning profile #{@file_path}"
raise CollectorError
end
expired = profile_expires_on <= DateTime.now
message = expired ? "expired" : "valid"
$file_logger.info "Provisioning profile #{@file_path} is #{message}"
expired
end
def serials
return @serials if @serials.any?
profile_data = read
certificates = profile_data["DeveloperCertificates"]
if certificates.nil? and not certificates.instance_of?(Array)
$file_logger.error "Failed to parse certificates from provisioning profile #{@file_path}"
raise CollectorError
end
serials = Array.new
certificates.each { |cert|
certificate = OpenSSL::X509::Certificate.new(cert.read)
serials.push certificate.serial
}
@serials = serials
serials
end
def has_beta_entitlements
entitlements = @parsed_data["Entitlements"] || {}
entitlements["beta-reports-active"] || false
end
def application_identifier
entitlements = @parsed_data["Entitlements"] || {}
entitlements["application-identifier"] || ""
end
def export_to_hash
base64_encoded = Base64.strict_encode64(open(@file_path).read)
{
:name => @parsed_data["Name"],
:uuid => @parsed_data["UUID"],
:serials => self.serials.map {|s| s.to_s},
:not_before => @parsed_data["CreationDate"].strftime('%Y-%m-%d %H:%M:%S'),
:not_after => @parsed_data["ExpirationDate"].strftime('%Y-%m-%d %H:%M:%S'),
:team_identifier => @parsed_data["TeamIdentifier"][0] || "",
:team_name => @parsed_data["TeamName"] || "",
:has_beta_entitlements => has_beta_entitlements,
:provisioned_devices => @parsed_data["ProvisionedDevices"] || [],
:provisions_all_devices => @parsed_data["ProvisionsAllDevices"] || false,
:application_identifier => application_identifier,
:is_wildcard_identifier => application_identifier.end_with?("*"),
:file => base64_encoded
}
end
def to_s
"#{@parsed_data['Name']} [#{@parsed_data['UUID']}]"
end
def ==(other)
self.serials == other.serials && self.class == other.class
end
end