diff --git a/CHANGELOG b/CHANGELOG index 3d8d6e1a..97b5f3be 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ * Reject unsupported code-signing xattrs in binary delta (Zorg) * Fixed crash while applying delta update (antonc27) * Added logging of appcast/download URL on error (Kornel LesiƄski) +* More robust reading of Autoupdate.app path from Sparkle bundle # 1.10.0 diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index 89337f25..d9e78800 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -31,7 +31,8 @@ MACOSX_DEPLOYMENT_TARGET = 10.7 PRODUCT_NAME = ${TARGET_NAME} PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier} -GCC_PREPROCESSOR_DEFINITIONS = SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" +GCC_PREPROCESSOR_DEFINITIONS = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" + CLANG_ENABLE_OBJC_ARC = YES // Enable warnings diff --git a/Resources/Sparkle-Icon.psd b/Resources/Sparkle-Icon.psd new file mode 100644 index 00000000..7097a190 Binary files /dev/null and b/Resources/Sparkle-Icon.psd differ diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index b1ba4ec1..33047aab 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -335,8 +335,8 @@ 14732BBC1960EFB500593899 /* README.markdown */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.markdown; sourceTree = SOURCE_ROOT; }; 14732BBF1960F0AC00593899 /* test_app_only_dsa_pub.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = test_app_only_dsa_pub.pem; sourceTree = ""; }; 14732BC11960F3B200593899 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = SOURCE_ROOT; usesTabs = 1; }; - 14732BC31960F3FF00593899 /* generate_keys.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = generate_keys.sh; sourceTree = ""; }; - 14732BC41960F3FF00593899 /* sign_update.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sign_update.sh; sourceTree = ""; }; + 14732BC31960F3FF00593899 /* generate_keys */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = generate_keys; sourceTree = ""; }; + 14732BC41960F3FF00593899 /* sign_update */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = sign_update; sourceTree = ""; }; 14732BC91960F70A00593899 /* make-release-package.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "make-release-package.sh"; sourceTree = ""; }; 14732BD219610A1800593899 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterTest.m; sourceTree = ""; usesTabs = 0; }; @@ -763,8 +763,8 @@ 14732BC21960F3FF00593899 /* bin */ = { isa = PBXGroup; children = ( - 14732BC31960F3FF00593899 /* generate_keys.sh */, - 14732BC41960F3FF00593899 /* sign_update.sh */, + 14732BC31960F3FF00593899 /* generate_keys */, + 14732BC41960F3FF00593899 /* sign_update */, ); path = bin; sourceTree = SOURCE_ROOT; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 8f2a6c8c..85d5dd91 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -442,10 +442,12 @@ [updaterDelegate updater:self.updater willInstallUpdate:self.updateItem]; } - NSBundle *sparkleBundle = [NSBundle bundleWithIdentifier:SUBundleIdentifier]; + NSBundle *sparkleBundle = self.updater.sparkleBundle; + // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. - NSString *const relaunchPathToCopy = [sparkleBundle pathForResource:[[sparkleBundle infoDictionary] objectForKey:SURelaunchToolNameKey] ofType:@"app"]; + NSString *const relaunchToolName = @"" SPARKLE_RELAUNCH_TOOL_NAME; + NSString *const relaunchPathToCopy = [sparkleBundle pathForResource:relaunchToolName ofType:@"app"]; if (relaunchPathToCopy != nil) { NSString *targetPath = [self.host.appCachePath stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index dadef0c2..b717d843 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -51,11 +51,10 @@ extern NSString *const SUPromptUserOnFirstLaunchKey; extern NSString *const SUKeepDownloadOnFailedInstallKey; extern NSString *const SUDefaultsDomainKey; extern NSString *const SUFixedHTMLDisplaySizeKey __attribute__((deprecated("This key is obsolete and has no effect."))); - -extern NSString *const SUAppendVersionNumberKey; -extern NSString *const SUEnableAutomatedDowngradesKey; -extern NSString *const SUNormalizeInstalledApplicationNameKey; -extern NSString *const SURelaunchToolNameKey; +extern NSString *const SUAppendVersionNumberKey __attribute__((deprecated("This key is obsolete. See SPARKLE_APPEND_VERSION_NUMBER."))); +extern NSString *const SUEnableAutomatedDowngradesKey __attribute__((deprecated("This key is obsolete. See SPARKLE_AUTOMATED_DOWNGRADES."))); +extern NSString *const SUNormalizeInstalledApplicationNameKey __attribute__((deprecated("This key is obsolete. SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME."))); +extern NSString *const SURelaunchToolNameKey __attribute__((deprecated("This key is obsolete. SPARKLE_RELAUNCH_TOOL_NAME."))); // ----------------------------------------------------------------------------- // Appcast keys:: diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index b9d622e8..ea5cf66b 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -91,7 +91,7 @@ typedef struct { - (NSString *)installationPath { - if ([[[NSBundle bundleWithIdentifier:SUBundleIdentifier] infoDictionary][SUNormalizeInstalledApplicationNameKey] boolValue]) { + if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) { // We'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name. NSString *normalizedAppPath = [[[self.bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [self.bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[self.bundle bundlePath] pathExtension]]]; if (![[NSFileManager defaultManager] fileExistsAtPath:[[[self.bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [self.bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[self.bundle bundlePath] pathExtension]]]]) { diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index da02f674..1fa1a8dd 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -69,12 +69,8 @@ } // Decide on a destination name we should use for the older app when we move it around the file system - // TODO: will need to merge finding sparkle bundle this with newer code - NSBundle *sparkleBundle = [NSBundle bundleWithIdentifier:SUBundleIdentifier]; - BOOL appendVersion = [[sparkleBundle infoDictionary][SUAppendVersionNumberKey] boolValue]; - NSString *oldDestinationName = nil; - if (appendVersion) { + if (SPARKLE_APPEND_VERSION_NUMBER) { NSString *oldBundleVersion = [self bundleVersionAppropriateForFilenameFromHost:host]; oldDestinationName = [oldURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingFormat:@" (%@)", oldBundleVersion != nil ? oldBundleVersion : @"old"]; @@ -174,8 +170,10 @@ { SUParameterAssert(host); + BOOL allowDowngrades = SPARKLE_AUTOMATED_DOWNGRADES; + // Prevent malicious downgrades - if (![[[NSBundle bundleWithIdentifier:SUBundleIdentifier] infoDictionary][SUEnableAutomatedDowngradesKey] boolValue]) { + if (!allowDowngrades) { if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending) { NSString *errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]]; NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }]; diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 3ac4828a..ce07a142 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -33,6 +33,7 @@ SU_EXPORT @interface SUUpdater : NSObject - (instancetype)initForBundle:(NSBundle *)bundle; @property (readonly, strong) NSBundle *hostBundle; +@property (strong, readonly) NSBundle *sparkleBundle; @property BOOL automaticallyChecksForUpdates; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index ca3b3606..5e0557f0 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -29,6 +29,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @interface SUUpdater () @property (strong) NSTimer *checkTimer; +@property (strong) NSBundle *sparkleBundle; + - (instancetype)initForBundle:(NSBundle *)bundle; - (void)startUpdateCycle; - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver; @@ -54,6 +56,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize httpHeaders; @synthesize driver; @synthesize host; +@synthesize sparkleBundle; static NSMutableDictionary *sharedUpdaters = nil; static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; @@ -80,6 +83,12 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults self = [super init]; if (bundle == nil) bundle = [NSBundle mainBundle]; + self.sparkleBundle = [NSBundle bundleForClass:[self class]]; + if (!self.sparkleBundle) { + SULog(@"Error: SUUpdater can't find Sparkle.framework it belongs to"); + return nil; + } + // Register as observer straight away to avoid exceptions on -dealloc when -unregisterAsObserver is called: if (self) { [self registerAsObserver]; @@ -465,7 +474,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults return customUserAgentString; } - NSString *version = [[NSBundle bundleWithIdentifier:SUBundleIdentifier] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; + NSString *version = [self.sparkleBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; NSString *userAgent = [NSString stringWithFormat:@"%@/%@ Sparkle/%@", [self.host name], [self.host displayVersion], version ? version : @"?"]; NSData *cleanedAgent = [userAgent dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; return [[NSString alloc] initWithData:cleanedAgent encoding:NSASCIIStringEncoding]; diff --git a/Sparkle/Sparkle-Info.plist b/Sparkle/Sparkle-Info.plist index 9efef523..0caff79f 100644 --- a/Sparkle/Sparkle-Info.plist +++ b/Sparkle/Sparkle-Info.plist @@ -24,13 +24,5 @@ ${CURRENT_PROJECT_VERSION} NSPrincipalClass - SUAppendVersionNumber - ${SPARKLE_APPEND_VERSION_NUMBER} - SUEnableAutomatedDowngrades - ${SPARKLE_AUTOMATED_DOWNGRADES} - SUNormalizeInstalledApplicationName - ${SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME} - SURelaunchToolName - ${SPARKLE_RELAUNCH_TOOL_NAME} diff --git a/bin/generate_keys.sh b/bin/generate_keys similarity index 96% rename from bin/generate_keys.sh rename to bin/generate_keys index 4666fbb0..4df8464c 100755 --- a/bin/generate_keys.sh +++ b/bin/generate_keys @@ -11,7 +11,6 @@ openssl="/usr/bin/openssl" $openssl gendsa <($openssl dsaparam 4096) -out dsa_priv.pem chmod 0400 dsa_priv.pem $openssl dsa -in dsa_priv.pem -pubout -out dsa_pub.pem -chmod 0444 dsa_pub.pem echo " Generated private and public keys: dsa_priv.pem and dsa_pub.pem. diff --git a/bin/sign_update.sh b/bin/sign_update similarity index 94% rename from bin/sign_update.sh rename to bin/sign_update index 7c439990..cd149133 100755 --- a/bin/sign_update.sh +++ b/bin/sign_update @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e set -o pipefail if [ "$#" -ne 2 ]; then