From 38af7cd8cd63a2c0b14f473c19c5c6329fe3a449 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 26 Aug 2016 23:01:30 -0400 Subject: [PATCH 01/10] Export -validateMenuItem: as a method in SUUpdater.h for public use --- Sparkle/SUUpdater.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 308f14d3..a64253ce 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -70,6 +70,11 @@ SU_EXPORT @interface SUUpdater : NSObject */ - (IBAction)checkForUpdates:(id)sender; +/*! + The menu item validation used for the -checkForUpdates: action + */ +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem; + /*! Checks for updates, but does not display any UI unless an update is found. From eb810c7d8f15a0fbf0136af1b1ff67e8c15506fd Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 26 Aug 2016 23:03:08 -0400 Subject: [PATCH 02/10] Implement menu item validation in Test Applications window controller --- TestApplication/SUUpdateSettingsWindowController.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/TestApplication/SUUpdateSettingsWindowController.m b/TestApplication/SUUpdateSettingsWindowController.m index 3d651044..24516509 100644 --- a/TestApplication/SUUpdateSettingsWindowController.m +++ b/TestApplication/SUUpdateSettingsWindowController.m @@ -29,4 +29,12 @@ [self.updater checkForUpdates:nil]; } +- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +{ + if (menuItem.action == @selector(checkForUpdates:)) { + return [self.updater validateMenuItem:menuItem]; + } + return YES; +} + @end From fdf79bc3a608f498dfabf0e6541d9f5f26bc9b6b Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 26 Aug 2016 23:07:13 -0400 Subject: [PATCH 03/10] Enable check for updates menu item if update driver is interruptible --- Sparkle/SUUpdater.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index cd73c668..26dab0ca 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -526,7 +526,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (BOOL)validateMenuItem:(NSMenuItem *)item { if ([item action] == @selector(checkForUpdates:)) { - return ![self updateInProgress]; + return ![self updateInProgress] || [self.driver isInterruptible]; } return YES; } From 99f34299f14a781de5399717eeef138907d69ce9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 00:07:11 -0400 Subject: [PATCH 04/10] Show alert if no pub key exists, but SUPublicDSAKeyFileKey exists --- Sparkle/SUHost.h | 1 + Sparkle/SUHost.m | 7 ++++++- Sparkle/SUUpdater.m | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 6d058b90..56fa7d18 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -34,6 +34,7 @@ typedef struct { @property (getter=isRunningOnReadOnlyVolume, readonly) BOOL runningOnReadOnlyVolume; @property (getter=isBackgroundApplication, readonly) BOOL backgroundApplication; @property (readonly, copy) NSString *publicDSAKey; +@property (readonly, nonatomic, copy) NSString *publicDSAKeyFileKey; @property (readonly, copy) NSArray *systemProfile; - (id)objectForInfoDictionaryKey:(NSString *)key; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 5f9cff46..427be8d8 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -168,7 +168,7 @@ } // More likely, we've got a reference to a Resources file by filename: - NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; + NSString *keyFilename = [self publicDSAKeyFileKey]; if (!keyFilename) { return nil; } @@ -180,6 +180,11 @@ return [NSString stringWithContentsOfFile:keyPath encoding:NSASCIIStringEncoding error:nil]; } +- (NSString * __nullable)publicDSAKeyFileKey +{ + return [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; +} + - (NSArray *)systemProfile { return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHost:self]; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index cd73c668..87e6f9d3 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -127,16 +127,23 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"]; if (!hasPublicDSAKey) { - if (!isMainBundle) { + // If we failed to retrieve a DSA key but the bundle specifies a path to one, we should consider this a configuration failure + NSString *publicDSAKeyFileKey = [self.host publicDSAKeyFileKey]; + if (publicDSAKeyFileKey != nil) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:SULocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; + informativeText:[NSString stringWithFormat:SULocalizedString(@"For security reasons, the file indicated by the '%@' key needs to exist in the bundle's Resources.", nil), SUPublicDSAKeyFileKey]]; } else { - if (!hostIsCodeSigned) { + if (!isMainBundle) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:SULocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; - } else if (!servingOverHttps) { - [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:SULocalizedString(@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + informativeText:SULocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; + } else { + if (!hostIsCodeSigned) { + [self showAlertText:SULocalizedString(@"Insecure update error!", nil) + informativeText:SULocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + } else if (!servingOverHttps) { + [self showAlertText:SULocalizedString(@"Insecure update error!", nil) + informativeText:SULocalizedString(@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + } } } } From e2fc8b42585dbe994a4155439d19177678f0c40f Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 00:32:01 -0400 Subject: [PATCH 05/10] Prevent public DSA key -> no public DSA key downgrade This may prevent developers from making accidental downgrades. --- Sparkle/SUBasicUpdateDriver.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 276e7339..2a942bb1 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -317,6 +317,12 @@ SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle]; NSString *newPublicDSAKey = newHost.publicDSAKey; + // Downgrade in DSA security should not be possible + if (publicDSAKey != nil && newPublicDSAKey == nil) { + SULog(@"A public DSA key is found in the old bundle but no public DSA key is found in the new update. For security reasons, the update will be rejected."); + return NO; + } + BOOL dsaKeysMatch = (publicDSAKey == nil || newPublicDSAKey == nil) ? NO : [publicDSAKey isEqualToString:newPublicDSAKey]; // If the new DSA key differs from the old, then this check is not a security measure, because the new key is not trusted. From 115686cd07beceeeb923f22fbcc62af7876786b8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 01:09:24 -0400 Subject: [PATCH 06/10] Change dmg and test verifying code by removing NTSynchronousTask --- Sparkle.xcodeproj/project.pbxproj | 16 --- Sparkle/SUBinaryDeltaUnarchiver.m | 1 - Sparkle/SUDiskImageUnarchiver.m | 39 ++++-- Tests/SUCodeSigningVerifierTest.m | 19 +-- Vendor/CocoatechCore/NTSynchronousTask.h | 26 ---- Vendor/CocoatechCore/NTSynchronousTask.m | 169 ----------------------- 6 files changed, 40 insertions(+), 230 deletions(-) delete mode 100644 Vendor/CocoatechCore/NTSynchronousTask.h delete mode 100644 Vendor/CocoatechCore/NTSynchronousTask.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 6f7c8a4b..87532d22 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -105,7 +105,6 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */; }; 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */; settings = {ATTRIBUTES = (); }; }; - 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */; }; 611142E910FB1BE5009810AA /* bspatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 611142E810FB1BE5009810AA /* bspatch.h */; }; 61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; }; 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (); }; }; @@ -123,7 +122,6 @@ 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */; }; 6158A1C5137904B300487EC1 /* SUUpdater_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6158A1C4137904B300487EC1 /* SUUpdater_Private.h */; }; 615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */ = {isa = PBXBuildFile; fileRef = 615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */; }; - 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */; settings = {ATTRIBUTES = (); }; }; 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA4FF0DAE88B40026945C /* SUInstaller.h */; settings = {ATTRIBUTES = (); }; }; 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5000DAE88B40026945C /* SUInstaller.m */; }; 618FA5050DAE8AB80026945C /* SUPlainInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA5030DAE8AB80026945C /* SUPlainInstaller.h */; settings = {ATTRIBUTES = (); }; }; @@ -569,8 +567,6 @@ 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUDiskImageUnarchiver.h; sourceTree = ""; }; 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDiskImageUnarchiver.m; sourceTree = ""; }; 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUnarchiver_Private.h; sourceTree = ""; }; - 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTSynchronousTask.m; sourceTree = ""; }; - 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTSynchronousTask.h; sourceTree = ""; }; 611142E810FB1BE5009810AA /* bspatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bspatch.h; sourceTree = ""; }; 61131A050F846CE600E97AF6 /* da */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Sparkle.strings; sourceTree = ""; }; 61131A090F846D0A00E97AF6 /* zh_CN */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = zh_CN; path = zh_CN.lproj/Sparkle.strings; sourceTree = ""; }; @@ -897,7 +893,6 @@ isa = PBXGroup; children = ( 14732BB61960ECE800593899 /* bsdiff */, - 14732BB71960ECF000593899 /* CocoatechCore */, ); name = "Third Party"; path = Vendor; @@ -917,15 +912,6 @@ path = bsdiff; sourceTree = ""; }; - 14732BB71960ECF000593899 /* CocoatechCore */ = { - isa = PBXGroup; - children = ( - 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */, - 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */, - ); - path = CocoatechCore; - sourceTree = ""; - }; 14732BB81960EEB600593899 /* Resources */ = { isa = PBXGroup; children = ( @@ -1247,7 +1233,6 @@ buildActionMask = 2147483647; files = ( 611142E910FB1BE5009810AA /* bspatch.h in Headers */, - 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, 61CFB3290E385186007A1735 /* Sparkle.pch in Headers */, 61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */, @@ -1801,7 +1786,6 @@ files = ( 5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */, 722954C51D04E66F00ECF9CA /* SUFileOperationConstants.m in Sources */, - 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */, diff --git a/Sparkle/SUBinaryDeltaUnarchiver.m b/Sparkle/SUBinaryDeltaUnarchiver.m index 7d1e1496..e9990e65 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.m +++ b/Sparkle/SUBinaryDeltaUnarchiver.m @@ -12,7 +12,6 @@ #import "SUUnarchiver_Private.h" #import "SUHost.h" #import "SULog.h" -#import "NTSynchronousTask.h" @implementation SUBinaryDeltaUnarchiver diff --git a/Sparkle/SUDiskImageUnarchiver.m b/Sparkle/SUDiskImageUnarchiver.m index 31a1b5ec..0b8f8f92 100644 --- a/Sparkle/SUDiskImageUnarchiver.m +++ b/Sparkle/SUDiskImageUnarchiver.m @@ -8,7 +8,6 @@ #import "SUDiskImageUnarchiver.h" #import "SUUnarchiver_Private.h" -#import "NTSynchronousTask.h" #import "SULog.h" #include @@ -89,12 +88,26 @@ NSInteger taskResult = -1; @try { - NTSynchronousTask *task = [[NTSynchronousTask alloc] init]; - - [task run:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:promptData]; - - taskResult = [task result]; - output = [[task output] copy]; + NSTask *task = [[NSTask alloc] init]; + task.launchPath = @"/usr/bin/hdiutil"; + task.currentDirectoryPath = @"/"; + task.arguments = arguments; + + NSPipe *inputPipe = [NSPipe pipe]; + NSPipe *outputPipe = [NSPipe pipe]; + + task.standardInput = inputPipe; + task.standardOutput = outputPipe; + + [task launch]; + + [inputPipe.fileHandleForWriting writeData:promptData]; + [inputPipe.fileHandleForWriting closeFile]; + + [task waitUntilExit]; + + output = [outputPipe.fileHandleForReading readDataToEndOfFile]; + taskResult = task.terminationStatus; } @catch (NSException *) { @@ -144,10 +157,16 @@ dispatch_async(dispatch_get_main_queue(), delegateFailure); finally: - if (mountedSuccessfully) - [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"detach", mountPoint, @"-force"]]; - else + if (mountedSuccessfully) { + @try { + [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"detach", mountPoint, @"-force"]]; + } @catch (NSException *exception) { + SULog(@"Failed to unmount %@", mountPoint); + SULog(@"Exception: %@", exception); + } + } else { SULog(@"Can't mount DMG %@", self.archivePath); + } } } diff --git a/Tests/SUCodeSigningVerifierTest.m b/Tests/SUCodeSigningVerifierTest.m index 40aa79ac..045a128f 100644 --- a/Tests/SUCodeSigningVerifierTest.m +++ b/Tests/SUCodeSigningVerifierTest.m @@ -8,7 +8,6 @@ #import #import -#import "NTSynchronousTask.h" #import "SUCodeSigningVerifier.h" #import "SUFileManager.h" @@ -124,10 +123,14 @@ BOOL success = NO; @try { - NTSynchronousTask *task = [[NTSynchronousTask alloc] init]; - NSArray *arguments = @[ zipPath ]; - [task run:@"/usr/bin/unzip" directory:destPath withArgs:arguments input:nil]; - success = ([task result] == 0); + NSTask *task = [[NSTask alloc] init]; + task.launchPath = @"/usr/bin/unzip"; + task.currentDirectoryPath = destPath; + task.arguments = @[zipPath]; + + [task launch]; + [task waitUntilExit]; + success = (task.terminationStatus == 0); } @catch (NSException *exception) { @@ -143,9 +146,9 @@ { // ad-hoc signing with the dash NSArray *arguments = @[ @"--force", @"--deep", @"--sign", @"-", appPath ]; - NTSynchronousTask *task = [[NTSynchronousTask alloc] init]; - [task run:@"/usr/bin/codesign" directory:nil withArgs:arguments input:nil]; - success = ([task result] == 0); + NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/codesign" arguments:arguments]; + [task waitUntilExit]; + success = (task.terminationStatus == 0); } @catch (NSException *exception) { diff --git a/Vendor/CocoatechCore/NTSynchronousTask.h b/Vendor/CocoatechCore/NTSynchronousTask.h deleted file mode 100644 index cbcbf2c8..00000000 --- a/Vendor/CocoatechCore/NTSynchronousTask.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// NTSynchronousTask.h -// CocoatechCore -// -// Created by Steve Gehrman on 9/29/05. -// Copyright 2005 Steve Gehrman. All rights reserved. -// - -#ifndef NTSYNCHRONOUSTASK_H -#define NTSYNCHRONOUSTASK_H - -@interface NTSynchronousTask : NSObject -@property (readonly, strong) NSData *output; -@property (readonly) int result; - -// pass nil for directory if not needed -// returns the result -+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData; - -+(NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input; - -- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input; - -@end - -#endif diff --git a/Vendor/CocoatechCore/NTSynchronousTask.m b/Vendor/CocoatechCore/NTSynchronousTask.m deleted file mode 100644 index 3f583d7d..00000000 --- a/Vendor/CocoatechCore/NTSynchronousTask.m +++ /dev/null @@ -1,169 +0,0 @@ -// -// NTSynchronousTask.m -// CocoatechCore -// -// Created by Steve Gehrman on 9/29/05. -// Copyright 2005 Steve Gehrman. All rights reserved. -// - -#import "NTSynchronousTask.h" - -@interface NTSynchronousTask () -@property (strong) NSTask *task; -@property (strong) NSPipe *outputPipe; -@property (strong) NSPipe *inputPipe; -@property (readwrite, strong) NSData *output; -@property (getter = isDone) BOOL done; -@property (readwrite) int result; -@end - -@implementation NTSynchronousTask -@synthesize output = mv_output; -@synthesize result = mv_result; -@synthesize task = mv_task; -@synthesize outputPipe = mv_outputPipe; -@synthesize inputPipe = mv_inputPipe; -@synthesize done = mv_done; - -- (void)taskOutputAvailable:(NSNotification*)note -{ - self.output = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem]; - - self.done = YES; -} - -- (void)taskDidTerminate:(NSNotification *) __unused note -{ - self.result = [self.task terminationStatus]; -} - -- (instancetype)init -{ - self = [super init]; - if (self) - { - self.task = [[NSTask alloc] init]; - self.outputPipe = [[NSPipe alloc] init]; - self.inputPipe = [[NSPipe alloc] init]; - - self.task.standardInput = self.inputPipe; - self.task.standardOutput = self.outputPipe; - self.task.standardError = self.outputPipe; - } - - return self; -} - -//---------------------------------------------------------- -// dealloc -//---------------------------------------------------------- -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input -{ - BOOL success = NO; - - if (currentDirectory) { - self.task.currentDirectoryPath = currentDirectory; - } - - self.task.launchPath = toolPath; - self.task.arguments = args; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(taskOutputAvailable:) - name:NSFileHandleReadToEndOfFileCompletionNotification - object:[[self outputPipe] fileHandleForReading]]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(taskDidTerminate:) - name:NSTaskDidTerminateNotification - object:[self task]]; - - [[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:@[NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode]]; - - @try - { - [self.task launch]; - success = YES; - } - @catch (NSException *) { } - - if (success) - { - if (input) - { - // feed the running task our input - [[self.inputPipe fileHandleForWriting] writeData:input]; - [[self.inputPipe fileHandleForWriting] closeFile]; - } - - // loop until we are done receiving the data - if (!self.done) - { - double resolution = 1; - BOOL isRunning; - NSDate* next; - - do { - next = [NSDate dateWithTimeIntervalSinceNow:resolution]; - - isRunning = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode - beforeDate:next]; - } while (isRunning && !self.done); - } - } -} - -+ (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input -{ - @autoreleasepool { - NSData* result = nil; - // we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased - @try { - NTSynchronousTask* task = [[NTSynchronousTask alloc] init]; - - [task run:toolPath directory:currentDirectory withArgs:args input:input]; - - if ([task result] == 0) { - result = [task output]; - } - } - @catch (NSException *) { } - - return result; - } -} - - -+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData*__autoreleasing *)outData -{ - // we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased - @autoreleasepool { - int taskResult = 0; - if (outData) { - *outData = nil; - } - - @try { - NTSynchronousTask* task = [[NTSynchronousTask alloc] init]; - - [task run:toolPath directory:currentDirectory withArgs:args input:input]; - - taskResult = [task result]; - if (outData) { - *outData = [task output]; - } - - } @catch (NSException *) { - taskResult = errCppGeneral; - } - - return taskResult; - } -} - -@end From 626d2c96f5d2c6caf121a72ac09775ba3683b516 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 09:11:08 -0400 Subject: [PATCH 07/10] Show the public DSA file key that doesn't exist in the insecure alert --- Sparkle/SUUpdater.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 87e6f9d3..d0007318 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -131,7 +131,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults NSString *publicDSAKeyFileKey = [self.host publicDSAKeyFileKey]; if (publicDSAKeyFileKey != nil) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:[NSString stringWithFormat:SULocalizedString(@"For security reasons, the file indicated by the '%@' key needs to exist in the bundle's Resources.", nil), SUPublicDSAKeyFileKey]]; + informativeText:[NSString stringWithFormat:SULocalizedString(@"For security reasons, the file (%@) indicated by the '%@' key needs to exist in the bundle's Resources.", nil), publicDSAKeyFileKey, SUPublicDSAKeyFileKey]]; } else { if (!isMainBundle) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil) From f700c96e47f3bf2780f73c4b3805ddfb4ddcc315 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 09:27:06 -0400 Subject: [PATCH 08/10] Read stdout to end before waiting for task to end to prevent deadlock --- Sparkle/SUDiskImageUnarchiver.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUDiskImageUnarchiver.m b/Sparkle/SUDiskImageUnarchiver.m index 0b8f8f92..c547b44b 100644 --- a/Sparkle/SUDiskImageUnarchiver.m +++ b/Sparkle/SUDiskImageUnarchiver.m @@ -104,9 +104,10 @@ [inputPipe.fileHandleForWriting writeData:promptData]; [inputPipe.fileHandleForWriting closeFile]; - [task waitUntilExit]; - + // Read data to end *before* waiting until the task ends so we don't deadlock if the stdout buffer becomes full if we haven't consumed from it output = [outputPipe.fileHandleForReading readDataToEndOfFile]; + + [task waitUntilExit]; taskResult = task.terminationStatus; } @catch (NSException *) From 668e258cffd10de0d2ae3c87ab808e004fdcef25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Sat, 27 Aug 2016 16:11:48 +0100 Subject: [PATCH 09/10] Updated CHANGELOG --- CHANGELOG | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ce1aa63f..8d1558e0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,11 @@ +# 1.15.0 * A new icon! Thanks to 1024jp * Show alert when an update is sent over insecure HTTP with no DSA key (Zorg) - If you can't use HTTPS, you must at least sign updates with a DSA key. +* Improved binary delta implementation (Zorg) +* Added improved -validateMenuItem: as a method in SUUpdater.h for public use (Zorg) +* Removed reachability preflight check (Zorg) * Clear update caches directory before downloading new update (Zorg) * Check the bundle's parent directory for writability too (Zorg) * Don't follow symbolic links for file operations (Zorg) @@ -13,11 +17,12 @@ * Fixed german l10n. (Sebastian Volland) * Error code for download errors (Kornel Lesiński) * Update last update check date when the update driver finishes (Zorg) -* Scale app icon up if needed in Software Update window (#763) (Nicholas Riley) -* Improved tests (Zorg) -* Don't register for termination notifications more than once. Fixes #757 (Zorg) +* Scale app icon up if needed in Software Update window (Nicholas Riley) +* Don't register for termination notifications more than once (Zorg) * Don't terminate the app if we're already terminating (Zorg) * Removed SUEnableAutomaticChecksKeyOld and SUCheckAtStartup constants (Eitot) +* Updated Sparkle framework headers to use modules if modules are available (B. Kevin Hardman) +* Fixed warnings, fixed uses of SULocalizedString (Jerry Krinock) # 1.14.0 (Mar 11, 2016) From 20be93e96b0f58b460d99567e78a3c21ee5b93df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Sat, 27 Aug 2016 16:13:05 +0100 Subject: [PATCH 10/10] Version bump --- Configurations/ConfigCommon.xcconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index c4cc79c5..6894683f 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -16,7 +16,7 @@ SPARKLE_AUTOMATED_DOWNGRADES = 0 SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0 SPARKLE_VERSION_MAJOR = 1 -SPARKLE_VERSION_MINOR = 14 +SPARKLE_VERSION_MINOR = 15 SPARKLE_VERSION_PATCH = 0 SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)