mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Re-sign the altered/new test app
For sandbox testing, we really have to use ad-hoc signing. Which means we have to sign the "new" app after we alter its info.plist file, so that our code signing verifier doesn't (rightfully) complain
This commit is contained in:
1 parent
db4e8a9946
commit
ed72d25eaa
9 files changed
+181
-120
No files matched your search
@@ -6,3 +6,4 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
|
||||
LD_RUNPATH_SEARCH_PATHS = @executable_path/../Frameworks
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.SparkleTestApp
|
||||
CODE_SIGN_ENTITLEMENTS = TestApplication/Sparkle-Test-App.entitlements
|
||||
CODE_SIGN_IDENTITY = -
|
||||
@@ -4,3 +4,4 @@ INFOPLIST_FILE = TestAppHelper/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
LD_RUNPATH_SEARCH_PATHS = @executable_path/../../../../Frameworks
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.TestAppHelper
|
||||
CODE_SIGN_IDENTITY = -
|
||||
@@ -179,6 +179,8 @@
|
||||
725CB9571C7120410064365A /* SUUserDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 725CB9561C7120410064365A /* SUUserDriver.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
725CB95A1C7121830064365A /* SUStandardUserDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 725CB9581C7121830064365A /* SUStandardUserDriver.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
725CB95B1C7121830064365A /* SUStandardUserDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 725CB9591C7121830064365A /* SUStandardUserDriver.m */; };
|
||||
725F97771C8A62F500265BE4 /* SUAdHocCodeSigning.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97751C8A62F500265BE4 /* SUAdHocCodeSigning.m */; };
|
||||
725F97781C8A65AC00265BE4 /* SUAdHocCodeSigning.m in Sources */ = {isa = PBXBuildFile; fileRef = 725F97751C8A62F500265BE4 /* SUAdHocCodeSigning.m */; };
|
||||
7268AC631AD634C200C3E0C1 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */; };
|
||||
726DF88E1C84277600188804 /* SUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SUStatusCompletionResults.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -665,6 +667,8 @@
|
||||
725CB9561C7120410064365A /* SUUserDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUserDriver.h; sourceTree = "<group>"; };
|
||||
725CB9581C7121830064365A /* SUStandardUserDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriver.h; sourceTree = "<group>"; };
|
||||
725CB9591C7121830064365A /* SUStandardUserDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUStandardUserDriver.m; sourceTree = "<group>"; };
|
||||
725F97741C8A62F500265BE4 /* SUAdHocCodeSigning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUAdHocCodeSigning.h; sourceTree = "<group>"; };
|
||||
725F97751C8A62F500265BE4 /* SUAdHocCodeSigning.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAdHocCodeSigning.m; sourceTree = "<group>"; };
|
||||
7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaCreate.m; sourceTree = "<group>"; };
|
||||
7268AC641AD634E400C3E0C1 /* SUBinaryDeltaCreate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaCreate.h; sourceTree = "<group>"; };
|
||||
726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -1125,6 +1129,8 @@
|
||||
72E45CF21B640CDD005C701A /* SUTestApplicationDelegate.m */,
|
||||
A5BF4F1B1BC7668B007A052A /* SUTestWebServer.h */,
|
||||
A5BF4F1C1BC7668B007A052A /* SUTestWebServer.m */,
|
||||
725F97741C8A62F500265BE4 /* SUAdHocCodeSigning.h */,
|
||||
725F97751C8A62F500265BE4 /* SUAdHocCodeSigning.m */,
|
||||
72E45CF41B640DAE005C701A /* SUUpdateSettingsWindowController.h */,
|
||||
72E45CF51B640DAE005C701A /* SUUpdateSettingsWindowController.m */,
|
||||
72E45CF61B640DAE005C701A /* SUUpdateSettingsWindowController.xib */,
|
||||
@@ -1772,6 +1778,7 @@
|
||||
72D4DAA11AD7632900B211E2 /* SUBinaryDeltaCreate.m in Sources */,
|
||||
142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */,
|
||||
F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */,
|
||||
725F97771C8A62F500265BE4 /* SUAdHocCodeSigning.m in Sources */,
|
||||
5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */,
|
||||
72A4A2401BB6567D00E7820D /* SUFileManagerTest.swift in Sources */,
|
||||
5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */,
|
||||
@@ -1807,6 +1814,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
725F97781C8A65AC00265BE4 /* SUAdHocCodeSigning.m in Sources */,
|
||||
726E4A1D1C86C88F00C57C6A /* main.m in Sources */,
|
||||
726E4A1B1C86C88F00C57C6A /* TestAppHelper.m in Sources */,
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "TestAppHelper.h"
|
||||
#import "SUAdHocCodeSigning.h"
|
||||
#import <Sparkle/Sparkle.h>
|
||||
|
||||
@interface TestAppHelper ()
|
||||
@@ -30,6 +31,11 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)codeSignApplicationAtPath:(NSString *)applicationPath reply:(void (^)(BOOL))reply
|
||||
{
|
||||
reply([SUAdHocCodeSigning codeSignApplicationAtPath:applicationPath]);
|
||||
}
|
||||
|
||||
- (void)startSparkleIfNeeded
|
||||
{
|
||||
if (self.updater == nil) {
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
// The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service.
|
||||
@protocol TestAppHelperProtocol
|
||||
|
||||
- (void)codeSignApplicationAtPath:(NSString *)applicationPath reply:(void (^)(BOOL))reply;
|
||||
|
||||
// Start up Sparkle
|
||||
- (void)startSparkle;
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// SUAdHocCodeSigning.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/4/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUAdHocCodeSigning : NSObject
|
||||
|
||||
+ (BOOL)codeSignApplicationAtPath:(NSString *)applicationPath;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// SUAdHocCodeSigning.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/4/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUAdHocCodeSigning.h"
|
||||
|
||||
@implementation SUAdHocCodeSigning
|
||||
|
||||
+ (BOOL)codeSignApplicationAtPath:(NSString *)applicationPath
|
||||
{
|
||||
BOOL success = NO;
|
||||
@try
|
||||
{
|
||||
// ad-hoc signing with the dash
|
||||
NSArray *arguments = @[ @"--force", @"--deep", @"--sign", @"-", applicationPath ];
|
||||
NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/codesign" arguments:arguments];
|
||||
[task waitUntilExit];
|
||||
success = (task.terminationStatus == 0);
|
||||
}
|
||||
@catch (NSException *exception)
|
||||
{
|
||||
NSLog(@"Failed to code sign application at %@", applicationPath);
|
||||
NSLog(@"Exception: %@", exception);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -11,6 +11,7 @@
|
||||
#import "SURemoteUpdateSettingsWindowController.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SUTestWebServer.h"
|
||||
#import "TestAppHelperProtocol.h"
|
||||
|
||||
@interface SUTestApplicationDelegate ()
|
||||
|
||||
@@ -97,107 +98,119 @@ static NSString * const UPDATED_VERSION = @"2.0";
|
||||
BOOL wroteInfoFile = [infoDictionary writeToURL:infoURL atomically:NO];
|
||||
assert(wroteInfoFile);
|
||||
|
||||
// Change current working directory so web server knows where to list files
|
||||
NSString *serverDirectoryPath = serverDirectoryURL.path;
|
||||
assert(serverDirectoryPath != nil);
|
||||
// This is unfortunately necessary for testing sandboxing
|
||||
NSXPCConnection *codeSignConnection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.TestAppHelper"];
|
||||
codeSignConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(TestAppHelperProtocol)];
|
||||
[codeSignConnection resume];
|
||||
|
||||
// Create the archive for our update
|
||||
NSString *zipName = @"Sparkle_Test_App.zip";
|
||||
NSTask *dittoTask = [[NSTask alloc] init];
|
||||
dittoTask.launchPath = @"/usr/bin/ditto";
|
||||
dittoTask.arguments = @[@"-c", @"-k", @"--sequesterRsrc", @"--keepParent", destinationBundleURL.lastPathComponent, zipName];
|
||||
dittoTask.currentDirectoryPath = serverDirectoryPath;
|
||||
[dittoTask launch];
|
||||
[dittoTask waitUntilExit];
|
||||
|
||||
assert(dittoTask.terminationStatus == 0);
|
||||
|
||||
[fileManager removeItemAtURL:destinationBundleURL error:NULL];
|
||||
|
||||
// Don't ever do this at home, kids (seriously)
|
||||
// (that is, including the private key inside of your application)
|
||||
NSString *privateKeyPath = [mainBundle pathForResource:@"test_app_only_dsa_priv_dont_ever_do_this_for_real" ofType:@"pem"];
|
||||
assert(privateKeyPath != nil);
|
||||
|
||||
// Sign our update
|
||||
NSTask *signUpdateTask = [[NSTask alloc] init];
|
||||
NSString *signUpdatePath = [mainBundle pathForResource:@"sign_update" ofType:@""];
|
||||
assert(signUpdatePath != nil);
|
||||
signUpdateTask.launchPath = signUpdatePath;
|
||||
|
||||
NSURL *archiveURL = [serverDirectoryURL URLByAppendingPathComponent:zipName];
|
||||
signUpdateTask.arguments = @[archiveURL.path, privateKeyPath];
|
||||
|
||||
NSPipe *outputPipe = [NSPipe pipe];
|
||||
signUpdateTask.standardOutput = outputPipe;
|
||||
|
||||
[signUpdateTask launch];
|
||||
[signUpdateTask waitUntilExit];
|
||||
|
||||
assert(signUpdateTask.terminationStatus == 0);
|
||||
|
||||
NSData *signatureData = [outputPipe.fileHandleForReading readDataToEndOfFile];
|
||||
NSString *signature = [[[NSString alloc] initWithData:signatureData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
|
||||
assert(signature != nil);
|
||||
|
||||
// Obtain the file attributes to get the file size of our update later
|
||||
NSError *fileAttributesError = nil;
|
||||
NSString *archiveURLPath = archiveURL.path;
|
||||
assert(archiveURLPath != nil);
|
||||
NSDictionary *archiveFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:archiveURLPath error:&fileAttributesError];
|
||||
if (archiveFileAttributes == nil) {
|
||||
NSLog(@"Failed to retrieve file attributes from archive with error %@", fileAttributesError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
NSString * const appcastName = @"sparkletestcast";
|
||||
NSString * const appcastExtension = @"xml";
|
||||
|
||||
// Copy our appcast over to the server directory
|
||||
NSURL *appcastDestinationURL = [[serverDirectoryURL URLByAppendingPathComponent:appcastName] URLByAppendingPathExtension:appcastExtension];
|
||||
NSError *copyAppcastError = nil;
|
||||
if (![fileManager copyItemAtURL:[mainBundle URLForResource:appcastName withExtension:appcastExtension] toURL:appcastDestinationURL error:©AppcastError]) {
|
||||
NSLog(@"Failed to copy appcast into cache directory with error %@", copyAppcastError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
// Update the appcast with the file size and signature of the update archive
|
||||
// We could be using some sort of XML parser instead of doing string substitutions, but for now, this is easier
|
||||
NSError *appcastError = nil;
|
||||
NSMutableString *appcastContents = [[NSMutableString alloc] initWithContentsOfURL:appcastDestinationURL encoding:NSUTF8StringEncoding error:&appcastError];
|
||||
if (appcastContents == nil) {
|
||||
NSLog(@"Failed to load appcast contents with error %@", appcastError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
NSUInteger numberOfLengthReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_ARCHIVE_LENGTH" withString:[NSString stringWithFormat:@"%llu", archiveFileAttributes.fileSize] options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
|
||||
assert(numberOfLengthReplacements == 1);
|
||||
|
||||
NSUInteger numberOfSignatureReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_DSA_SIGNATURE" withString:signature options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
|
||||
assert(numberOfSignatureReplacements == 1);
|
||||
|
||||
NSError *writeAppcastError = nil;
|
||||
if (![appcastContents writeToURL:appcastDestinationURL atomically:NO encoding:NSUTF8StringEncoding error:&writeAppcastError]) {
|
||||
NSLog(@"Failed to write updated appcast with error %@", writeAppcastError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
// Finally start the server
|
||||
SUTestWebServer *webServer = [[SUTestWebServer alloc] initWithPort:1337 workingDirectory:serverDirectoryPath];
|
||||
if (!webServer) {
|
||||
NSLog(@"Failed to create the web server");
|
||||
assert(NO);
|
||||
}
|
||||
self.webServer = webServer;
|
||||
|
||||
// Show the Settings window
|
||||
|
||||
// SURemoteUpdateSettingsWindowController will show its window by itself
|
||||
self.remoteUpdateSettingsWindowController = [[SURemoteUpdateSettingsWindowController alloc] init];
|
||||
|
||||
//self.updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
|
||||
//[self.updateSettingsWindowController showWindow:nil];
|
||||
[codeSignConnection.remoteObjectProxy codeSignApplicationAtPath:destinationBundleURL.path reply:^(BOOL success) {
|
||||
assert(success);
|
||||
[codeSignConnection invalidate];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Change current working directory so web server knows where to list files
|
||||
NSString *serverDirectoryPath = serverDirectoryURL.path;
|
||||
assert(serverDirectoryPath != nil);
|
||||
|
||||
// Create the archive for our update
|
||||
NSString *zipName = @"Sparkle_Test_App.zip";
|
||||
NSTask *dittoTask = [[NSTask alloc] init];
|
||||
dittoTask.launchPath = @"/usr/bin/ditto";
|
||||
dittoTask.arguments = @[@"-c", @"-k", @"--sequesterRsrc", @"--keepParent", destinationBundleURL.lastPathComponent, zipName];
|
||||
dittoTask.currentDirectoryPath = serverDirectoryPath;
|
||||
[dittoTask launch];
|
||||
[dittoTask waitUntilExit];
|
||||
|
||||
assert(dittoTask.terminationStatus == 0);
|
||||
|
||||
[fileManager removeItemAtURL:destinationBundleURL error:NULL];
|
||||
|
||||
// Don't ever do this at home, kids (seriously)
|
||||
// (that is, including the private key inside of your application)
|
||||
NSString *privateKeyPath = [mainBundle pathForResource:@"test_app_only_dsa_priv_dont_ever_do_this_for_real" ofType:@"pem"];
|
||||
assert(privateKeyPath != nil);
|
||||
|
||||
// Sign our update
|
||||
NSTask *signUpdateTask = [[NSTask alloc] init];
|
||||
NSString *signUpdatePath = [mainBundle pathForResource:@"sign_update" ofType:@""];
|
||||
assert(signUpdatePath != nil);
|
||||
signUpdateTask.launchPath = signUpdatePath;
|
||||
|
||||
NSURL *archiveURL = [serverDirectoryURL URLByAppendingPathComponent:zipName];
|
||||
signUpdateTask.arguments = @[archiveURL.path, privateKeyPath];
|
||||
|
||||
NSPipe *outputPipe = [NSPipe pipe];
|
||||
signUpdateTask.standardOutput = outputPipe;
|
||||
|
||||
[signUpdateTask launch];
|
||||
[signUpdateTask waitUntilExit];
|
||||
|
||||
assert(signUpdateTask.terminationStatus == 0);
|
||||
|
||||
NSData *signatureData = [outputPipe.fileHandleForReading readDataToEndOfFile];
|
||||
NSString *signature = [[[NSString alloc] initWithData:signatureData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
|
||||
assert(signature != nil);
|
||||
|
||||
// Obtain the file attributes to get the file size of our update later
|
||||
NSError *fileAttributesError = nil;
|
||||
NSString *archiveURLPath = archiveURL.path;
|
||||
assert(archiveURLPath != nil);
|
||||
NSDictionary *archiveFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:archiveURLPath error:&fileAttributesError];
|
||||
if (archiveFileAttributes == nil) {
|
||||
NSLog(@"Failed to retrieve file attributes from archive with error %@", fileAttributesError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
NSString * const appcastName = @"sparkletestcast";
|
||||
NSString * const appcastExtension = @"xml";
|
||||
|
||||
// Copy our appcast over to the server directory
|
||||
NSURL *appcastDestinationURL = [[serverDirectoryURL URLByAppendingPathComponent:appcastName] URLByAppendingPathExtension:appcastExtension];
|
||||
NSError *copyAppcastError = nil;
|
||||
if (![fileManager copyItemAtURL:[mainBundle URLForResource:appcastName withExtension:appcastExtension] toURL:appcastDestinationURL error:©AppcastError]) {
|
||||
NSLog(@"Failed to copy appcast into cache directory with error %@", copyAppcastError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
// Update the appcast with the file size and signature of the update archive
|
||||
// We could be using some sort of XML parser instead of doing string substitutions, but for now, this is easier
|
||||
NSError *appcastError = nil;
|
||||
NSMutableString *appcastContents = [[NSMutableString alloc] initWithContentsOfURL:appcastDestinationURL encoding:NSUTF8StringEncoding error:&appcastError];
|
||||
if (appcastContents == nil) {
|
||||
NSLog(@"Failed to load appcast contents with error %@", appcastError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
NSUInteger numberOfLengthReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_ARCHIVE_LENGTH" withString:[NSString stringWithFormat:@"%llu", archiveFileAttributes.fileSize] options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
|
||||
assert(numberOfLengthReplacements == 1);
|
||||
|
||||
NSUInteger numberOfSignatureReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_DSA_SIGNATURE" withString:signature options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
|
||||
assert(numberOfSignatureReplacements == 1);
|
||||
|
||||
NSError *writeAppcastError = nil;
|
||||
if (![appcastContents writeToURL:appcastDestinationURL atomically:NO encoding:NSUTF8StringEncoding error:&writeAppcastError]) {
|
||||
NSLog(@"Failed to write updated appcast with error %@", writeAppcastError);
|
||||
assert(NO);
|
||||
}
|
||||
|
||||
// Finally start the server
|
||||
SUTestWebServer *webServer = [[SUTestWebServer alloc] initWithPort:1337 workingDirectory:serverDirectoryPath];
|
||||
if (!webServer) {
|
||||
NSLog(@"Failed to create the web server");
|
||||
assert(NO);
|
||||
}
|
||||
self.webServer = webServer;
|
||||
|
||||
// Show the Settings window
|
||||
|
||||
// SURemoteUpdateSettingsWindowController will show its window by itself
|
||||
self.remoteUpdateSettingsWindowController = [[SURemoteUpdateSettingsWindowController alloc] init];
|
||||
|
||||
//self.updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
|
||||
//[self.updateSettingsWindowController showWindow:nil];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)__unused sender
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUAdHocCodeSigning.h"
|
||||
|
||||
@interface SUCodeSigningVerifierTest : XCTestCase
|
||||
|
||||
@@ -74,7 +75,7 @@
|
||||
}
|
||||
if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndValid error:&error]) {
|
||||
self.validSignedAppPath = signedAndValid;
|
||||
if (![self codesignAppPath:self.validSignedAppPath]) {
|
||||
if (![SUAdHocCodeSigning codeSignApplicationAtPath:self.validSignedAppPath]) {
|
||||
NSLog(@"Failed to codesign %@", self.validSignedAppPath);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +95,7 @@
|
||||
}
|
||||
if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndInvalid error:&error]) {
|
||||
self.invalidSignedAppPath = signedAndInvalid;
|
||||
if ([self codesignAppPath:self.invalidSignedAppPath]) {
|
||||
if ([SUAdHocCodeSigning codeSignApplicationAtPath:self.invalidSignedAppPath]) {
|
||||
NSString *fileInAppBundleToRemove = [self.invalidSignedAppPath stringByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"];
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:fileInAppBundleToRemove error:&error]) {
|
||||
NSLog(@"Failed to remove %@ with error %@", fileInAppBundleToRemove, error);
|
||||
@@ -130,24 +131,6 @@
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL)codesignAppPath:(NSString *)appPath
|
||||
{
|
||||
BOOL success = NO;
|
||||
@try
|
||||
{
|
||||
// ad-hoc signing with the dash
|
||||
NSArray *arguments = @[ @"--force", @"--deep", @"--sign", @"-", appPath ];
|
||||
NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/codesign" arguments:arguments];
|
||||
[task waitUntilExit];
|
||||
success = (task.terminationStatus == 0);
|
||||
}
|
||||
@catch (NSException *exception)
|
||||
{
|
||||
NSLog(@"exception: %@", exception);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
- (void)testUnsignedApp
|
||||
{
|
||||
XCTAssertFalse([SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.notSignedAppPath], @"App not expected to be code signed");
|
||||
|
||||
Reference in new issue
Block a user