Skip to content

Commit

Permalink
Merge pull request #46 from adzellman/master
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekish committed Aug 4, 2015
2 parents f0fa976 + e073f20 commit c2567c5
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 62 deletions.
8 changes: 4 additions & 4 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>14D136</string>
<string>15A235d</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,17 +27,17 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>6D2105</string>
<string>6E35b</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>14D125</string>
<key>DTSDKName</key>
<string>macosx10.10</string>
<key>DTXcode</key>
<string>0632</string>
<string>0640</string>
<key>DTXcodeBuild</key>
<string>6D2105</string>
<string>6E35b</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.
18 changes: 9 additions & 9 deletions iReSign/iReSign/en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14D87h" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment defaultVersion="1060" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand All @@ -11,7 +11,7 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<menu title="AMainMenu" systemMenu="main" id="29">
<items>
<menuItem title="iReSign" id="56">
Expand Down Expand Up @@ -252,15 +252,15 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="OGH-jD-zcO">
<rect key="frame" x="20" y="190.0000008638354" width="69" height="69"/>
<rect key="frame" x="20" y="190.0000017943762" width="69" height="69"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="Icon" id="LSY-JN-rDx"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="Ft3-WI-tTm">
<rect key="frame" x="101.00000067379159" y="239.0000008638354" width="303" height="20"/>
<rect key="frame" x="101.00000067379159" y="239.0000017943762" width="303" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="How to use iReSign" id="QDO-Yr-Chc">
<font key="font" size="14" name="LucidaGrande-Bold"/>
<font key="font" metaFont="systemBold" size="14"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -269,7 +269,7 @@
<rect key="frame" x="101.00000067379159" y="49" width="303" height="182"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" id="yH0-zO-1ov">
<font key="font" size="11" name="LucidaGrande"/>
<font key="font" metaFont="smallSystem"/>
<string key="title">iReSign allows you to re-sign any unencrypted ipa-file with any certificate for which you hold the corresponding private key.

1. Drag your unsigned .ipa file to the top box, or use the browse button.
Expand Down Expand Up @@ -302,4 +302,4 @@ DQ
<resources>
<image name="Icon" width="128" height="128"/>
</resources>
</document>
</document>
5 changes: 5 additions & 0 deletions iReSign/iReSign/iReSignAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
NSTask *zipTask;
NSString *sourcePath;
NSString *appPath;
NSString *frameworksDirPath;
NSString *frameworkPath;
NSString *workingPath;
NSString *appName;
NSString *fileName;
Expand All @@ -33,6 +35,9 @@
NSString *codesigningResult;
NSString *verificationResult;

NSMutableArray *frameworks;
Boolean hasFrameworks;

IBOutlet IRTextFieldDrag *pathField;
IBOutlet IRTextFieldDrag *provisioningPathField;
IBOutlet IRTextFieldDrag *entitlementField;
Expand Down
135 changes: 86 additions & 49 deletions iReSign/iReSign/iReSignAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
static NSString *kKeyBundleIDPlistiTunesArtwork = @"softwareVersionBundleId";
static NSString *kKeyInfoPlistApplicationProperties = @"ApplicationProperties";
static NSString *kKeyInfoPlistApplicationPath = @"ApplicationPath";
static NSString *kFrameworksDirName = @"Frameworks";
static NSString *kPayloadDirName = @"Payload";
static NSString *kProductsDirName = @"Products";
static NSString *kInfoPlistFilename = @"Info.plist";
Expand Down Expand Up @@ -428,73 +429,101 @@ - (void)doEntitlementsEdit

- (void)doCodeSigning {
appPath = nil;
frameworksDirPath = nil;
hasFrameworks = NO;
frameworks = [[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];
frameworksDirPath = [appPath stringByAppendingPathComponent:kFrameworksDirName];
NSLog(@"Found %@",appPath);
appName = file;
if ([[NSFileManager defaultManager] fileExistsAtPath:frameworksDirPath]) {
NSLog(@"Found %@",frameworksDirPath);
hasFrameworks = YES;
NSArray *frameworksContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:frameworksDirPath error:nil];
for (NSString *frameworkFile in frameworksContents) {
if ([[[frameworkFile pathExtension] lowercaseString] isEqualTo:@"framework"]) {
frameworkPath = [frameworksDirPath stringByAppendingPathComponent:frameworkFile];
NSLog(@"Found %@",frameworkPath);
[frameworks addObject:frameworkPath];
}
}
}
[statusLabel setStringValue:[NSString stringWithFormat:@"Codesigning %@",file]];
break;
}
}

