15
15
static NSString *kKeyBundleIDPlistiTunesArtwork = @" softwareVersionBundleId" ;
16
16
static NSString *kKeyInfoPlistApplicationProperties = @" ApplicationProperties" ;
17
17
static NSString *kKeyInfoPlistApplicationPath = @" ApplicationPath" ;
18
+ static NSString *kFrameworksDirName = @" Frameworks" ;
18
19
static NSString *kPayloadDirName = @" Payload" ;
19
20
static NSString *kProductsDirName = @" Products" ;
20
21
static NSString *kInfoPlistFilename = @" Info.plist" ;
@@ -428,73 +429,101 @@ - (void)doEntitlementsEdit
428
429
429
430
- (void )doCodeSigning {
430
431
appPath = nil ;
432
+ frameworksDirPath = nil ;
433
+ hasFrameworks = NO ;
434
+ frameworks = [[NSMutableArray alloc ] init ];
431
435
432
436
NSArray *dirContents = [[NSFileManager defaultManager ] contentsOfDirectoryAtPath: [workingPath stringByAppendingPathComponent: kPayloadDirName ] error: nil ];
433
437
434
438
for (NSString *file in dirContents) {
435
439
if ([[[file pathExtension ] lowercaseString ] isEqualToString: @" app" ]) {
436
440
appPath = [[workingPath stringByAppendingPathComponent: kPayloadDirName ] stringByAppendingPathComponent: file];
441
+ frameworksDirPath = [appPath stringByAppendingPathComponent: kFrameworksDirName ];
437
442
NSLog (@" Found %@ " ,appPath);
438
443
appName = file;
444
+ if ([[NSFileManager defaultManager ] fileExistsAtPath: frameworksDirPath]) {
445
+ NSLog (@" Found %@ " ,frameworksDirPath);
446
+ hasFrameworks = YES ;
447
+ NSArray *frameworksContents = [[NSFileManager defaultManager ] contentsOfDirectoryAtPath: frameworksDirPath error: nil ];
448
+ for (NSString *frameworkFile in frameworksContents) {
449
+ if ([[[frameworkFile pathExtension ] lowercaseString ] isEqualTo: @" framework" ]) {
450
+ frameworkPath = [frameworksDirPath stringByAppendingPathComponent: frameworkFile];
451
+ NSLog (@" Found %@ " ,frameworkPath);
452
+ [frameworks addObject: frameworkPath];
453
+ }
454
+ }
455
+ }
439
456
[statusLabel setStringValue: [NSString stringWithFormat: @" Codesigning %@ " ,file]];
440
457
break ;
441
458
}
442
459
}
443
460
444
461
if (appPath) {
445
- NSMutableArray *arguments = [NSMutableArray arrayWithObjects: @" -fs" , [certComboBox objectValue ], nil ];
446
- NSDictionary *systemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile: @" /System/Library/CoreServices/SystemVersion.plist" ];
447
- NSString * systemVersion = [systemVersionDictionary objectForKey: @" ProductVersion" ];
448
- NSArray * version = [systemVersion componentsSeparatedByString: @" ." ];
449
- if ([version[0 ] intValue ]<10 || ([version[0 ] intValue ]==10 && ([version[1 ] intValue ]<9 || ([version[1 ] intValue ]==9 && [version[2 ] intValue ]<5 )))) {
450
-
451
- /*
452
- Before OSX 10.9, code signing requires a version 1 signature.
453
- The resource envelope is necessary.
454
- To ensure it is added, append the resource flag to the arguments.
455
- */
456
-
457
- NSString *resourceRulesPath = [[NSBundle mainBundle ] pathForResource: @" ResourceRules" ofType: @" plist" ];
458
- NSString *resourceRulesArgument = [NSString stringWithFormat: @" --resource-rules=%@ " ,resourceRulesPath];
459
- [arguments addObject: resourceRulesArgument];
462
+ if (hasFrameworks) {
463
+ [self signFile: [frameworks lastObject ]];
464
+ [frameworks removeLastObject ];
460
465
} else {
461
-
462
- /*
463
- For OSX 10.9 and later, code signing requires a version 2 signature.
464
- The resource envelope is obsolete.
465
- To ensure it is ignored, remove the resource key from the Info.plist file.
466
- */
467
-
468
- NSString *infoPath = [NSString stringWithFormat: @" %@ /Info.plist" , appPath];
469
- NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile: infoPath];
470
- [infoDict removeObjectForKey: @" CFBundleResourceSpecification" ];
471
- [infoDict writeToFile: infoPath atomically: YES ];
472
- [arguments addObject: @" --no-strict" ]; // http://stackoverflow.com/a/26204757
473
- }
474
-
475
- if (![[entitlementField stringValue ] isEqualToString: @" " ]) {
476
- [arguments addObject: [NSString stringWithFormat: @" --entitlements=%@ " , [entitlementField stringValue ]]];
466
+ [self signFile: appPath];
477
467
}
468
+ }
469
+ }
470
+
471
+ - (void )signFile : (NSString *)filePath {
472
+ NSLog (@" Codesigning %@ " , filePath);
473
+ [statusLabel setStringValue: [NSString stringWithFormat: @" Codesigning %@ " ,filePath]];
474
+
475
+ NSMutableArray *arguments = [NSMutableArray arrayWithObjects: @" -fs" , [certComboBox objectValue ], nil ];
476
+ NSDictionary *systemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile: @" /System/Library/CoreServices/SystemVersion.plist" ];
477
+ NSString * systemVersion = [systemVersionDictionary objectForKey: @" ProductVersion" ];
478
+ NSArray * version = [systemVersion componentsSeparatedByString: @" ." ];
479
+ if ([version[0 ] intValue ]<10 || ([version[0 ] intValue ]==10 && ([version[1 ] intValue ]<9 || ([version[1 ] intValue ]==9 && [version[2 ] intValue ]<5 )))) {
478
480
479
- [arguments addObjectsFromArray: [NSArray arrayWithObjects: appPath, nil ]];
480
-
481
- codesignTask = [[NSTask alloc ] init ];
482
- [codesignTask setLaunchPath: @" /usr/bin/codesign" ];
483
- [codesignTask setArguments: arguments];
484
-
485
- [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector (checkCodesigning: ) userInfo: nil repeats: TRUE ];
486
-
481
+ /*
482
+ Before OSX 10.9, code signing requires a version 1 signature.
483
+ The resource envelope is necessary.
484
+ To ensure it is added, append the resource flag to the arguments.
485
+ */
487
486
488
- NSPipe * pipe =[ NSPipe pipe ];
489
- [codesignTask setStandardOutput: pipe ];
490
- [codesignTask setStandardError: pipe ];
491
- NSFileHandle *handle=[ pipe fileHandleForReading ];
487
+ NSString *resourceRulesPath = [[ NSBundle mainBundle ] pathForResource: @" ResourceRules " ofType: @" plist " ];
488
+ NSString *resourceRulesArgument = [ NSString stringWithFormat: @" --resource-rules= %@ " ,resourceRulesPath ];
489
+ [arguments addObject: resourceRulesArgument ];
490
+ } else {
492
491
493
- [codesignTask launch ];
492
+ /*
493
+ For OSX 10.9 and later, code signing requires a version 2 signature.
494
+ The resource envelope is obsolete.
495
+ To ensure it is ignored, remove the resource key from the Info.plist file.
496
+ */
494
497
495
- [NSThread detachNewThreadSelector: @selector (watchCodesigning: )
496
- toTarget: self withObject: handle];
498
+ NSString *infoPath = [NSString stringWithFormat: @" %@ /Info.plist" , filePath];
499
+ NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile: infoPath];
500
+ [infoDict removeObjectForKey: @" CFBundleResourceSpecification" ];
501
+ [infoDict writeToFile: infoPath atomically: YES ];
502
+ [arguments addObject: @" --no-strict" ]; // http://stackoverflow.com/a/26204757
503
+ }
504
+
505
+ if (![[entitlementField stringValue ] isEqualToString: @" " ]) {
506
+ [arguments addObject: [NSString stringWithFormat: @" --entitlements=%@ " , [entitlementField stringValue ]]];
497
507
}
508
+
509
+ [arguments addObjectsFromArray: [NSArray arrayWithObjects: filePath, nil ]];
510
+
511
+ codesignTask = [[NSTask alloc ] init ];
512
+ [codesignTask setLaunchPath: @" /usr/bin/codesign" ];
513
+ [codesignTask setArguments: arguments];
514
+
515
+ [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector (checkCodesigning: ) userInfo: nil repeats: TRUE ];
516
+
517
+
518
+ NSPipe *pipe =[NSPipe pipe ];
519
+ [codesignTask setStandardOutput: pipe ];
520
+ [codesignTask setStandardError: pipe ];
521
+ NSFileHandle *handle=[pipe fileHandleForReading ];
522
+
523
+ [codesignTask launch ];
524
+
525
+ [NSThread detachNewThreadSelector: @selector (watchCodesigning: )
526
+ toTarget: self withObject: handle];
498
527
}
499
528
500
529
- (void )watchCodesigning : (NSFileHandle *)streamHandle {
@@ -509,9 +538,17 @@ - (void)checkCodesigning:(NSTimer *)timer {
509
538
if ([codesignTask isRunning ] == 0 ) {
510
539
[timer invalidate ];
511
540
codesignTask = nil ;
512
- NSLog (@" Codesigning done" );
513
- [statusLabel setStringValue: @" Codesigning completed" ];
514
- [self doVerifySignature ];
541
+ if (frameworks.count > 0 ) {
542
+ [self signFile: [frameworks lastObject ]];
543
+ [frameworks removeLastObject ];
544
+ } else if (hasFrameworks) {
545
+ hasFrameworks = NO ;
546
+ [self signFile: appPath];
547
+ } else {
548
+ NSLog (@" Codesigning done" );
549
+ [statusLabel setStringValue: @" Codesigning completed" ];
550
+ [self doVerifySignature ];
551
+ }
515
552
}
516
553
}
517
554
0 commit comments