Skip to content

Sign plugins and additional executable files. When generating entitle… #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions iReSign.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15A235d</string>
<string>14F27</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -22,22 +22,26 @@
<string>1.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>6E35b</string>
<string>7A1001</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>14D125</string>
<string>15A278</string>
<key>DTSDKName</key>
<string>macosx10.10</string>
<string>macosx10.11</string>
<key>DTXcode</key>
<string>0640</string>
<string>0701</string>
<key>DTXcodeBuild</key>
<string>6E35b</string>
<string>7A1001</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Binary file modified iReSign.app/Contents/MacOS/iReSign
Binary file not shown.
Binary file modified iReSign.app/Contents/Resources/en.lproj/MainMenu.nib
Binary file not shown.
Binary file modified iReSign.app/Contents/Resources/zh-Hans.lproj/MainMenu.nib
Binary file not shown.
8 changes: 4 additions & 4 deletions iReSign/iReSign/iReSignAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
83 changes: 55 additions & 28 deletions iReSign/iReSign/iReSignAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@implementation iReSignAppDelegate

@synthesize window,workingPath;
@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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.");
Expand All @@ -422,19 +428,19 @@ - (void)doEntitlementsEdit
[statusLabel setStringValue:@"Ready"];
}
else {
entitlementField.stringValue = filePath;
entitlementsFilePath = filePath;
[self doCodeSigning];
}
}

- (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];
Expand All @@ -443,26 +449,44 @@ - (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];
}
}
}
[statusLabel setStringValue:[NSString stringWithFormat:@"Codesigning %@",file]];
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];
}
Expand All @@ -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"];
Expand All @@ -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"];
Expand Down Expand Up @@ -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");
Expand Down