This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
/
EEAppleServices.m
616 lines (459 loc) · 27.9 KB
/
EEAppleServices.m
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//
// EEAppleServices.m
// Extender Installer
//
// Created by Matt Clarke on 28/04/2017.
//
//
#import "EEAppleServices.h"
#import "NSData+GZIP.h"
#import "RPVAuthentication.h"
#import "AuthKit.h"
@interface EEAppleServices ()
@property (nonatomic, strong) NSString *teamid;
@property (nonatomic, strong) NSURLCredential* credentials;
@property (nonatomic, strong) RPVAuthentication *authentication;
@end
@implementation EEAppleServices
+ (instancetype)sharedInstance {
static EEAppleServices *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[EEAppleServices alloc] init];
});
return sharedInstance;
}
- (instancetype)init {
self = [super init];
if (self) {
self.teamid = @"";
self.authentication = [[RPVAuthentication alloc] init];
}
return self;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private methods.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (NSMutableURLRequest*)populateHeaders:(NSMutableURLRequest*)request {
NSDictionary<NSString *, NSString *> *appleHeaders = [self.authentication appleIDHeadersForRequest:request];
AKDevice* currentDevice = [AKDevice currentDevice];
NSDictionary<NSString *, NSString *> *httpHeaders = @{
@"Content-Type": @"text/x-xml-plist",
@"User-Agent": @"Xcode",
@"Accept": @"text/x-xml-plist",
@"Accept-Language": @"en-us",
@"Connection": @"keep-alive",
@"X-Xcode-Version": @"11.2 (11B52)",
@"X-Apple-I-Identity-Id": [[self.credentials user] componentsSeparatedByString:@"|"][0],
@"X-Apple-GS-Token": [self.credentials password],
@"X-Mme-Device-Id": [currentDevice uniqueDeviceIdentifier],
};
[httpHeaders enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[request setValue:value forHTTPHeaderField:key];
}];
[appleHeaders enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[request setValue:value forHTTPHeaderField:key];
}];
[request.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
NSLog(@"%@: %@", key, value);
}];
return request;
}
- (void)_doActionWithName:(NSString*)action systemType:(EESystemType)systemType extraDictionary:(NSDictionary*)extra andCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSString *os = @"";
if (systemType != EESystemTypeUndefined)
os = systemType == EESystemTypeiOS || systemType == EESystemTypewatchOS ? @"ios/" : @"tvos/";
NSString *urlStr = [NSString stringWithFormat:@"https://developerservices2.apple.com/services/QH65B2/%@%@?clientId=XABBG36SBA", os,action];
NSLog(@"Request to URL: %@", urlStr);
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]];
request.HTTPMethod = @"POST";
request = [self populateHeaders:request];
// Now, body.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:@"XABBG36SBA" forKey:@"clientId"];
[dict setObject:@"QH65B2" forKey:@"protocolVersion"];
[dict setObject:[[NSUUID UUID] UUIDString] forKey:@"requestId"];
[dict setObject:@[@"en_US"] forKey:@"userLocale"];
// Automatically switch this dependant on device type.
/*
* Available options:
* mac
* ios
* tvos
* watchos
*/
switch (systemType) {
case EESystemTypeiOS:
[dict setObject:@"ios" forKey:@"DTDK_Platform"];
//[dict setObject:@"ios" forKey:@"subPlatform"];
break;
case EESystemTypewatchOS:
[dict setObject:@"watchos" forKey:@"DTDK_Platform"];
//[dict setObject:@"watchOS" forKey:@"subPlatform"];
break;
case EESystemTypetvOS:
[dict setObject:@"tvos" forKey:@"DTDK_Platform"];
[dict setObject:@"tvOS" forKey:@"subPlatform"];
break;
default:
break;
}
if (extra) {
for (NSString *key in extra.allKeys) {
if ([extra objectForKey:key]) // do a nil check.
[dict setObject:[extra objectForKey:key] forKey:key];
}
}
// We want this as an XML plist.
NSData *data = [NSPropertyListSerialization dataWithPropertyList:dict format:NSPropertyListXMLFormat_v1_0 options:0 error:nil];
[request setHTTPBody:data];
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration ephemeralSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:nil delegateQueue:nil];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error || !data) {
completionHandler(error, nil);
} else {
NSData* unpacked = [data isGzippedData] ? [data gunzippedData] : data;
NSDictionary *plist = [NSPropertyListSerialization propertyListWithData:unpacked options:NSPropertyListImmutable format:nil error:nil];
if (!plist)
completionHandler(error,nil);
else
// Hit the completion handler.
completionHandler(nil, plist);
}
}];
[task resume];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Sign-In methods.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)ensureSessionWithIdentity:(NSString*)identity gsToken:(NSString*)token andCompletionHandler:(void (^)(NSError *error, NSDictionary *plist))completionHandler {
self.credentials = [[NSURLCredential alloc] initWithUser:identity password:token persistence:NSURLCredentialPersistencePermanent];
// TODO: Validate credentials
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
[resultDictionary setObject:@"authenticated" forKey:@"reason"];
[resultDictionary setObject:@"" forKey:@"userString"];
completionHandler(nil, resultDictionary);
}
- (void)signInWithUsername:(NSString *)username password:(NSString *)password andCompletionHandler:(void (^)(NSError *, NSDictionary *, NSURLCredential*))completionHandler {
[self.authentication authenticateWithUsername:username password:password withCompletion:^(NSError *error, NSString *userIdentity, NSString *gsToken) {
if (error) {
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
if (error.code == -22406) {
[resultDictionary setObject:@"Your Apple ID or password is incorrect. App-specific passwords are not supported." forKey:@"userString"];
[resultDictionary setObject:@"incorrectCredentials" forKey:@"reason"];
} else if (error.code == 5000) { // Internal error
[resultDictionary setObject:error.localizedDescription forKey:@"userString"];
[resultDictionary setObject:@"incorrectCredentials" forKey:@"reason"];
} else if (error.code == 4010 || error.code == 4011) {
[resultDictionary setObject:@"2FA code is required" forKey:@"userString"];
[resultDictionary setObject:@"appSpecificRequired" forKey:@"reason"];
} else {
if (![error.localizedDescription isEqualToString:@""]) {
[resultDictionary setObject:[NSString stringWithFormat:@"%@ (%ld)", error.localizedDescription, (long)error.code] forKey:@"userString"];
} else {
[resultDictionary setObject:[NSString stringWithFormat:@"Unknown error occurred (%ld)", (long)error.code] forKey:@"userString"];
}
[resultDictionary setObject:@"incorrectCredentials" forKey:@"reason"];
}
completionHandler(nil, resultDictionary, nil);
return;
}
self.credentials = [[NSURLCredential alloc] initWithUser:userIdentity password:gsToken persistence:NSURLCredentialPersistencePermanent];
// Do a request to listTeams.action to check that the user is a member of a team
[self listTeamsWithCompletionHandler:^(NSError *error, NSDictionary *plist) {
NSArray *teams = [plist objectForKey:@"teams"];
if (!teams) {
// Error of some kind?
// TODO: HANDLE ME
completionHandler(error, plist, nil);
return;
}
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
[resultDictionary setObject:@"" forKey:@"userString"];
[resultDictionary setObject:@"authenticated" forKey:@"reason"];
completionHandler(nil, resultDictionary, self.credentials);
}];
}];
}
- (void)requestTwoFactorLoginCodeWithCompletionHandler:(void (^)(NSError*))completion {
[self.authentication requestLoginCodeWithCompletion:completion];
}
- (void)validateLoginCode:(NSString*)code andCompletionHandler:(void (^)(NSError*, NSDictionary*, NSURLCredential*))completionHandler {
[self.authentication validateLoginCode:code withCompletion:^(NSError *error, NSString *userIdentity, NSString *gsToken) {
if (error) {
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
if (error.code == 4012) {
[resultDictionary setObject:@"2FA code is incorrect" forKey:@"userString"];
[resultDictionary setObject:@"incorrectCredentials" forKey:@"reason"];
} else {
if (![error.localizedDescription isEqualToString:@""]) {
[resultDictionary setObject:[NSString stringWithFormat:@"%@ (%ld)", error.localizedDescription, (long)error.code] forKey:@"userString"];
} else {
[resultDictionary setObject:[NSString stringWithFormat:@"Unknown error occurred (%ld)", (long)error.code] forKey:@"userString"];
}
[resultDictionary setObject:@"incorrectCredentials" forKey:@"reason"];
}
completionHandler(nil, resultDictionary, nil);
return;
}
self.credentials = [[NSURLCredential alloc] initWithUser:userIdentity password:gsToken persistence:NSURLCredentialPersistencePermanent];
// Do a request to listTeams.action to check that the user is a member of a team
[self listTeamsWithCompletionHandler:^(NSError *error, NSDictionary *plist) {
NSArray *teams = [plist objectForKey:@"teams"];
if (!teams) {
// Error of some kind?
// TODO: HANDLE ME
completionHandler(error, plist, nil);
return;
}
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
[resultDictionary setObject:@"" forKey:@"userString"];
[resultDictionary setObject:@"authenticated" forKey:@"reason"];
completionHandler(nil, resultDictionary, self.credentials);
}];
}];
}
- (void)fallback2FACodeRequest:(void(^)(NSError *, NSDictionary *, NSURLCredential *))completionHandler {
[self.authentication fallback2FACodeRequest:^(NSError *error, NSString *userIdentity, NSString *gsToken) {
if (error) {
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
if (error.code == 4012) {
[resultDictionary setObject:@"2FA code is incorrect" forKey:@"userString"];
[resultDictionary setObject:@"incorrectCredentials" forKey:@"reason"];
} else {
if (![error.localizedDescription isEqualToString:@""]) {
[resultDictionary setObject:[NSString stringWithFormat:@"%@ (%ld)", error.localizedDescription, (long)error.code] forKey:@"userString"];
} else {
[resultDictionary setObject:[NSString stringWithFormat:@"Unknown error occurred (%ld)", (long)error.code] forKey:@"userString"];
}
[resultDictionary setObject:@"incorrectCredentials" forKey:@"reason"];
}
completionHandler(nil, resultDictionary, nil);
return;
}
self.credentials = [[NSURLCredential alloc] initWithUser:userIdentity password:gsToken persistence:NSURLCredentialPersistencePermanent];
// Do a request to listTeams.action to check that the user is a member of a team
[self listTeamsWithCompletionHandler:^(NSError *error, NSDictionary *plist) {
NSArray *teams = [plist objectForKey:@"teams"];
if (!teams) {
// Error of some kind?
// TODO: HANDLE ME
completionHandler(error, plist, nil);
return;
}
NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
[resultDictionary setObject:@"" forKey:@"userString"];
[resultDictionary setObject:@"authenticated" forKey:@"reason"];
completionHandler(nil, resultDictionary, self.credentials);
}];
}];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Team ID methods.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (NSString*)currentTeamID {
return self.teamid;
}
- (void)updateCurrentTeamIDWithTeamIDCheck:(NSString* (^)(NSArray*))teamIDCallback andCallback:(void (^)(NSError*, NSString *))completionHandler {
// We also want to pull the Team ID for this user, rather than find it on installation.
[self listTeamsWithCompletionHandler:^(NSError *error, NSDictionary *plist) {
if (error) {
// XXX: It is possible for a user to never have signed up for a development
// account with Apple with their existing ID. Thus, we should hit here if
// that's the case!
self.teamid = @"";
completionHandler(error, @"");
return;
}
NSArray *teams = [plist objectForKey:@"teams"];
if (!teams) {
completionHandler(error, @"");
return;
}
NSString *teamId;
// If there are multiple teams this user is in, request which one they want to use.
if (teams.count > 1) {
teamId = teamIDCallback(teams);
} else if (teams.count == 1) {
NSDictionary *onlyTeam = teams[0];
teamId = [onlyTeam objectForKey:@"teamId"];
} else {
completionHandler(error, @"");
return;
}
self.teamid = teamId;
completionHandler(error, self.teamid);
}];
}
- (void)viewDeveloperWithCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
[self _doActionWithName:@"viewDeveloper.action" systemType:EESystemTypeUndefined extraDictionary:nil andCompletionHandler:^(NSError * error, NSDictionary *plist) {
if (error) {
completionHandler(error, nil);
} else {
// Hit the completion handler.
completionHandler(nil, plist);
}
}];
}
- (void)listTeamsWithCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
[self _doActionWithName:@"listTeams.action" systemType:EESystemTypeUndefined extraDictionary:nil andCompletionHandler:^(NSError *error, NSDictionary *plist) {
if (error) {
completionHandler(error, nil);
} else {
// Hit the completion handler.
completionHandler(nil, plist);
}
}];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Device methods
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)addDevice:(NSString*)udid deviceName:(NSString*)name forTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:udid forKey:@"deviceNumber"];
[extra setObject:name forKey:@"name"];
[self _doActionWithName:@"addDevice.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)listDevicesForTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:@"500" forKey:@"pageSize"];
[extra setObject:@"1" forKey:@"pageNumber"];
[extra setObject:@"name=asc" forKey:@"sort"];
[extra setObject:@"false" forKey:@"includeRemovedDevices"];
[self _doActionWithName:@"listDevices.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Application ID methods.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)listAllApplicationsForTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[self _doActionWithName:@"listAppIds.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)addApplicationId:(NSString*)applicationIdentifier name:(NSString*)applicationName enabledFeatures:(NSDictionary*)enabledFeatures teamID:(NSString*)teamID entitlements:(NSDictionary*)entitlements systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:applicationIdentifier forKey:@"identifier"];
[extra setObject:applicationName forKey:@"name"];
[extra setObject:@"explicit" forKey:@"type"];
// Features - assume caller has correctly set "on", "off", "whatever"
for (NSString *key in [enabledFeatures allKeys]) {
[extra setObject:[enabledFeatures objectForKey:key] forKey:key];
}
[extra setObject:entitlements forKey:@"entitlements"];
[self _doActionWithName:@"addAppId.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)updateApplicationIdId:(NSString*)appIdId enabledFeatures:(NSDictionary*)enabledFeatures teamID:(NSString*)teamID entitlements:(NSDictionary*)entitlements systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler; {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:appIdId forKey:@"appIdId"];
[extra setObject:@"explicit" forKey:@"type"];
// Features - assume caller has correctly set "on", "off", "whatever"
for (NSString *key in [enabledFeatures allKeys]) {
[extra setObject:[enabledFeatures objectForKey:key] forKey:key];
}
[extra setObject:entitlements forKey:@"entitlements"];
[self _doActionWithName:@"updateAppId.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)deleteApplicationIdId:(NSString*)appIdId teamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:appIdId forKey:@"appIdId"];
[self _doActionWithName:@"deleteAppId.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)listAllApplicationGroupsForTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
// CHECKME: is this the right dictionary?
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[self _doActionWithName:@"listApplicationGroups.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)addApplicationGroupWithIdentifier:(NSString*)identifier andName:(NSString*)groupName forTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:identifier forKey:@"identifier"];
[extra setObject:groupName forKey:@"name"];
[self _doActionWithName:@"addApplicationGroup.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)assignApplicationGroup:(NSString*)applicationGroup toApplicationIdId:(NSString*)appIdId teamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:appIdId forKey:@"appIdId"];
[extra setObject:applicationGroup forKey:@"applicationGroups"];
[self _doActionWithName:@"assignApplicationGroupToAppId.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Certificates methods.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)listAllDevelopmentCertificatesForTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[self _doActionWithName:@"listAllDevelopmentCerts.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)listAllProvisioningProfilesForTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[self _doActionWithName:@"listProvisioningProfiles.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)getProvisioningProfileForAppIdId:(NSString*)appIdId withTeamID:(NSString*)teamID systemType:(EESystemType)systemType andCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:appIdId forKey:@"appIdId"];
[self _doActionWithName:@"downloadTeamProvisioningProfile.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)deleteProvisioningProfileForApplication:(NSString*)applicationId andTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
[self listAllProvisioningProfilesForTeamID:teamID systemType:systemType withCompletionHandler:^(NSError *error, NSDictionary *plist) {
if (error) {
completionHandler(error, nil);
return;
}
NSArray *provisioningProfiles = [plist objectForKey:@"provisioningProfiles"];
// We want the provisioning profile that has an appId that matches our provided bundle identifier.
// Then, we take it's provisioningProfileId.
NSString *provisioningProfileId = @"";
for (NSDictionary *profile in provisioningProfiles) {
NSDictionary *appId = [profile objectForKey:@"appId"];
// For whatever reason, Impactor/Extender will add some extra stuff to identifier.
BOOL matches = [[appId objectForKey:@"identifier"] rangeOfString:applicationId].location != NSNotFound;
if (matches) {
provisioningProfileId = [profile objectForKey:@"provisioningProfileId"];
break;
}
}
if (![provisioningProfileId isEqualToString:@""]) {
// Onwards to deletion!
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:provisioningProfileId forKey:@"provisioningProfileId"];
[self _doActionWithName:@"deleteProvisioningProfile.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
} else {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: NSLocalizedString(@"No provisioning profile contains the provided bundle identifier.", nil),
NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"No provisioning profile contains the provided bundle identifier.", nil)
};
NSError *error = [NSError errorWithDomain:NSInvalidArgumentException
code:-1
userInfo:userInfo];
completionHandler(error, nil);
return;
}
}];
}
- (void)revokeCertificateForSerialNumber:(NSString*)serialNumber andTeamID:(NSString*)teamID systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamID forKey:@"teamId"];
[extra setObject:serialNumber forKey:@"serialNumber"];
[self _doActionWithName:@"revokeDevelopmentCert.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
- (void)submitCodeSigningRequestForTeamID:(NSString*)teamId machineName:(NSString*)machineName machineID:(NSString*)machineID codeSigningRequest:(NSData*)csr systemType:(EESystemType)systemType withCompletionHandler:(void (^)(NSError*, NSDictionary *))completionHandler {
NSString *stringifiedCSR = [[NSString alloc] initWithData:csr encoding:NSUTF8StringEncoding];
NSMutableDictionary *extra = [NSMutableDictionary dictionary];
[extra setObject:teamId forKey:@"teamId"];
[extra setObject:stringifiedCSR forKey:@"csrContent"];
[extra setObject:machineID forKey:@"machineId"];
[extra setObject:machineName forKey:@"machineName"];
[self _doActionWithName:@"submitDevelopmentCSR.action" systemType:systemType extraDictionary:extra andCompletionHandler:completionHandler];
}
@end