@@ -9,25 +9,29 @@ class Export
9
9
10
10
class << self
11
11
# @param [String] bundle_identifier
12
+ # @param [String] uuid
12
13
# @return [Hash]
13
- def find_local_data ( bundle_identifier )
14
+ def find_local_data ( bundle_identifier , uuid = nil )
14
15
result_profiles = { }
15
16
teams = { }
16
- profiles . each do |profile_path |
17
- plist = analyze_profile ( profile_path )
18
- entities = plist [ 'Entitlements' ]
17
+ profile_paths = load_profile_paths
18
+ profiles = profile_paths . map { |p | profile_to_plist ( p ) }
19
+ profiles . reject! { |profile | profile [ 'UUID' ] != uuid } unless uuid . nil?
20
+
21
+ profiles . each do |profile |
22
+ entities = profile [ 'Entitlements' ]
19
23
unless entities [ 'get-task-allow' ]
20
24
team = entities [ 'com.apple.developer.team-identifier' ]
21
25
application_id = entities [ 'application-identifier' ]
22
26
application_id . slice! ( /^#{ team } \. / )
23
27
application_id = '.' + application_id if application_id == '*'
24
28
if bundle_identifier . match ( application_id ) &&
25
- DateTime . now < plist [ 'ExpirationDate' ] &&
26
- installed_certificate? ( profile_path )
29
+ DateTime . now < profile [ 'ExpirationDate' ] &&
30
+ installed_certificate? ( profile [ 'Path' ] )
27
31
28
- teams [ team ] = plist [ 'TeamName' ] if teams [ team ] . nil?
32
+ teams [ team ] = profile [ 'TeamName' ] if teams [ team ] . nil?
29
33
result_profiles [ team ] = [ ] if result_profiles [ team ] . nil?
30
- result_profiles [ team ] . push ( profile_path )
34
+ result_profiles [ team ] . push ( profile [ 'Path' ] )
31
35
end
32
36
end
33
37
end
@@ -41,11 +45,14 @@ def find_local_data(bundle_identifier)
41
45
# @param [String] profile_path
42
46
# @return [Boolean]
43
47
def installed_certificate? ( profile_path )
44
- plist = analyze_profile ( profile_path )
45
- certificate_str = plist [ 'DeveloperCertificates' ] . first . read
46
- certificate = OpenSSL ::X509 ::Certificate . new certificate_str
47
- id = OpenSSL ::Digest ::SHA1 . new ( certificate . to_der ) . to_s . upcase!
48
- installed_identies . include? ( id )
48
+ profile = profile_to_plist ( profile_path )
49
+ certs = profile [ 'DeveloperCertificates' ] . map do |cert |
50
+ certificate_str = cert . read
51
+ certificate = OpenSSL ::X509 ::Certificate . new certificate_str
52
+ id = OpenSSL ::Digest ::SHA1 . new ( certificate . to_der ) . to_s . upcase!
53
+ installed_identies . include? ( id )
54
+ end
55
+ certs . include? ( true )
49
56
end
50
57
51
58
# @return [Array]
@@ -64,25 +71,39 @@ def installed_identies
64
71
ids
65
72
end
66
73
67
- # @param [Array] profiles
74
+ # @param [Array] profile_paths
68
75
# @return [String]
69
- def select_profile ( profiles )
76
+ def select_profile ( profile_paths )
70
77
select = nil
71
78
72
- profiles . each do |profile |
73
- select = profile if adhoc? ( profile ) && select . nil?
74
- select = profile if inhouse? ( profile )
79
+ profile_paths . each do |path |
80
+ select = path if adhoc? ( path ) && select . nil?
81
+ select = path if inhouse? ( path )
75
82
end
76
83
select
77
84
end
78
85
79
86
# @param [String] profile_path
80
87
# @return [String]
81
88
def codesigning_identity ( profile_path )
82
- plist = analyze_profile ( profile_path )
83
- method = method ( profile_path )
84
- identity = "iPhone Distribution: #{ plist [ 'TeamName' ] } "
85
- identity += " (#{ plist [ 'Entitlements' ] [ 'com.apple.developer.team-identifier' ] } )" if method == AD_HOC
89
+ profile = profile_to_plist ( profile_path )
90
+ identity = nil
91
+
92
+ profile [ 'DeveloperCertificates' ] . each do |cert |
93
+ certificate_str = cert . read
94
+ certificate = OpenSSL ::X509 ::Certificate . new certificate_str
95
+ id = OpenSSL ::Digest ::SHA1 . new ( certificate . to_der ) . to_s . upcase!
96
+
97
+ available = `security find-identity -v -p codesigning`
98
+ available . split ( "\n " ) . each do |current |
99
+ next if current . include? "REVOKED"
100
+ begin
101
+ search = current . match ( /.*\) (.*) \" (.*)\" / )
102
+ identity = search [ 2 ] if id == search [ 1 ]
103
+ rescue
104
+ end
105
+ end
106
+ end
86
107
87
108
identity
88
109
end
@@ -96,46 +117,32 @@ def method(profile_path)
96
117
# @param [String] profile_path
97
118
# @return [Boolean]
98
119
def adhoc? ( profile_path )
99
- plist = analyze_profile ( profile_path )
100
- !plist [ 'Entitlements' ] [ 'get-task-allow' ] && plist [ 'ProvisionsAllDevices' ] . nil?
120
+ profile = profile_to_plist ( profile_path )
121
+ !profile [ 'Entitlements' ] [ 'get-task-allow' ] && profile [ 'ProvisionsAllDevices' ] . nil?
101
122
end
102
123
103
124
# @param [String] profile_path
104
125
# @return [Boolean]
105
126
def inhouse? ( profile_path )
106
- plist = analyze_profile ( profile_path )
107
- !plist [ 'Entitlements' ] [ 'get-task-allow' ] && !plist [ 'ProvisionsAllDevices' ] . nil?
127
+ profile = profile_to_plist ( profile_path )
128
+ !profile [ 'Entitlements' ] [ 'get-task-allow' ] && !profile [ 'ProvisionsAllDevices' ] . nil?
129
+ end
130
+
131
+ def load_profile_paths
132
+ profiles_path = File . expand_path ( "~" ) + "/Library/MobileDevice/Provisioning Profiles/*.mobileprovision"
133
+ Dir [ profiles_path ]
108
134
end
109
135
110
136
# @param [String] profile_path
111
137
# @return [Hash]
112
- def analyze_profile ( profile_path )
113
- plist = nil
138
+ def profile_to_plist ( profile_path )
114
139
File . open ( profile_path ) do |profile |
115
140
asn1 = OpenSSL ::ASN1 . decode ( profile . read )
116
141
plist_str = asn1 . value [ 1 ] . value [ 0 ] . value [ 2 ] . value [ 1 ] . value [ 0 ] . value
117
142
plist = Plist . parse_xml plist_str . force_encoding ( 'UTF-8' )
143
+ plist [ 'Path' ] = profile_path
144
+ return plist
118
145
end
119
- plist
120
- end
121
-
122
- # @return [Array]
123
- def profiles
124
- profiles = [ ]
125
- Find . find ( profile_dir_path ) do |path |
126
- next if path == profile_dir_path
127
- Find . prune if FileTest . directory? ( path )
128
- if File . extname ( path ) == PROFILE_EXTNAME
129
- profiles . push ( path )
130
- end
131
- end
132
-
133
- profiles
134
- end
135
-
136
- # @return [String]
137
- def profile_dir_path
138
- File . join ( ENV [ 'HOME' ] , 'Library/MobileDevice/Provisioning Profiles' )
139
146
end
140
147
end
141
148
end
0 commit comments