if (appPath) {
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"-fs", [certComboBox objectValue], nil];
NSDictionary *systemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
NSString * systemVersion = [systemVersionDictionary objectForKey:@"ProductVersion"];
NSArray * version = [systemVersion componentsSeparatedByString:@"."];
if ([version[0] intValue]<10 || ([version[0] intValue]==10 && ([version[1] intValue]<9 || ([version[1] intValue]==9 && [version[2] intValue]<5)))) {

/*
Before OSX 10.9, code signing requires a version 1 signature.
The resource envelope is necessary.
To ensure it is added, append the resource flag to the arguments.
*/

NSString *resourceRulesPath = [[NSBundle mainBundle] pathForResource:@"ResourceRules" ofType:@"plist"];
NSString *resourceRulesArgument = [NSString stringWithFormat:@"--resource-rules=%@",resourceRulesPath];
[arguments addObject:resourceRulesArgument];
if (hasFrameworks) {
[self signFile:[frameworks lastObject]];
[frameworks removeLastObject];
} else {

/*
For OSX 10.9 and later, code signing requires a version 2 signature.
The resource envelope is obsolete.
To ensure it is ignored, remove the resource key from the Info.plist file.
*/

NSString *infoPath = [NSString stringWithFormat:@"%@/Info.plist", appPath];
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]]];
[self signFile:appPath];

This comment has been minimized.

Copy link
@jefferycline1

jefferycline1 Sep 25, 2021

Resign IPAs Apple developer

}
}
}

- (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"];
NSArray * version = [systemVersion componentsSeparatedByString:@"."];
if ([version[0] intValue]<10 || ([version[0] intValue]==10 && ([version[1] intValue]<9 || ([version[1] intValue]==9 && [version[2] intValue]<5)))) {

[arguments addObjectsFromArray:[NSArray arrayWithObjects:appPath, nil]];

codesignTask = [[NSTask alloc] init];
[codesignTask setLaunchPath:@"/usr/bin/codesign"];
[codesignTask setArguments:arguments];

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

/*
Before OSX 10.9, code signing requires a version 1 signature.
The resource envelope is necessary.
To ensure it is added, append the resource flag to the arguments.
*/

NSPipe *pipe=[NSPipe pipe];
[codesignTask setStandardOutput:pipe];
[codesignTask setStandardError:pipe];
NSFileHandle *handle=[pipe fileHandleForReading];
NSString *resourceRulesPath = [[NSBundle mainBundle] pathForResource:@"ResourceRules" ofType:@"plist"];
NSString *resourceRulesArgument = [NSString stringWithFormat:@"--resource-rules=%@",resourceRulesPath];
[arguments addObject:resourceRulesArgument];
} else {

[codesignTask launch];
/*
For OSX 10.9 and later, code signing requires a version 2 signature.
The resource envelope is obsolete.
To ensure it is ignored, remove the resource key from the Info.plist file.
*/

[NSThread detachNewThreadSelector:@selector(watchCodesigning:)
toTarget:self withObject:handle];
NSString *infoPath = [NSString stringWithFormat:@"%@/Info.plist", filePath];
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]]];
}

[arguments addObjectsFromArray:[NSArray arrayWithObjects:filePath, nil]];

codesignTask = [[NSTask alloc] init];
[codesignTask setLaunchPath:@"/usr/bin/codesign"];
[codesignTask setArguments:arguments];

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


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

[codesignTask launch];

[NSThread detachNewThreadSelector:@selector(watchCodesigning:)
toTarget:self withObject:handle];
}

- (void)watchCodesigning:(NSFileHandle*)streamHandle {
Expand All @@ -509,9 +538,17 @@ - (void)checkCodesigning:(NSTimer *)timer {
if ([codesignTask isRunning] == 0) {
[timer invalidate];
codesignTask = nil;
NSLog(@"Codesigning done");
[statusLabel setStringValue:@"Codesigning completed"];
[self doVerifySignature];
if (frameworks.count > 0) {
[self signFile:[frameworks lastObject]];
[frameworks removeLastObject];
} else if (hasFrameworks) {
hasFrameworks = NO;
[self signFile:appPath];
} else {
NSLog(@"Codesigning done");
[statusLabel setStringValue:@"Codesigning completed"];
[self doVerifySignature];
}
}
}

Expand Down

0 comments on commit c2567c5

Please sign in to comment.