diff --git a/iReSign.app/Contents/Info.plist b/iReSign.app/Contents/Info.plist index 491ce4c..2cf98d4 100644 --- a/iReSign.app/Contents/Info.plist +++ b/iReSign.app/Contents/Info.plist @@ -3,7 +3,7 @@ BuildMachineOSBuild - 15A235d + 14F27 CFBundleDevelopmentRegion en CFBundleExecutable @@ -22,22 +22,26 @@ 1.4 CFBundleSignature ???? + CFBundleSupportedPlatforms + + MacOSX + CFBundleVersion 1.0 DTCompiler com.apple.compilers.llvm.clang.1_0 DTPlatformBuild - 6E35b + 7A1001 DTPlatformVersion GM DTSDKBuild - 14D125 + 15A278 DTSDKName - macosx10.10 + macosx10.11 DTXcode - 0640 + 0701 DTXcodeBuild - 6E35b + 7A1001 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/iReSign.app/Contents/MacOS/iReSign b/iReSign.app/Contents/MacOS/iReSign index 55bdbdd..71267b4 100755 Binary files a/iReSign.app/Contents/MacOS/iReSign and b/iReSign.app/Contents/MacOS/iReSign differ diff --git a/iReSign.app/Contents/Resources/en.lproj/MainMenu.nib b/iReSign.app/Contents/Resources/en.lproj/MainMenu.nib index 426e89e..5102671 100644 Binary files a/iReSign.app/Contents/Resources/en.lproj/MainMenu.nib and b/iReSign.app/Contents/Resources/en.lproj/MainMenu.nib differ diff --git a/iReSign.app/Contents/Resources/zh-Hans.lproj/MainMenu.nib b/iReSign.app/Contents/Resources/zh-Hans.lproj/MainMenu.nib index 571e217..2113259 100644 Binary files a/iReSign.app/Contents/Resources/zh-Hans.lproj/MainMenu.nib and b/iReSign.app/Contents/Resources/zh-Hans.lproj/MainMenu.nib differ diff --git a/iReSign/iReSign/iReSignAppDelegate.h b/iReSign/iReSign/iReSignAppDelegate.h index 6bd917b..a997732 100755 --- a/iReSign/iReSign/iReSignAppDelegate.h +++ b/iReSign/iReSign/iReSignAppDelegate.h @@ -30,13 +30,15 @@ NSString *workingPath; NSString *appName; NSString *fileName; + NSString *entitlementsDirPath; + NSString *entitlementsFilePath; NSString *entitlementsResult; NSString *codesigningResult; NSString *verificationResult; - NSMutableArray *frameworks; - Boolean hasFrameworks; + NSMutableArray *additionalResourcesToSign; + Boolean additionalToSign; IBOutlet IRTextFieldDrag *pathField; IBOutlet IRTextFieldDrag *provisioningPathField; @@ -59,8 +61,6 @@ @property (unsafe_unretained) IBOutlet NSWindow *window; -@property (nonatomic, strong) NSString *workingPath; - - (IBAction)resign:(id)sender; - (IBAction)browse:(id)sender; - (IBAction)provisioningBrowse:(id)sender; diff --git a/iReSign/iReSign/iReSignAppDelegate.m b/iReSign/iReSign/iReSignAppDelegate.m index d536f4e..5ed1b54 100755 --- a/iReSign/iReSign/iReSignAppDelegate.m +++ b/iReSign/iReSign/iReSignAppDelegate.m @@ -23,7 +23,7 @@ @implementation iReSignAppDelegate -@synthesize window,workingPath; +@synthesize window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { @@ -66,21 +66,25 @@ - (IBAction)resign:(id)sender { verificationResult = nil; sourcePath = [pathField stringValue]; + entitlementsFilePath = [entitlementField stringValue]; workingPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"com.appulize.iresign"]; + entitlementsDirPath = [workingPath stringByAppendingString:@"-entitlements"]; if ([certComboBox objectValue]) { if (([[[sourcePath pathExtension] lowercaseString] isEqualToString:@"ipa"]) || ([[[sourcePath pathExtension] lowercaseString] isEqualToString:@"xcarchive"])) { [self disableControls]; - NSLog(@"Setting up working directory in %@",workingPath); + NSLog(@"Setting up working directory in [%@], and entitlements work directory in [%@]",workingPath, entitlementsDirPath); [statusLabel setHidden:NO]; - [statusLabel setStringValue:@"Setting up working directory"]; + [statusLabel setStringValue:@"Setting up working directories"]; [[NSFileManager defaultManager] removeItemAtPath:workingPath error:nil]; - [[NSFileManager defaultManager] createDirectoryAtPath:workingPath withIntermediateDirectories:TRUE attributes:nil error:nil]; - + + [[NSFileManager defaultManager] removeItemAtPath:entitlementsDirPath error:nil]; + [[NSFileManager defaultManager] createDirectoryAtPath:entitlementsDirPath withIntermediateDirectories:TRUE attributes:nil error:nil]; + if ([[[sourcePath pathExtension] lowercaseString] isEqualToString:@"ipa"]) { if (sourcePath && [sourcePath length] > 0) { NSLog(@"Unzipping %@",sourcePath); @@ -338,7 +342,7 @@ - (void)checkProvisioning:(NSTimer *)timer { NSLog(@"Mobileprovision identifier: %@",identifierInProvisioning); - NSDictionary *infoplist = [NSDictionary dictionaryWithContentsOfFile:[appPath stringByAppendingPathComponent:@"Info.plist"]]; + NSDictionary *infoplist = [NSDictionary dictionaryWithContentsOfFile:[appPath stringByAppendingPathComponent:kInfoPlistFilename]]; if ([identifierInProvisioning isEqualTo:[infoplist objectForKey:kKeyBundleIDPlistApp]]) { NSLog(@"Identifiers match"); identifierOK = TRUE; @@ -366,12 +370,13 @@ - (void)checkProvisioning:(NSTimer *)timer { - (void)doEntitlementsFixing { - if (![entitlementField.stringValue isEqualToString:@""] || [provisioningPathField.stringValue isEqualToString:@""]) { + if (![entitlementsFilePath isEqualToString:@""] || [provisioningPathField.stringValue isEqualToString:@""]) { [self doCodeSigning]; return; // Using a pre-made entitlements file or we're not re-provisioning. } [statusLabel setStringValue:@"Generating entitlements"]; + NSLog(@"Generating entitlements"); if (appPath) { generateEntitlementsTask = [[NSTask alloc] init]; @@ -413,7 +418,8 @@ - (void)doEntitlementsEdit { NSDictionary* entitlements = entitlementsResult.propertyList; entitlements = entitlements[@"Entitlements"]; - NSString* filePath = [workingPath stringByAppendingPathComponent:@"entitlements.plist"]; + NSString* filePath = [entitlementsDirPath stringByAppendingPathComponent:@"entitlements.plist"]; + NSLog(@"entitlementsDirPath %@, filePath %@", entitlementsDirPath, filePath); NSData *xmlData = [NSPropertyListSerialization dataWithPropertyList:entitlements format:NSPropertyListXMLFormat_v1_0 options:kCFPropertyListImmutable error:nil]; if(![xmlData writeToFile:filePath atomically:YES]) { NSLog(@"Error writing entitlements file."); @@ -422,7 +428,7 @@ - (void)doEntitlementsEdit [statusLabel setStringValue:@"Ready"]; } else { - entitlementField.stringValue = filePath; + entitlementsFilePath = filePath; [self doCodeSigning]; } } @@ -430,11 +436,11 @@ - (void)doEntitlementsEdit - (void)doCodeSigning { appPath = nil; frameworksDirPath = nil; - hasFrameworks = NO; - frameworks = [[NSMutableArray alloc] init]; - + additionalToSign = NO; + additionalResourcesToSign = [[NSMutableArray alloc] init]; + NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[workingPath stringByAppendingPathComponent:kPayloadDirName] error:nil]; - + for (NSString *file in dirContents) { if ([[[file pathExtension] lowercaseString] isEqualToString:@"app"]) { appPath = [[workingPath stringByAppendingPathComponent:kPayloadDirName] stringByAppendingPathComponent:file]; @@ -443,14 +449,14 @@ - (void)doCodeSigning { appName = file; if ([[NSFileManager defaultManager] fileExistsAtPath:frameworksDirPath]) { NSLog(@"Found %@",frameworksDirPath); - hasFrameworks = YES; + additionalToSign = YES; NSArray *frameworksContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:frameworksDirPath error:nil]; for (NSString *frameworkFile in frameworksContents) { NSString *extension = [[frameworkFile pathExtension] lowercaseString]; if ([extension isEqualTo:@"framework"] || [extension isEqualTo:@"dylib"]) { frameworkPath = [frameworksDirPath stringByAppendingPathComponent:frameworkFile]; NSLog(@"Found %@",frameworkPath); - [frameworks addObject:frameworkPath]; + [additionalResourcesToSign addObject:frameworkPath]; } } } @@ -458,11 +464,29 @@ - (void)doCodeSigning { break; } } - + + //Sign plugins and other executables except the main one + NSString *dir = appPath; + NSDirectoryEnumerator *dirEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:dir]; + + for (NSString *file in dirEnumerator) { + if ([[file lastPathComponent] isEqualToString:kInfoPlistFilename] && [[[file stringByDeletingLastPathComponent] stringByTrimmingCharactersInSet: + [NSCharacterSet whitespaceCharacterSet]] length] > 0) { + NSString* InfoPlistPath = [appPath stringByAppendingPathComponent: file]; + NSDictionary *infoDict = [NSDictionary dictionaryWithContentsOfFile:InfoPlistPath]; + if ([infoDict objectForKey:@"CFBundleExecutable"] != nil) { + additionalToSign = YES; + NSString* dirToSign = [InfoPlistPath stringByDeletingLastPathComponent]; + NSLog(@"Found %@", dirToSign); + [additionalResourcesToSign addObject:dirToSign]; + } + } + } + if (appPath) { - if (hasFrameworks) { - [self signFile:[frameworks lastObject]]; - [frameworks removeLastObject]; + if (additionalToSign) { + [self signFile:[additionalResourcesToSign lastObject]]; + [additionalResourcesToSign removeLastObject]; } else { [self signFile:appPath]; } @@ -472,7 +496,7 @@ - (void)doCodeSigning { - (void)signFile:(NSString*)filePath { NSLog(@"Codesigning %@", filePath); [statusLabel setStringValue:[NSString stringWithFormat:@"Codesigning %@",filePath]]; - + NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"-fs", [certComboBox objectValue], nil]; NSDictionary *systemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; NSString * systemVersion = [systemVersionDictionary objectForKey:@"ProductVersion"]; @@ -496,18 +520,21 @@ - (void)signFile:(NSString*)filePath { To ensure it is ignored, remove the resource key from the Info.plist file. */ - NSString *infoPath = [NSString stringWithFormat:@"%@/Info.plist", filePath]; + NSString *infoPath = [NSString stringWithFormat:@"%@/%@", filePath, kInfoPlistFilename]; NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:infoPath]; [infoDict removeObjectForKey:@"CFBundleResourceSpecification"]; [infoDict writeToFile:infoPath atomically:YES]; [arguments addObject:@"--no-strict"]; // http://stackoverflow.com/a/26204757 } - if (![[entitlementField stringValue] isEqualToString:@""]) { - [arguments addObject:[NSString stringWithFormat:@"--entitlements=%@", [entitlementField stringValue]]]; + if (![entitlementsFilePath isEqualToString:@""]) { + NSLog(@"Signing with entitlements file: %@", entitlementsFilePath); + [arguments addObject:[NSString stringWithFormat:@"--entitlements=%@", entitlementsFilePath]]; } [arguments addObjectsFromArray:[NSArray arrayWithObjects:filePath, nil]]; + + NSLog(@"Signing arguments = %@", arguments); codesignTask = [[NSTask alloc] init]; [codesignTask setLaunchPath:@"/usr/bin/codesign"]; @@ -539,11 +566,11 @@ - (void)checkCodesigning:(NSTimer *)timer { if ([codesignTask isRunning] == 0) { [timer invalidate]; codesignTask = nil; - if (frameworks.count > 0) { - [self signFile:[frameworks lastObject]]; - [frameworks removeLastObject]; - } else if (hasFrameworks) { - hasFrameworks = NO; + if (additionalResourcesToSign.count > 0) { + [self signFile:[additionalResourcesToSign lastObject]]; + [additionalResourcesToSign removeLastObject]; + } else if (additionalToSign) { + additionalToSign = NO; [self signFile:appPath]; } else { NSLog(@"Codesigning done");