Compare commits

...
5 Commits
9 changed files with 88 additions and 57 deletions

No files matched your search

+1 -1
View File
@@ -187,7 +187,7 @@ static const NSTimeInterval SUInstallationTimeLimit = 5;
NSError *error = nil;
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:relaunchPath]
options:NSWorkspaceLaunchNewInstance
configuration:nil
configuration:@{}
error:&error];
if (error.code != noErr)
{
+4 -2
View File
@@ -83,7 +83,8 @@ BOOL SUShouldUseXPCInstaller(void)
const char *errorString = xpc_dictionary_get_string(response, SUInstallServiceErrorLocalizedDescriptionKey);
if (errorString != NULL)
{
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:[NSString stringWithCString:errorString encoding:NSUTF8StringEncoding]
NSString *errorStr = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding];
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:errorStr ? errorStr : @""
forKey:NSLocalizedDescriptionKey];
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
}
@@ -136,7 +137,8 @@ BOOL SUShouldUseXPCInstaller(void)
const char *errorString = xpc_dictionary_get_string(response, SUInstallServiceErrorLocalizedDescriptionKey);
if (errorString != NULL)
{
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:[NSString stringWithCString:errorString encoding:NSUTF8StringEncoding]
NSString *errorStr = [NSString stringWithCString:errorString encoding:NSUTF8StringEncoding];
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:errorStr ? errorStr : @""
forKey:NSLocalizedDescriptionKey];
error = [[NSError alloc] initWithDomain:SUSparkleErrorDomain code:SUXPCServiceError userInfo:errorInfo];
}
+2 -1
View File
@@ -162,7 +162,8 @@ static xpc_object_t SUISLaunchTask(xpc_object_t message)
NSMutableArray *mutableArgs = [NSMutableArray arrayWithCapacity:count];
for (size_t i = 0; i < count; i++)
{
[mutableArgs addObject:[NSString stringWithUTF8String:xpc_array_get_string(array, i)]];
NSString *argument = [NSString stringWithUTF8String:xpc_array_get_string(array, i)];
[mutableArgs addObject: argument ? argument : @""];
}
arguments = mutableArgs;
+7 -6
View File
@@ -196,7 +196,8 @@ CF_EXPORT CFDictionaryRef DMCopyHTTPRequestHeaders(CFBundleRef appBundle, CFData
- (void)updateURLRequestHTTPHeaders:(NSMutableURLRequest *)request
{
CFBundleRef hostBundle = CFBundleCreate(kCFAllocatorDefault, (__bridge CFURLRef)[NSURL fileURLWithPath:self.host.bundlePath]);
NSURL *hostBundleURL = self.host.bundlePath.length ? [NSURL fileURLWithPath:self.host.bundlePath] : nil;
CFBundleRef hostBundle = hostBundleURL ? CFBundleCreate(kCFAllocatorDefault, (__bridge CFURLRef)hostBundleURL) : NULL;
NSDictionary *devmateHeaders = (__bridge_transfer NSDictionary *)DMCopyHTTPRequestHeaders(hostBundle, NULL);
if (devmateHeaders.count)
{
@@ -299,8 +300,8 @@ CF_EXPORT CFDictionaryRef DMCopyHTTPRequestHeaders(CFBundleRef appBundle, CFData
SULog(@"Update has no valid Code Signing (%ld - %@)", error.code, error.localizedDescription);
}
BOOL shouldCheckCodeSignEquality = updateIsCodeSigned ? [SUCodeSigningVerifier hostApplicationIsCodeSigned] : NO;
if (shouldCheckCodeSignEquality && [SUCodeSigningVerifier codeSignatureMatchesHostAndIsValidAtPath:installSourcePath error:&error])
BOOL shouldCheckCodeSignEquality = updateIsCodeSigned ? [SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.host.bundlePath] : NO;
if (shouldCheckCodeSignEquality && [SUCodeSigningVerifier codeSignatureAtPath:self.host.bundlePath matchesSignatureAtPath:installSourcePath error:&error])
{
isUpdateValid = YES;
break;
@@ -499,10 +500,10 @@ CF_EXPORT CFDictionaryRef DMCopyHTTPRequestHeaders(CFBundleRef appBundle, CFData
if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) {
pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater];
}
NSArray *arguments = @[[self.host bundlePath],
pathToRelaunch,
NSArray *arguments = @[self.host.bundlePath.length ? self.host.bundlePath: @"",
pathToRelaunch.length ? pathToRelaunch : @"",
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
self.tempDir,
self.tempDir.length ? self.tempDir : @"",
relaunch ? @"1" : @"0",
showUI ? @"1" : @"0"];
if (SUShouldUseXPCInstaller())
+2 -2
View File
@@ -12,9 +12,9 @@
#import <Foundation/Foundation.h>
@interface SUCodeSigningVerifier : NSObject
+ (BOOL)codeSignatureMatchesHostAndIsValidAtPath:(NSString *)applicationPath error:(NSError **)error;
// pass nil as an application path to check a host one
+ (BOOL)codeSignatureAtPath:(NSString *)hostPath matchesSignatureAtPath:(NSString *)otherAppPath error:(NSError **)error;
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)applicationPath error:(NSError **)error;
+ (BOOL)hostApplicationIsCodeSigned;
+ (BOOL)applicationAtPathIsCodeSigned:(NSString *)applicationPath;
+ (BOOL)hostApplicationIsSandboxed;
@end
+69 -42
View File
@@ -13,51 +13,92 @@
@implementation SUCodeSigningVerifier
+ (BOOL)codeSignatureMatchesHostAndIsValidAtPath:(NSString *)applicationPath error:(NSError *__autoreleasing *)error
+ (BOOL)codeSignatureAtPath:(NSString *)hostPath matchesSignatureAtPath:(NSString *)otherAppPath error:(NSError *__autoreleasing *)error
{
OSStatus result;
SecRequirementRef requirement = NULL;
SecStaticCodeRef staticCode = NULL;
SecCodeRef hostCode = NULL;
NSBundle *newBundle;
CFErrorRef cfError = NULL;
SecStaticCodeRef staticHostCode = NULL;
SecStaticCodeRef staticAppCode = NULL;
if (error) {
*error = nil;
}
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
if (result != noErr) {
SULog(@"Failed to copy host code %d", result);
goto finally;
if (0 == hostPath.length) {
SecCodeRef hostCode = NULL;
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
if (result != noErr) {
SULog(@"Failed to copy host code %d", result);
goto finally;
}
result = SecCodeCopyStaticCode(hostCode, kSecCSDefaultFlags, &staticHostCode);
CFRelease(hostCode);
if (result != noErr) {
SULog(@"Failed to copy host code %d", result);
goto finally;
}
} else {
NSBundle *hostAppBundle = [NSBundle bundleWithPath:hostPath];
if (nil == hostAppBundle) {
SULog(@"Failed to create bundle at path %@", hostPath);
result = -1;
goto finally;
}
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)hostAppBundle.bundleURL, kSecCSDefaultFlags, &staticHostCode);
if (result != noErr) {
SULog(@"Failed to copy host code %d", result);
goto finally;
}
}
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
result = SecCodeCopyDesignatedRequirement(staticHostCode, kSecCSDefaultFlags, &requirement);
if (result != noErr) {
SULog(@"Failed to copy designated requirement. Code Signing OSStatus code: %d", result);
goto finally;
}
newBundle = [NSBundle bundleWithPath:applicationPath];
if (!newBundle) {
SULog(@"Failed to load NSBundle for update");
result = -1;
goto finally;
}
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
if (result != noErr) {
SULog(@"Failed to get static code %d", result);
goto finally;
if (0 == otherAppPath.length) {
SecCodeRef hostCode = NULL;
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
if (result != noErr) {
SULog(@"Failed to copy other app code %d", result);
goto finally;
}
result = SecCodeCopyStaticCode(hostCode, kSecCSDefaultFlags, &staticAppCode);
CFRelease(hostCode);
if (result != noErr) {
SULog(@"Failed to copy other app code %d", result);
goto finally;
}
} else {
NSBundle *otherAppBundle = [NSBundle bundleWithPath:otherAppPath];
if (nil == otherAppBundle) {
SULog(@"Failed to create bundle at path %@", otherAppPath);
result = -1;
goto finally;
}
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)otherAppBundle.bundleURL, kSecCSDefaultFlags, &staticAppCode);
if (result != noErr) {
SULog(@"Failed to copy other app code %d", result);
goto finally;
}
}
// Note that kSecCSCheckNestedCode may not work with pre-Mavericks code signing.
// See https://github.com/sparkle-project/Sparkle/issues/376#issuecomment-48824267 and https://developer.apple.com/library/mac/technotes/tn2206
CFErrorRef cfError = NULL;
SecCSFlags flags = (SecCSFlags) (kSecCSDefaultFlags | kSecCSCheckAllArchitectures);
result = SecStaticCodeCheckValidityWithErrors(staticCode, flags, requirement, &cfError);
result = SecStaticCodeCheckValidityWithErrors(staticAppCode, flags, requirement, &cfError);
if (cfError) {
NSError *tmpError = CFBridgingRelease(cfError);
if (error) *error = tmpError;
if (error) {
*error = tmpError;
}
}
if (result != noErr) {
@@ -71,14 +112,14 @@
CFRelease(requirementString);
}
[self logSigningInfoForCode:hostCode label:@"host info"];
[self logSigningInfoForCode:staticCode label:@"new info"];
[self logSigningInfoForCode:staticHostCode label:@"host info"];
[self logSigningInfoForCode:staticAppCode label:@"new info"];
}
}
finally:
if (hostCode) CFRelease(hostCode);
if (staticCode) CFRelease(staticCode);
if (staticHostCode) CFRelease(staticHostCode);
if (staticAppCode) CFRelease(staticAppCode);
if (requirement) CFRelease(requirement);
return (result == noErr);
}
@@ -150,20 +191,6 @@ static id valueOrNSNull(id value) {
}
}
+ (BOOL)hostApplicationIsCodeSigned
{
OSStatus result;
SecCodeRef hostCode = NULL;
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
if (result != 0) return NO;
SecRequirementRef requirement = NULL;
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
if (hostCode) CFRelease(hostCode);
if (requirement) CFRelease(requirement);
return (result == 0);
}
+ (BOOL)hostApplicationIsSandboxed
{
static BOOL sIsAppSandboxed = NO;
+1 -1
View File
@@ -14,7 +14,7 @@
#import "SUVersionComparisonProtocol.h"
#import "SUVersionDisplayProtocol.h"
@class SUUpdateDriver, SUAppcastItem, SUHost, SUAppcast;
@class SUAppcastItem, SUAppcast;
@protocol SUUpdaterDelegate;
+1 -1
View File
@@ -111,7 +111,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
// Saving-the-developer-from-a-stupid-mistake-check:
BOOL hasPublicDSAKey = [host publicDSAKey] != nil;
BOOL isMainBundle = [bundle isEqualTo:[NSBundle mainBundle]];
BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned];
BOOL hostIsCodeSigned = [SUCodeSigningVerifier applicationAtPathIsCodeSigned:host.bundlePath];
BOOL servingOverHttps = [[[[self feedURL] scheme] lowercaseString] isEqualToString:@"https"];
NSAlert *alert = nil;
if (!isMainBundle && !hasPublicDSAKey) {
+1 -1
View File
@@ -8,7 +8,7 @@
#import "SUUpdater.h"
@class SUBasicUpdateDriver;
@class SUBasicUpdateDriver, SUHost;
@interface SUUpdater (Private)