mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
commit
077c64419f
5 files changed
+103
-135
No files matched your search
Vendored
+6
-7
@@ -337,18 +337,17 @@
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier bundleAtPathIsCodeSigned:installSourcePath];
|
||||
|
||||
BOOL updateIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:newHost.bundle.bundleURL];
|
||||
|
||||
if (dsaKeysMatch) {
|
||||
NSError *error = nil;
|
||||
if (updateIsCodeSigned && ![SUCodeSigningVerifier codeSignatureIsValidAtPath:installSourcePath error:&error]) {
|
||||
if (updateIsCodeSigned && ![SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:newHost.bundle.bundleURL error:&error]) {
|
||||
SULog(@"The update archive has a valid DSA signature, but the app is also signed with Code Signing, which is corrupted: %@. The update will be rejected.", error);
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
NSString *hostBundlePath = host.bundlePath;
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtPathIsCodeSigned:hostBundlePath];
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:host.bundle.bundleURL];
|
||||
|
||||
NSString *dsaStatus = newPublicDSAKey ? @"has a new DSA key that doesn't match the previous one" : (publicDSAKey ? @"removes the DSA key" : @"isn't signed with a DSA key");
|
||||
if (!hostIsCodeSigned || !updateIsCodeSigned) {
|
||||
@@ -358,7 +357,7 @@
|
||||
}
|
||||
|
||||
NSError *error = nil;
|
||||
if (![SUCodeSigningVerifier codeSignatureAtPath:hostBundlePath matchesSignatureAtPath:installSourcePath error:&error]) {
|
||||
if (![SUCodeSigningVerifier codeSignatureAtBundleURL:host.bundle.bundleURL matchesSignatureAtBundleURL:newHost.bundle.bundleURL error:&error]) {
|
||||
SULog(@"The update archive %@, and the app is signed with a new Code Signing identity that doesn't match code signing of the original app: %@. At least one method of signature verification must be valid. The update will be rejected.", dsaStatus, error);
|
||||
return NO;
|
||||
}
|
||||
@@ -407,7 +406,7 @@
|
||||
|
||||
- (void)extractUpdate
|
||||
{
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:[[self.host bundle] bundlePath] withPassword:self.updater.decryptionPassword];
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath withPassword:self.updater.decryptionPassword];
|
||||
if (!unarchiver) {
|
||||
SULog(@"Error: No valid unarchiver for %@!", self.downloadPath);
|
||||
[self unarchiverDidFail:nil];
|
||||
|
||||
Vendored
+3
-3
@@ -12,9 +12,9 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
+ (BOOL)codeSignatureAtPath:(NSString *)oldBundlePath matchesSignatureAtPath:(NSString *)newBundlePath error:(NSError **)error;
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)bundlePath error:(NSError **)error;
|
||||
+ (BOOL)bundleAtPathIsCodeSigned:(NSString *)bundlePath;
|
||||
+ (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundlePath matchesSignatureAtBundleURL:(NSURL *)newBundlePath error:(NSError **)error;
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundlePath error:(NSError **)error;
|
||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundlePath;
|
||||
@end
|
||||
|
||||
#endif
|
||||
Vendored
+16
-47
@@ -13,45 +13,29 @@
|
||||
|
||||
@implementation SUCodeSigningVerifier
|
||||
|
||||
+ (BOOL)codeSignatureAtPath:(NSString *)oldBundlePath matchesSignatureAtPath:(NSString *)newBundlePath error:(NSError *__autoreleasing *)error
|
||||
+ (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundleURL matchesSignatureAtBundleURL:(NSURL *)newBundleURL error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecRequirementRef requirement = NULL;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
SecStaticCodeRef oldCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
NSBundle *oldBundle;
|
||||
CFErrorRef cfError = NULL;
|
||||
if (error) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
oldBundle = [NSBundle bundleWithPath:oldBundlePath];
|
||||
if (!oldBundle) {
|
||||
SULog(@"Failed to load NSBundle for original");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[oldBundle bundleURL], kSecCSDefaultFlags, &oldCode);
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)oldBundleURL, kSecCSDefaultFlags, &oldCode);
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
result = SecCodeCopyDesignatedRequirement(oldCode, kSecCSDefaultFlags, &requirement);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to copy designated requirement. Code Signing OSStatus code: %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:newBundlePath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle for update");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)newBundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
@@ -92,30 +76,22 @@ finally:
|
||||
return (result == noErr);
|
||||
}
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)bundlePath error:(NSError *__autoreleasing *)error
|
||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundleURL error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
CFErrorRef cfError = NULL;
|
||||
if (error) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:bundlePath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
// See in -codeSignatureAtPath:matchesSignatureAtPath:error: for why kSecCSCheckNestedCode is not passed
|
||||
|
||||
// See in -codeSignatureAtBundleURL:matchesSignatureAtBundleURL:error: for why kSecCSCheckNestedCode is not passed
|
||||
SecCSFlags flags = (SecCSFlags) (kSecCSDefaultFlags | kSecCSCheckAllArchitectures);
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, flags, NULL, &cfError);
|
||||
|
||||
@@ -126,7 +102,7 @@ finally:
|
||||
|
||||
if (result != noErr) {
|
||||
if (result == errSecCSUnsigned) {
|
||||
SULog(@"Error: The app is not signed using Apple Code Signing. %@", bundlePath);
|
||||
SULog(@"Error: The app is not signed using Apple Code Signing. %@", bundleURL);
|
||||
}
|
||||
if (result == errSecCSReqFailed) {
|
||||
[self logSigningInfoForCode:staticCode label:@"new info"];
|
||||
@@ -158,23 +134,16 @@ static id valueOrNSNull(id value) {
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)bundleAtPathIsCodeSigned:(NSString *)bundlePath
|
||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundleURL
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:bundlePath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle");
|
||||
return NO;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundleURL, kSecCSDefaultFlags, &staticCode);
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
result = SecCodeCopyDesignatedRequirement(staticCode, kSecCSDefaultFlags, &requirement);
|
||||
if (staticCode) {
|
||||
|
||||
Vendored
+1
-1
@@ -122,7 +122,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
|
||||
-(void)checkIfConfiguredProperly {
|
||||
BOOL hasPublicDSAKey = [self.host publicDSAKey] != nil;
|
||||
BOOL isMainBundle = [self.host.bundle isEqualTo:[NSBundle mainBundle]];
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtPathIsCodeSigned:self.host.bundlePath];
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.host.bundle.bundleURL];
|
||||
NSURL *feedURL = [self feedURL];
|
||||
BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"];
|
||||
|
||||
|
||||
@@ -15,19 +15,19 @@
|
||||
|
||||
@interface SUCodeSigningVerifierTest : XCTestCase
|
||||
|
||||
@property (copy) NSString *notSignedAppPath;
|
||||
@property (copy) NSString *validSignedAppPath;
|
||||
@property (copy) NSString *invalidSignedAppPath;
|
||||
@property (copy) NSString *calculatorCopyPath;
|
||||
@property (copy) NSURL *notSignedAppURL;
|
||||
@property (copy) NSURL *validSignedAppURL;
|
||||
@property (copy) NSURL *invalidSignedAppURL;
|
||||
@property (copy) NSURL *calculatorCopyURL;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUCodeSigningVerifierTest
|
||||
|
||||
@synthesize notSignedAppPath = _notSignedAppPath;
|
||||
@synthesize validSignedAppPath = _validSignedAppPath;
|
||||
@synthesize invalidSignedAppPath = _invalidSignedAppPath;
|
||||
@synthesize calculatorCopyPath = _calculatorCopyPath;
|
||||
@synthesize notSignedAppURL = _notSignedAppURL;
|
||||
@synthesize validSignedAppURL = _validSignedAppURL;
|
||||
@synthesize invalidSignedAppURL = _invalidSignedAppURL;
|
||||
@synthesize calculatorCopyURL = _calculatorCopyURL;
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
@@ -35,31 +35,28 @@
|
||||
|
||||
NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]];
|
||||
NSString *unitTestBundleIdentifier = unitTestBundle.bundleIdentifier;
|
||||
NSString *zippedAppPath = [unitTestBundle pathForResource:@"SparkleTestCodeSignApp" ofType:@"zip"];
|
||||
|
||||
NSString *zippedAppURL = [unitTestBundle pathForResource:@"SparkleTestCodeSignApp" ofType:@"zip"];
|
||||
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
|
||||
|
||||
NSError *tempError = nil;
|
||||
NSURL *tempDir = [fileManager makeTemporaryDirectoryWithPreferredName:unitTestBundleIdentifier appropriateForDirectoryURL:[NSURL fileURLWithPath:zippedAppPath] error:&tempError];
|
||||
|
||||
NSURL *tempDir = [fileManager makeTemporaryDirectoryWithPreferredName:unitTestBundleIdentifier appropriateForDirectoryURL:[NSURL fileURLWithPath:zippedAppURL] error:&tempError];
|
||||
|
||||
if (tempDir == nil) {
|
||||
XCTFail(@"Failed to create temporary directory with error: %@", tempError);
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *tempDirPath = tempDir.path;
|
||||
XCTAssertNotNil(tempDirPath);
|
||||
|
||||
|
||||
NSError *error = nil;
|
||||
if ([[NSFileManager defaultManager] createDirectoryAtPath:tempDirPath withIntermediateDirectories:YES attributes:nil error:&error]) {
|
||||
if ([self unzip:zippedAppPath toPath:tempDirPath]) {
|
||||
self.notSignedAppPath = [tempDirPath stringByAppendingPathComponent:@"SparkleTestCodeSignApp.app"];
|
||||
if ([[NSFileManager defaultManager] createDirectoryAtURL:tempDir withIntermediateDirectories:YES attributes:nil error:&error]) {
|
||||
if ([self unzip:zippedAppURL toPath:tempDir.path]) {
|
||||
self.notSignedAppURL = [tempDir URLByAppendingPathComponent:@"SparkleTestCodeSignApp.app"];
|
||||
[self setupValidSignedApp];
|
||||
[self setupCalculatorCopy];
|
||||
[self setupInvalidSignedApp];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to unzip %@", zippedAppPath);
|
||||
NSLog(@"Failed to unzip %@", zippedAppURL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -70,87 +67,87 @@
|
||||
- (void)tearDown
|
||||
{
|
||||
[super tearDown];
|
||||
|
||||
if (self.notSignedAppPath) {
|
||||
NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent];
|
||||
[[NSFileManager defaultManager] removeItemAtPath:tempDir error:nil];
|
||||
|
||||
if (self.notSignedAppURL) {
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
[[NSFileManager defaultManager] removeItemAtURL:tempDir error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupValidSignedApp
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent];
|
||||
NSString *signedAndValid = [tempDir stringByAppendingPathComponent:@"valid-signed.app"];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndValid]) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:signedAndValid error:NULL];
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
NSURL *signedAndValid = [tempDir URLByAppendingPathComponent:@"valid-signed.app"];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndValid.path]) {
|
||||
[[NSFileManager defaultManager] removeItemAtURL:signedAndValid error:NULL];
|
||||
}
|
||||
|
||||
if (![[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndValid error:&error]) {
|
||||
XCTFail("Failed to copy %@ to %@ with error: %@", self.notSignedAppPath, signedAndValid, error);
|
||||
|
||||
if (![[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toURL:signedAndValid error:&error]) {
|
||||
XCTFail("Failed to copy %@ to %@ with error: %@", self.notSignedAppURL, signedAndValid, error);
|
||||
}
|
||||
|
||||
self.validSignedAppURL = signedAndValid;
|
||||
|
||||
self.validSignedAppPath = signedAndValid;
|
||||
|
||||
if (![self codesignAppPath:self.validSignedAppPath]) {
|
||||
XCTFail(@"Failed to codesign %@", self.validSignedAppPath);
|
||||
if (![self codesignAppURL:self.validSignedAppURL]) {
|
||||
XCTFail(@"Failed to codesign %@", self.validSignedAppURL);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupCalculatorCopy
|
||||
{
|
||||
NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent];
|
||||
NSString *calculatorCopy = [tempDir stringByAppendingPathComponent:@"calc.app"];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:calculatorCopy]) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:calculatorCopy error:NULL];
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
NSURL *calculatorCopy = [tempDir URLByAppendingPathComponent:@"calc.app"];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:calculatorCopy.path]) {
|
||||
[[NSFileManager defaultManager] removeItemAtURL:calculatorCopy error:NULL];
|
||||
}
|
||||
|
||||
|
||||
// Make a copy of the signed calculator app so we can match signatures later
|
||||
// Matching signatures on ad-hoc signed apps does *not* work
|
||||
NSError *copyError = nil;
|
||||
// Don't check the return value of this operation - seems like on 10.11 the API can say it fails even though the operation really succeeds,
|
||||
// which sounds like some kind of (SIP / attribute?) bug
|
||||
[[NSFileManager defaultManager] copyItemAtPath:CALCULATOR_PATH toPath:calculatorCopy error:©Error];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:calculatorCopy]) {
|
||||
[[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:CALCULATOR_PATH] toURL:calculatorCopy error:©Error];
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:calculatorCopy.path]) {
|
||||
XCTFail(@"Copied calculator application does not exist");
|
||||
}
|
||||
|
||||
|
||||
// Alter the signed copy slightly, this won't invalidate signature matching (although it will invalidate the integrity part of the signature)
|
||||
// Which is what we want. If a user alters an app bundle, we should still be able to update as long as its identity is still valid
|
||||
NSError *removeError = nil;
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:[[calculatorCopy stringByAppendingPathComponent:@"Contents"] stringByAppendingPathComponent:@"PkgInfo"] error:&removeError]) {
|
||||
if (![[NSFileManager defaultManager] removeItemAtURL:[[calculatorCopy URLByAppendingPathComponent:@"Contents"] URLByAppendingPathComponent:@"PkgInfo"] error:&removeError]) {
|
||||
XCTFail(@"Failed to remove file in calculator copy with error: %@", removeError);
|
||||
}
|
||||
|
||||
self.calculatorCopyPath = calculatorCopy;
|
||||
|
||||
self.calculatorCopyURL = calculatorCopy;
|
||||
}
|
||||
|
||||
- (void)setupInvalidSignedApp
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent];
|
||||
NSString *signedAndInvalid = [tempDir stringByAppendingPathComponent:@"invalid-signed.app"];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndInvalid]) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:signedAndInvalid error:NULL];
|
||||
NSURL *tempDir = [self.notSignedAppURL URLByDeletingLastPathComponent];
|
||||
NSURL *signedAndInvalid = [tempDir URLByAppendingPathComponent:@"invalid-signed.app"];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:signedAndInvalid.path]) {
|
||||
[[NSFileManager defaultManager] removeItemAtURL:signedAndInvalid error:NULL];
|
||||
}
|
||||
if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndInvalid error:&error]) {
|
||||
self.invalidSignedAppPath = signedAndInvalid;
|
||||
if ([self codesignAppPath:self.invalidSignedAppPath]) {
|
||||
NSString *fileInAppBundleToRemove = [self.invalidSignedAppPath stringByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"];
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:fileInAppBundleToRemove error:&error]) {
|
||||
if ([[NSFileManager defaultManager] copyItemAtURL:self.notSignedAppURL toURL:signedAndInvalid error:&error]) {
|
||||
self.invalidSignedAppURL = signedAndInvalid;
|
||||
if ([self codesignAppURL:self.invalidSignedAppURL]) {
|
||||
NSURL *fileInAppBundleToRemove = [self.invalidSignedAppURL URLByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"];
|
||||
if (![[NSFileManager defaultManager] removeItemAtURL:fileInAppBundleToRemove error:&error]) {
|
||||
NSLog(@"Failed to remove %@ with error %@", fileInAppBundleToRemove, error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to codesign %@", self.invalidSignedAppPath);
|
||||
NSLog(@"Failed to codesign %@", self.invalidSignedAppURL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to copy %@ to %@ with error %@", self.notSignedAppPath, signedAndInvalid, error);
|
||||
NSLog(@"Failed to copy %@ to %@ with error %@", self.notSignedAppURL, signedAndInvalid, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +160,7 @@
|
||||
task.launchPath = @"/usr/bin/unzip";
|
||||
task.currentDirectoryPath = destPath;
|
||||
task.arguments = @[zipPath];
|
||||
|
||||
|
||||
[task launch];
|
||||
[task waitUntilExit];
|
||||
success = (task.terminationStatus == 0);
|
||||
@@ -175,7 +172,7 @@
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL)codesignAppPath:(NSString *)appPath
|
||||
- (BOOL)codesignAppURL:(NSURL *)appPath
|
||||
{
|
||||
BOOL success = NO;
|
||||
@try
|
||||
@@ -195,58 +192,61 @@
|
||||
|
||||
- (void)testUnsignedApp
|
||||
{
|
||||
XCTAssertFalse([SUCodeSigningVerifier bundleAtPathIsCodeSigned:self.notSignedAppPath], @"App not expected to be code signed");
|
||||
XCTAssertFalse([SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.notSignedAppURL], @"App not expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.notSignedAppPath error:&error], @"signature should not be valid as it's not code signed");
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:self.notSignedAppURL error:&error], @"signature should not be valid as it's not code signed");
|
||||
XCTAssertNotNil(error, @"error should not be nil");
|
||||
}
|
||||
|
||||
- (void)testValidSignedApp
|
||||
{
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtPathIsCodeSigned:self.validSignedAppPath], @"App expected to be code signed");
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.validSignedAppURL], @"App expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.validSignedAppPath error:&error], @"signature should be valid");
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:self.validSignedAppURL error:&error], @"signature should be valid");
|
||||
XCTAssertNil(error, @"error should be nil");
|
||||
}
|
||||
|
||||
- (void)testValidSignedCalculatorApp
|
||||
{
|
||||
NSString *appPath = CALCULATOR_PATH;
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtPathIsCodeSigned:appPath], @"App expected to be code signed");
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtURLIsCodeSigned:appPath], @"App expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtPath:appPath error:&error], @"signature should be valid");
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:appPath error:&error], @"signature should be valid");
|
||||
XCTAssertNil(error, @"error should be nil");
|
||||
}
|
||||
|
||||
- (void)testValidMatchingSelf
|
||||
{
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtPath:CALCULATOR_PATH matchesSignatureAtPath:CALCULATOR_PATH error:&error], @"Our valid signed app expected to having matching signature to itself");
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:appPath error:&error], @"Our valid signed app expected to having matching signature to itself");
|
||||
}
|
||||
|
||||
- (void)testValidMatching
|
||||
{
|
||||
// We can't test our own app because matching with ad-hoc signed apps understandably does not succeed
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtPath:CALCULATOR_PATH matchesSignatureAtPath:self.calculatorCopyPath error:&error], @"The calculator app is expected to have matching identity signature to its altered copy");
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:self.calculatorCopyURL error:&error], @"The calculator app is expected to have matching identity signature to its altered copy");
|
||||
}
|
||||
|
||||
- (void)testInvalidMatching
|
||||
{
|
||||
NSString *appPath = CALCULATOR_PATH;
|
||||
NSURL *appPath = [NSURL fileURLWithPath:CALCULATOR_PATH];
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureAtPath:appPath matchesSignatureAtPath:self.validSignedAppPath error:&error], @"Calculator app bundle expected to have different signature than our valid signed app");
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureAtBundleURL:appPath matchesSignatureAtBundleURL:self.validSignedAppURL error:&error], @"Calculator app bundle expected to have different signature than our valid signed app");
|
||||
}
|
||||
|
||||
- (void)testInvalidSignedApp
|
||||
{
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtPathIsCodeSigned:self.invalidSignedAppPath], @"App expected to be code signed, but signature is invalid");
|
||||
XCTAssertTrue([SUCodeSigningVerifier bundleAtURLIsCodeSigned:self.invalidSignedAppURL], @"App expected to be code signed, but signature is invalid");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.invalidSignedAppPath error:&error], @"signature should not be valid");
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtBundleURL:self.invalidSignedAppURL error:&error], @"signature should not be valid");
|
||||
XCTAssertNotNil(error, @"error should not be nil");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user