diff --git a/Autoupdate/AppInstaller.m b/Autoupdate/AppInstaller.m index 41d973ba..23df75f3 100644 --- a/Autoupdate/AppInstaller.m +++ b/Autoupdate/AppInstaller.m @@ -26,6 +26,7 @@ #import "SUInstallerCommunicationProtocol.h" #import "AgentConnection.h" #import "SUInstallerAgentProtocol.h" +#import "SUInstallationType.h" #ifdef _APPKITDEFINES_H #error This is a "daemon-safe" class and should NOT import AppKit @@ -375,20 +376,26 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; NSBundle *hostBundle = [NSBundle bundleWithPath:nonNullInstallationData.hostBundlePath]; SUHost *host = [[SUHost alloc] initWithBundle:hostBundle]; - NSString *bundleIdentifier = hostBundle.bundleIdentifier; - if (bundleIdentifier == nil || ![bundleIdentifier isEqualToString:self.hostBundleIdentifier]) { - SULog(@"Error: Failed to match host bundle identifiers %@ and %@", self.hostBundleIdentifier, bundleIdentifier); + NSString *installationType = nonNullInstallationData.installationType; + if (!SUValidInstallationType(installationType)) { + SULog(@"Error: Received invalid installation type: %@", installationType); [self cleanupAndExitWithStatus:EXIT_FAILURE]; } else { - // This will be important later - if (nonNullInstallationData.relaunchPath == nil) { - SULog(@"Error: Failed to obtain relaunch path from installation data"); + NSString *bundleIdentifier = hostBundle.bundleIdentifier; + if (bundleIdentifier == nil || ![bundleIdentifier isEqualToString:self.hostBundleIdentifier]) { + SULog(@"Error: Failed to match host bundle identifiers %@ and %@", self.hostBundleIdentifier, bundleIdentifier); [self cleanupAndExitWithStatus:EXIT_FAILURE]; } else { - self.host = host; - self.installationData = installationData; - - [self extractAndInstallUpdate]; + // This will be important later + if (nonNullInstallationData.relaunchPath == nil) { + SULog(@"Error: Failed to obtain relaunch path from installation data"); + [self cleanupAndExitWithStatus:EXIT_FAILURE]; + } else { + self.host = host; + self.installationData = installationData; + + [self extractAndInstallUpdate]; + } } } } @@ -436,7 +443,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; dispatch_async(self.installerQueue, ^{ NSError *installerError = nil; - id installer = [SUInstaller installerForHost:self.host updateDirectory:self.installationData.updateDirectoryPath allowingInteraction:self.allowsInteraction versionComparator:[SUStandardVersionComparator standardVersionComparator] error:&installerError]; + id installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationData.installationType updateDirectory:self.installationData.updateDirectoryPath allowingInteraction:self.allowsInteraction versionComparator:[SUStandardVersionComparator standardVersionComparator] error:&installerError]; if (installer == nil) { SULog(@"Error: Failed to create installer instance with error: %@", installerError); diff --git a/Autoupdate/SUInstallationInputData.h b/Autoupdate/SUInstallationInputData.h index 573916c3..d585ac72 100644 --- a/Autoupdate/SUInstallationInputData.h +++ b/Autoupdate/SUInstallationInputData.h @@ -20,12 +20,13 @@ NS_ASSUME_NONNULL_BEGIN * dsaSignature - DSA signature for the update that came from the appcast item * decryptionPassword - optional decryption password for dmg archives */ -- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadName:(NSString *)downloadName dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword; +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadName:(NSString *)downloadName installationType:(NSString *)installationType dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword; @property (nonatomic, copy, readonly) NSString *relaunchPath; @property (nonatomic, copy, readonly) NSString *hostBundlePath; @property (nonatomic, copy, readonly) NSString *updateDirectoryPath; @property (nonatomic, copy, readonly) NSString *downloadName; +@property (nonatomic, copy, readonly) NSString *installationType; @property (nonatomic, copy, readonly) NSString *dsaSignature; @property (nonatomic, copy, readonly, nullable) NSString *decryptionPassword; diff --git a/Autoupdate/SUInstallationInputData.m b/Autoupdate/SUInstallationInputData.m index 93250523..4854677a 100644 --- a/Autoupdate/SUInstallationInputData.m +++ b/Autoupdate/SUInstallationInputData.m @@ -7,6 +7,7 @@ // #import "SUInstallationInputData.h" +#import "SUInstallationType.h" #ifdef _APPKITDEFINES_H #error This is a "daemon-safe" class and should NOT import AppKit @@ -18,6 +19,7 @@ static NSString *SUUpdateDirectoryPathKey = @"SUUpdateDirectoryPath"; static NSString *SUDownloadNameKey = @"SUDownloadName"; static NSString *SUDSASignatureKey = @"SUDSASignature"; static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; +static NSString *SUInstallationTypeKey = @"SUInstallationType"; @implementation SUInstallationInputData @@ -27,8 +29,9 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; @synthesize downloadName = _downloadName; @synthesize dsaSignature = _dsaSignature; @synthesize decryptionPassword = _decryptionPassword; +@synthesize installationType = _installationType; -- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadName:(NSString *)downloadName dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadName:(NSString *)downloadName installationType:(NSString *)installationType dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword { self = [super init]; if (self != nil) { @@ -36,6 +39,10 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; _hostBundlePath = [hostBundlePath copy]; _updateDirectoryPath = [updateDirectoryPath copy]; _downloadName = [downloadName copy]; + + _installationType = [installationType copy]; + assert(SUValidInstallationType(_installationType)); + _dsaSignature = [dsaSignature copy]; _decryptionPassword = [decryptionPassword copy]; } @@ -64,6 +71,11 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; return nil; } + NSString *installationType = [decoder decodeObjectOfClass:[NSString class] forKey:SUInstallationTypeKey]; + if (!SUValidInstallationType(installationType)) { + return nil; + } + NSString *dsaSignature = [decoder decodeObjectOfClass:[NSString class] forKey:SUDSASignatureKey]; if (dsaSignature == nil) { return nil; @@ -71,7 +83,7 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; NSString *decryptionPassword = [decoder decodeObjectOfClass:[NSString class] forKey:SUDecryptionPasswordKey]; - return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadName:downloadName dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; + return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadName:downloadName installationType:installationType dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; } - (void)encodeWithCoder:(NSCoder *)coder @@ -79,6 +91,7 @@ static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; [coder encodeObject:self.relaunchPath forKey:SURelaunchPathKey]; [coder encodeObject:self.hostBundlePath forKey:SUHostBundlePathKey]; [coder encodeObject:self.updateDirectoryPath forKey:SUUpdateDirectoryPathKey]; + [coder encodeObject:self.installationType forKey:SUInstallationTypeKey]; [coder encodeObject:self.downloadName forKey:SUDownloadNameKey]; [coder encodeObject:self.dsaSignature forKey:SUDSASignatureKey]; if (self.decryptionPassword != nil) { diff --git a/Autoupdate/SUInstaller.h b/Autoupdate/SUInstaller.h index d6fc3b96..9f8952fc 100644 --- a/Autoupdate/SUInstaller.h +++ b/Autoupdate/SUInstaller.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUInstaller : NSObject -+ (nullable id)installerForHost:(SUHost *)host updateDirectory:(NSString *)updateDirectory allowingInteraction:(BOOL)allowsInteraction versionComparator:(id )comparator error:(NSError **)error; ++ (nullable id)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory allowingInteraction:(BOOL)allowsInteraction versionComparator:(id )comparator error:(NSError **)error; + (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr; diff --git a/Autoupdate/SUInstaller.m b/Autoupdate/SUInstaller.m index 1e043c16..63604e33 100644 --- a/Autoupdate/SUInstaller.m +++ b/Autoupdate/SUInstaller.m @@ -15,6 +15,7 @@ #import "SULog.h" #import "SUParameterAssert.h" #import "SUErrors.h" +#import "SUInstallationType.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -112,7 +113,7 @@ return newAppDownloadPath; } -+ (nullable id)installerForHost:(SUHost *)host updateDirectory:(NSString *)updateDirectory allowingInteraction:(BOOL)allowsInteraction versionComparator:(id )comparator error:(NSError * __autoreleasing *)error ++ (nullable id)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory allowingInteraction:(BOOL)allowsInteraction versionComparator:(id )comparator error:(NSError * __autoreleasing *)error { BOOL isPackage = NO; BOOL isGuided = NO; @@ -125,16 +126,43 @@ return nil; } - // If the installer does not allow interaction, we could be running as root - // If we are running as root, using a non-guided package installer does not work properly so avoid it at all costs + // Make sure we find the type of installer that we were expecting to find + // We shouldn't implicitly trust the installation type fed into here from the appcast because the installation type helps us determine + // ahead of time whether or not this installer tool should be ran as root or not id installer = nil; - if (isPackage && (isGuided || !allowsInteraction)) { - installer = [[SUGuidedPackageInstaller alloc] initWithPackagePath:newDownloadPath]; + if (isPackage && isGuided) { + if (![expectedInstallationType isEqualToString:SUInstallationTypeGuidedPackage]) { + if (error != NULL) { + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found guided package installer but '%@=%@' was probably missing in the appcast item enclosure", SUAppcastAttributeInstallationType, SUInstallationTypeGuidedPackage] }]; + } + } else { + installer = [[SUGuidedPackageInstaller alloc] initWithPackagePath:newDownloadPath]; + } } else if (isPackage) { - installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath]; + if (![expectedInstallationType isEqualToString:SUInstallationTypePackage]) { + if (error != NULL) { + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found package installer but '%@=%@' was probably missing in the appcast item enclosure", SUAppcastAttributeInstallationType, SUInstallationTypePackage] }]; + } + } else { +#warning review this + // Even if we expect an ordinary package, if we don't allow interaction (eg: because we're already running root) - + // we should try a guided installation instead - because an ordinary package installation may not work well + if (allowsInteraction) { + installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath]; + } else { + installer = [[SUGuidedPackageInstaller alloc] initWithPackagePath:newDownloadPath]; + } + } } else { - installer = [[SUPlainInstaller alloc] initWithHost:host applicationPath:newDownloadPath installationPath:[[self class] installationPathForHost:host] versionComparator:comparator]; + if (![expectedInstallationType isEqualToString:SUInstallationTypeApplication]) { + if (error != NULL) { + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found regular application update but expected '%@=%@' from the appcast item enclosure instead", SUAppcastAttributeInstallationType, expectedInstallationType] }]; + } + } else { + installer = [[SUPlainInstaller alloc] initWithHost:host applicationPath:newDownloadPath installationPath:[[self class] installationPathForHost:host] versionComparator:comparator]; + } } + return installer; } diff --git a/InstallerConnection/SUInstallerConnection.m b/InstallerConnection/SUInstallerConnection.m index 71246774..b4f26932 100644 --- a/InstallerConnection/SUInstallerConnection.m +++ b/InstallerConnection/SUInstallerConnection.m @@ -58,9 +58,9 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K [self enableAutomaticTermination]; } -- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath guided:(BOOL)guided +- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType { - NSXPCConnectionOptions options = SUNeedsSystemAuthorizationAccess(hostPath, guided, NULL) ? NSXPCConnectionPrivileged : 0; + NSXPCConnectionOptions options = SUNeedsSystemAuthorizationAccess(hostPath, installationType, NULL) ? NSXPCConnectionPrivileged : 0; NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:options]; connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)]; diff --git a/InstallerConnection/SUInstallerConnectionProtocol.h b/InstallerConnection/SUInstallerConnectionProtocol.h index 8eeaeb0c..61bb80de 100644 --- a/InstallerConnection/SUInstallerConnectionProtocol.h +++ b/InstallerConnection/SUInstallerConnectionProtocol.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setInvalidationHandler:(void (^)(void))invalidationHandler; -- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath guided:(BOOL)guided; +- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType; - (void)invalidate; diff --git a/InstallerConnection/SUXPCInstallerConnection.m b/InstallerConnection/SUXPCInstallerConnection.m index 76cbe27e..ae04b223 100644 --- a/InstallerConnection/SUXPCInstallerConnection.m +++ b/InstallerConnection/SUXPCInstallerConnection.m @@ -59,9 +59,9 @@ }]; } -- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath guided:(BOOL)guided +- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType { - [self.connection.remoteObjectProxy setServiceName:serviceName hostPath:hostPath guided:guided]; + [self.connection.remoteObjectProxy setServiceName:serviceName hostPath:hostPath installationType:installationType]; } - (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data diff --git a/InstallerLauncher/SUInstallerLauncher.m b/InstallerLauncher/SUInstallerLauncher.m index d8cbfdb6..b04e0aa6 100644 --- a/InstallerLauncher/SUInstallerLauncher.m +++ b/InstallerLauncher/SUInstallerLauncher.m @@ -264,13 +264,13 @@ return reply; } -- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt guidedInstallation:(BOOL)guidedInstallation allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(SUAuthorizationReply))completionHandler +- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(SUAuthorizationReply))completionHandler { dispatch_async(dispatch_get_main_queue(), ^{ NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath]; BOOL preflighted = NO; - BOOL needsSystemAuthorization = SUNeedsSystemAuthorizationAccess(hostBundlePath, guidedInstallation, &preflighted); + BOOL needsSystemAuthorization = SUNeedsSystemAuthorizationAccess(hostBundlePath, installationType, &preflighted); // if we need to use the system domain and we aren't already root and we aren't allowed interaction, then try sometime later when interaction is allowed if (needsSystemAuthorization && !preflighted && !allowingInteraction) { diff --git a/InstallerLauncher/SUInstallerLauncherProtocol.h b/InstallerLauncher/SUInstallerLauncherProtocol.h index d0175c2d..5fd9fa3c 100644 --- a/InstallerLauncher/SUInstallerLauncherProtocol.h +++ b/InstallerLauncher/SUInstallerLauncherProtocol.h @@ -11,6 +11,6 @@ @protocol SUInstallerLauncherProtocol -- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt guidedInstallation:(BOOL)guidedInstallation allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(SUAuthorizationReply))completionHandler; +- (void)launchInstallerAtPath:(NSString *)installerPath progressToolPath:(NSString *)progressToolPath withHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingInteraction:(BOOL)allowingInteraction completion:(void (^)(SUAuthorizationReply))completionHandler; @end diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index dfe90726..4a8843ef 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -760,6 +760,7 @@ 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = ""; }; 7214B87F1D456A8500CB5CED /* SUBundleIcon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBundleIcon.h; sourceTree = ""; }; 7214B8801D456A8500CB5CED /* SUBundleIcon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBundleIcon.m; sourceTree = ""; }; + 7214B8851D45AD9A00CB5CED /* SUInstallationType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUInstallationType.h; sourceTree = ""; }; 72162B051C82C8B30013C1C5 /* SUParameterAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUParameterAssert.h; sourceTree = ""; }; 72162B071C82C9600013C1C5 /* SULocalizations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULocalizations.h; sourceTree = ""; }; 721652671D3C8FED00FD13D8 /* SUAuthorizationReply.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SUAuthorizationReply.h; path = InstallerLauncher/SUAuthorizationReply.h; sourceTree = SOURCE_ROOT; }; @@ -1385,6 +1386,7 @@ 61B5FB9509C4F04600B25A18 /* SUAppcast.m */, 61B5FC5309C5182000B25A18 /* SUAppcastItem.h */, 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */, + 7214B8851D45AD9A00CB5CED /* SUInstallationType.h */, 72B09CE51CE6BCBD0052EF9E /* SUURLDownload.h */, 72B09CE61CE6BCBD0052EF9E /* SUURLDownload.m */, 7293A1AC1CEE933800B957A7 /* SUURLRequest.h */, diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 69fa0286..54bbf509 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -30,6 +30,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly) NSString *displayVersionString; @property (copy, readonly) NSDictionary *deltaUpdates; @property (strong, readonly) NSURL *infoURL; +@property (nonatomic, copy, readonly) NSString *installationType; // Initializes with data from a dictionary provided by the RSS class. - (instancetype)initWithDictionary:(NSDictionary *)dict; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 855e5dd3..681b8db8 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -10,6 +10,7 @@ #import "SUVersionComparisonProtocol.h" #import "SULog.h" #import "SUConstants.h" +#import "SUInstallationType.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -28,6 +29,7 @@ static NSString *SUAppcastItemReleaseNotesURLKey = @"releaseNotesURL"; static NSString *SUAppcastItemTitleKey = @"title"; static NSString *SUAppcastItemVersionStringKey = @"versionString"; static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; +static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationType"; @implementation SUAppcastItem @@ -45,6 +47,7 @@ static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; @synthesize title = _title; @synthesize versionString = _versionString; @synthesize propertiesDictionary = _propertiesDictionary; +@synthesize installationType = _installationType; + (BOOL)supportsSecureCoding { @@ -67,6 +70,11 @@ static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; return nil; } + _installationType = [decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemInstallationTypeKey]; + if (!SUValidInstallationType(_installationType)) { + return nil; + } + _itemDescription = [[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemDescriptionKey] copy]; _maximumSystemVersion = [[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMaximumSystemVersionKey] copy]; _minimumSystemVersion = [[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMinimumSystemVersionKey] copy]; @@ -130,6 +138,10 @@ static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; if (self.propertiesDictionary != nil) { [encoder encodeObject:self.propertiesDictionary forKey:SUAppcastItemPropertiesKey]; } + + if (self.installationType != nil) { + [encoder encodeObject:self.installationType forKey:SUAppcastItemInstallationTypeKey]; + } } - (BOOL)isDeltaUpdate @@ -263,6 +275,18 @@ static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; } else { _displayVersionString = [_versionString copy]; } + + _installationType = [enclosure objectForKey:SUAppcastAttributeInstallationType]; + if (_installationType == nil) { + _installationType = SUInstallationTypeDefault; + } else if (!SUValidInstallationType(_installationType)) { + if (error != NULL) { + *error = [NSString stringWithFormat:@"Feed item's enclosure lacks valid %@ (found %@)", SUAppcastAttributeInstallationType, _installationType]; + } + return nil; + } else if ([_installationType isEqualToString:SUInstallationTypePackage]) { + SULog(@"warning: '%@' for %@ is deprecated. Use '%@' instead.", SUInstallationTypePackage, SUAppcastAttributeInstallationType, SUInstallationTypeGuidedPackage); + } // Find the appropriate release notes URL. NSString *releaseNotesString = [dict objectForKey:SUAppcastElementReleaseNotesLink]; diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index ff36ab3b..ec0bad29 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -66,6 +66,7 @@ extern NSString *const SUAppcastAttributeDeltaFrom; extern NSString *const SUAppcastAttributeDSASignature; extern NSString *const SUAppcastAttributeShortVersionString; extern NSString *const SUAppcastAttributeVersion; +extern NSString *const SUAppcastAttributeInstallationType; extern NSString *const SUAppcastElementCriticalUpdate; extern NSString *const SUAppcastElementDeltas; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 2c69d8ae..8e892e0e 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -64,6 +64,7 @@ NSString *const SUAppcastAttributeDeltaFrom = @"sparkle:deltaFrom"; NSString *const SUAppcastAttributeDSASignature = @"sparkle:dsaSignature"; NSString *const SUAppcastAttributeShortVersionString = @"sparkle:shortVersionString"; NSString *const SUAppcastAttributeVersion = @"sparkle:version"; +NSString *const SUAppcastAttributeInstallationType = @"sparkle:installationType"; NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate"; NSString *const SUAppcastElementDeltas = @"sparkle:deltas"; diff --git a/Sparkle/SUInstallationType.h b/Sparkle/SUInstallationType.h new file mode 100644 index 00000000..e8830951 --- /dev/null +++ b/Sparkle/SUInstallationType.h @@ -0,0 +1,20 @@ +// +// SUInstallationType.h +// Sparkle +// +// Created by Mayur Pawashe on 7/24/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#ifndef SUInstallationType_h +#define SUInstallationType_h + +#define SUInstallationTypeApplication @"application" // the default installation type for ordinary application updates +#define SUInstallationTypeGuidedPackage @"guided-package" // the preferred installation type for package installations +#define SUInstallationTypePackage @"package" // the deprecated installation type; use guided package instead + +#define SUInstallationTypeDefault SUInstallationTypeApplication +#define SUInstallationTypesArray (@[SUInstallationTypeApplication, SUInstallationTypeGuidedPackage, SUInstallationTypePackage]) +#define SUValidInstallationType(x) ((x != nil) && [SUInstallationTypesArray containsObject:x]) + +#endif /* SUInstallationType_h */ diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index f9cff8bd..3aeed79d 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -125,9 +125,10 @@ }]; NSString *serviceName = SUInstallerServiceNameForBundleIdentifier(hostBundleIdentifier); + NSString *installationType = self.updateItem.installationType; + assert(installationType != nil); -#warning use self.updateItem later for passing guided option - [self.installerConnection setServiceName:serviceName hostPath:self.host.bundlePath guided:NO]; + [self.installerConnection setServiceName:serviceName hostPath:self.host.bundlePath installationType:installationType]; [self sendInstallationData]; } @@ -169,7 +170,7 @@ decryptionPassword = [self.updaterDelegate decryptionPasswordForUpdater:self.updater]; } - SUInstallationInputData *installationData = [[SUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadName:self.downloadName dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; + SUInstallationInputData *installationData = [[SUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadName:self.downloadName installationType:self.updateItem.installationType dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; NSData *archivedData = SUArchiveRootObjectSecurely(installationData); if (archivedData == nil) { @@ -438,10 +439,12 @@ NSString *hostBundlePath = self.host.bundle.bundlePath; assert(hostBundlePath != nil); -#warning pass actual guided flag eventually + NSString *installationType = self.updateItem.installationType; + assert(installationType != nil); + // The installer launcher could be in a XPC service, so we don't want to do localization in there NSString *authorizationPrompt = [NSString stringWithFormat:SULocalizedString(@"%1$@ wants to update.", nil), self.host.name]; - [installerLauncher launchInstallerAtPath:relaunchToolPath progressToolPath:progressToolPath withHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt guidedInstallation:NO allowingInteraction:shouldAllowInstallerInteraction completion:^(SUAuthorizationReply result) { + [installerLauncher launchInstallerAtPath:relaunchToolPath progressToolPath:progressToolPath withHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingInteraction:shouldAllowInstallerInteraction completion:^(SUAuthorizationReply result) { dispatch_async(dispatch_get_main_queue(), ^{ retrievedLaunchStatus = YES; [launcherConnection invalidate]; diff --git a/Sparkle/SUSystemAuthorization.h b/Sparkle/SUSystemAuthorization.h index 13fc0547..6e9232ce 100644 --- a/Sparkle/SUSystemAuthorization.h +++ b/Sparkle/SUSystemAuthorization.h @@ -11,6 +11,6 @@ NS_ASSUME_NONNULL_BEGIN -BOOL SUNeedsSystemAuthorizationAccess(NSString *path, BOOL guided, BOOL * _Nullable preflighted); +BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType, BOOL * _Nullable preflighted); NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUSystemAuthorization.m b/Sparkle/SUSystemAuthorization.m index 8afe4d9b..0b5a87e7 100644 --- a/Sparkle/SUSystemAuthorization.m +++ b/Sparkle/SUSystemAuthorization.m @@ -8,6 +8,7 @@ #import "SUSystemAuthorization.h" #import +#import "SUInstallationType.h" static BOOL SUPreflightSystemAuthorization(void) { @@ -38,7 +39,7 @@ static BOOL SUPreflightSystemAuthorization(void) return (copyStatus == errAuthorizationSuccess); } -BOOL SUNeedsSystemAuthorizationAccess(NSString *path, BOOL guided, BOOL * _Nullable preflighted) +BOOL SUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType, BOOL * _Nullable preflighted) { BOOL result; if (SUPreflightSystemAuthorization()) { @@ -46,8 +47,10 @@ BOOL SUNeedsSystemAuthorizationAccess(NSString *path, BOOL guided, BOOL * _Nulla *preflighted = YES; } result = YES; - } else if (guided) { + } else if ([installationType isEqualToString:SUInstallationTypeGuidedPackage]) { result = YES; + } else if ([installationType isEqualToString:SUInstallationTypePackage]) { + result = NO; } else { #warning what about symbolic links? NSFileManager *fileManager = [NSFileManager defaultManager];