Skip to content
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

Solve Signer Identity Ambiguity #86

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
Binary file modified iReSign.app/Contents/MacOS/iReSign
Binary file not shown.
50 changes: 35 additions & 15 deletions iReSign/iReSign/iReSignAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
static NSString *kInfoPlistFilename = @"Info.plist";
static NSString *kiTunesMetadataFileName = @"iTunesMetadata";


@interface iReSignAppDelegate()
@property (nonatomic , strong) NSDictionary* signinigCerts;
@end



@implementation iReSignAppDelegate

@synthesize window,workingPath;
Expand Down Expand Up @@ -372,22 +379,22 @@ - (void)doEntitlementsFixing
}

[statusLabel setStringValue:@"Generating entitlements"];

if (appPath) {
generateEntitlementsTask = [[NSTask alloc] init];
[generateEntitlementsTask setLaunchPath:@"/usr/bin/security"];
[generateEntitlementsTask setArguments:@[@"cms", @"-D", @"-i", provisioningPathField.stringValue]];
[generateEntitlementsTask setCurrentDirectoryPath:workingPath];

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkEntitlementsFix:) userInfo:nil repeats:TRUE];

NSPipe *pipe=[NSPipe pipe];
[generateEntitlementsTask setStandardOutput:pipe];
[generateEntitlementsTask setStandardError:pipe];
NSFileHandle *handle = [pipe fileHandleForReading];

[generateEntitlementsTask launch];

[NSThread detachNewThreadSelector:@selector(watchEntitlements:)
toTarget:self withObject:handle];
}
Expand Down Expand Up @@ -473,7 +480,9 @@ - (void)signFile:(NSString*)filePath {
NSLog(@"Codesigning %@", filePath);
[statusLabel setStringValue:[NSString stringWithFormat:@"Codesigning %@",filePath]];

NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"-fs", [certComboBox objectValue], nil];
NSString* certHash = [self.signinigCerts objectForKey:[certComboBox objectValue]] ? [self.signinigCerts objectForKey:[certComboBox objectValue]] : [certComboBox objectValue];

NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"-fs", certHash, nil];
NSDictionary *systemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
NSString * systemVersion = [systemVersionDictionary objectForKey:@"ProductVersion"];
NSArray * version = [systemVersion componentsSeparatedByString:@"."];
Expand Down Expand Up @@ -558,7 +567,7 @@ - (void)doVerifySignature {
verifyTask = [[NSTask alloc] init];
[verifyTask setLaunchPath:@"/usr/bin/codesign"];
[verifyTask setArguments:[NSArray arrayWithObjects:@"-v", appPath, nil]];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkVerificationProcess:) userInfo:nil repeats:TRUE];

NSLog(@"Verifying %@",appPath);
Expand Down Expand Up @@ -623,7 +632,7 @@ - (void)doZip {
[zipTask setLaunchPath:@"/usr/bin/zip"];
[zipTask setCurrentDirectoryPath:workingPath];
[zipTask setArguments:[NSArray arrayWithObjects:@"-qry", destinationPath, @".", nil]];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkZip:) userInfo:nil repeats:TRUE];

NSLog(@"Zipping %@", destinationPath);
Expand Down Expand Up @@ -784,20 +793,28 @@ - (void)watchGetCerts:(NSFileHandle*)streamHandle {
// Nothing in the result, return
return;
}
NSArray *rawResult = [securityResult componentsSeparatedByString:@"\""];
NSMutableArray *tempGetCertsResult = [NSMutableArray arrayWithCapacity:20];
for (int i = 0; i <= [rawResult count] - 2; i+=2) {
NSArray *rawResult = [securityResult componentsSeparatedByString:@"\n"];
NSMutableDictionary *tempGetCertsResult = [NSMutableDictionary dictionaryWithCapacity:20];
NSMutableArray *tempGetCertsResultNames = [NSMutableArray arrayWithCapacity:20];
for (int i = 0; i < [rawResult count] - 2; i++) {
if(!rawResult || [[rawResult objectAtIndex:i] isEqualToString:@""]) continue;

NSLog(@"i:%d", i+1);
if (rawResult.count - 1 < i + 1) {
NSArray *row = [[[rawResult objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsSeparatedByString:@" "];
if (row.count < 3)
{
// Invalid array, don't add an object to that position
} else {
// Valid object
[tempGetCertsResult addObject:[rawResult objectAtIndex:i+1]];

NSString* name = [[[rawResult objectAtIndex:i] componentsSeparatedByString:@"\""] objectAtIndex:1];
[tempGetCertsResult setObject:[row objectAtIndex:1] forKey:name];
[tempGetCertsResultNames addObject:name];
}
}

certComboBoxItems = [NSMutableArray arrayWithArray:tempGetCertsResult];

self.signinigCerts = tempGetCertsResult;
certComboBoxItems = [NSMutableArray arrayWithArray:tempGetCertsResultNames];

[certComboBox reloadData];

Expand Down Expand Up @@ -859,3 +876,6 @@ - (void)showAlertOfKind:(NSAlertStyle)style WithTitle:(NSString *)title AndMessa
}

@end