From 467ffb15caa7b490d056d405c69a45cecdc349ee Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 3 Apr 2021 13:46:10 -0700 Subject: [PATCH] Pass whether or not system domain is being used back to framework This avoids needing to do a file system check in InstallerConnection to determine if we need to connect to the system or user domain. --- Autoupdate/SPUInstallationInfo.h | 2 + Autoupdate/SPUInstallationInfo.m | 14 ++++- InstallerConnection/SUInstallerConnection.m | 5 +- .../SUInstallerConnectionProtocol.h | 2 +- .../SUXPCInstallerConnection.m | 4 +- InstallerLauncher/SUInstallerLauncher.m | 63 +++++++++++++++---- .../SUInstallerLauncherProtocol.h | 2 +- InstallerStatus/SUInstallerStatus.m | 1 - Sparkle.xcodeproj/project.pbxproj | 22 ++----- .../InstallerProgressAppController.m | 17 ++++- Sparkle/SPUBasicUpdateDriver.h | 2 +- Sparkle/SPUBasicUpdateDriver.m | 17 +++-- Sparkle/SPUCoreBasedUpdateDriver.m | 5 +- Sparkle/SPUInstallerDriver.h | 2 +- Sparkle/SPUInstallerDriver.m | 17 +++-- Sparkle/SPUProbingUpdateDriver.m | 2 +- Sparkle/SPUSecureCoding.h | 3 + Sparkle/SPUSystemAuthorization.h | 15 ----- Sparkle/SPUSystemAuthorization.m | 55 ---------------- 19 files changed, 121 insertions(+), 129 deletions(-) delete mode 100644 Sparkle/SPUSystemAuthorization.h delete mode 100644 Sparkle/SPUSystemAuthorization.m diff --git a/Autoupdate/SPUInstallationInfo.h b/Autoupdate/SPUInstallationInfo.h index 37d25312..e0c4f2db 100644 --- a/Autoupdate/SPUInstallationInfo.h +++ b/Autoupdate/SPUInstallationInfo.h @@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) SUAppcastItem *appcastItem; @property (nonatomic, readonly) BOOL canSilentlyInstall; +@property (nonatomic) BOOL systemDomain; + @end NS_ASSUME_NONNULL_END diff --git a/Autoupdate/SPUInstallationInfo.m b/Autoupdate/SPUInstallationInfo.m index bb628ef0..6e8e51d9 100644 --- a/Autoupdate/SPUInstallationInfo.m +++ b/Autoupdate/SPUInstallationInfo.m @@ -14,22 +14,30 @@ static NSString *SUAppcastItemKey = @"SUAppcastItem"; static NSString *SUCanSilentlyInstallKey = @"SUCanSilentlyInstall"; +static NSString *SUSystemDomainKey = @"SUSystemDomain"; @implementation SPUInstallationInfo @synthesize appcastItem = _appcastItem; @synthesize canSilentlyInstall = _canSilentlyInstall; +@synthesize systemDomain = _systemDomain; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall +- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall systemDomain:(BOOL)systemDomain { self = [super init]; if (self != nil) { _appcastItem = appcastItem; _canSilentlyInstall = canSilentlyInstall; + _systemDomain = systemDomain; } return self; } +- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentlyInstall +{ + return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:NO]; +} + - (nullable instancetype)initWithCoder:(NSCoder *)decoder { SUAppcastItem *appcastItem = [decoder decodeObjectOfClass:[SUAppcastItem class] forKey:SUAppcastItemKey]; @@ -38,13 +46,15 @@ static NSString *SUCanSilentlyInstallKey = @"SUCanSilentlyInstall"; } BOOL canSilentlyInstall = [decoder decodeBoolForKey:SUCanSilentlyInstallKey]; - return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall]; + BOOL systemDomain = [decoder decodeBoolForKey:SUSystemDomainKey]; + return [self initWithAppcastItem:appcastItem canSilentlyInstall:canSilentlyInstall systemDomain:systemDomain]; } - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.appcastItem forKey:SUAppcastItemKey]; [coder encodeBool:self.canSilentlyInstall forKey:SUCanSilentlyInstallKey]; + [coder encodeBool:self.systemDomain forKey:SUSystemDomainKey]; } + (BOOL)supportsSecureCoding diff --git a/InstallerConnection/SUInstallerConnection.m b/InstallerConnection/SUInstallerConnection.m index 249ad219..89887aff 100644 --- a/InstallerConnection/SUInstallerConnection.m +++ b/InstallerConnection/SUInstallerConnection.m @@ -7,7 +7,6 @@ // #import "SUInstallerConnection.h" -#import "SPUSystemAuthorization.h" #include "AppKitPrevention.h" @@ -61,9 +60,9 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K [self enableAutomaticTermination]; } -- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType +- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain { - NSXPCConnectionOptions options = SPUNeedsSystemAuthorizationAccess(hostPath, installationType) ? NSXPCConnectionPrivileged : 0; + NSXPCConnectionOptions options = systemDomain ? 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 cbba5f57..900c91b8 100644 --- a/InstallerConnection/SUInstallerConnectionProtocol.h +++ b/InstallerConnection/SUInstallerConnectionProtocol.h @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setInvalidationHandler:(void (^)(void))invalidationHandler; -- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType; +- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain; - (void)invalidate; diff --git a/InstallerConnection/SUXPCInstallerConnection.m b/InstallerConnection/SUXPCInstallerConnection.m index efb239bf..d077f190 100644 --- a/InstallerConnection/SUXPCInstallerConnection.m +++ b/InstallerConnection/SUXPCInstallerConnection.m @@ -62,9 +62,9 @@ }]; } -- (void)setServiceName:(NSString *)serviceName hostPath:(NSString *)hostPath installationType:(NSString *)installationType +- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain { - [(id)self.connection.remoteObjectProxy setServiceName:serviceName hostPath:hostPath installationType:installationType]; + [(id)self.connection.remoteObjectProxy setServiceName:serviceName systemDomain:systemDomain]; } - (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data diff --git a/InstallerLauncher/SUInstallerLauncher.m b/InstallerLauncher/SUInstallerLauncher.m index 2b10d3e1..782302e5 100644 --- a/InstallerLauncher/SUInstallerLauncher.m +++ b/InstallerLauncher/SUInstallerLauncher.m @@ -10,7 +10,6 @@ #import "SUFileManager.h" #import "SULog.h" #import "SPUMessageTypes.h" -#import "SPUSystemAuthorization.h" #import "SUBundleIcon.h" #import "SPULocalCacheDirectory.h" #import "SPUInstallationType.h" @@ -281,8 +280,50 @@ return resolvedAuxiliaryToolURL.path; } +static BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType) +{ + BOOL needsAuthorization; + if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) { + needsAuthorization = YES; + } else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) { + needsAuthorization = NO; + } else { + NSFileManager *fileManager = [NSFileManager defaultManager]; + BOOL hasWritability = [fileManager isWritableFileAtPath:path] && [fileManager isWritableFileAtPath:[path stringByDeletingLastPathComponent]]; + if (!hasWritability) { + needsAuthorization = YES; + } else { + // Just because we have writability access does not mean we can set the correct owner/group + // Test if we can set the owner/group on a temporarily created file + // If we can, then we can probably perform an update without authorization + + NSString *tempFilename = @"permission_test" ; + + SUFileManager *suFileManager = [[SUFileManager alloc] init]; + NSURL *tempDirectoryURL = [suFileManager makeTemporaryDirectoryWithPreferredName:tempFilename appropriateForDirectoryURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:NULL]; + + if (tempDirectoryURL == nil) { + // I don't imagine this ever happening but in case it does, requesting authorization may be the better option + needsAuthorization = YES; + } else { + NSURL *tempFileURL = [tempDirectoryURL URLByAppendingPathComponent:tempFilename]; + if (![[NSData data] writeToURL:tempFileURL atomically:NO]) { + // Obvious indicator we may need authorization + needsAuthorization = YES; + } else { + needsAuthorization = ![suFileManager changeOwnerAndGroupOfItemAtRootURL:tempFileURL toMatchURL:[NSURL fileURLWithPath:path] error:NULL]; + } + + [suFileManager removeItemAtURL:tempDirectoryURL error:NULL]; + } + } + } + return needsAuthorization; +} + + // Note: do not pass untrusted information such as paths to the installer and progress agent tools, when we can find them ourselves here -- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus))completionHandler +- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler { dispatch_async(dispatch_get_main_queue(), ^{ NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath]; @@ -290,19 +331,19 @@ if (needsSystemAuthorization && !allowingUpdaterInteraction) { SULog(SULogLevelError, @"Updater is not allowing interaction to the launcher."); - completionHandler(SUInstallerLauncherFailure); + completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); return; } if (!allowingUpdaterInteraction && [installationType isEqualToString:SPUInstallationTypeInteractivePackage]) { SULog(SULogLevelError, @"Updater is not allowing interaction to the launcher for performing an interactive type package installation."); - completionHandler(SUInstallerLauncherFailure); + completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); return; } // if we need to use the system domain and we aren't allowed interaction, then try sometime later when interaction is allowed if (needsSystemAuthorization && !allowingDriverInteraction) { - completionHandler(SUInstallerLauncherAuthorizeLater); + completionHandler(SUInstallerLauncherAuthorizeLater, needsSystemAuthorization); return; } @@ -317,7 +358,7 @@ NSString *installerPath = [self pathForBundledTool:@""SPARKLE_RELAUNCH_TOOL_NAME extension:@"" inBundle:ourBundle]; if (installerPath == nil) { SULog(SULogLevelError, @"Error: Cannot submit installer because the installer could not be located"); - completionHandler(SUInstallerLauncherFailure); + completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); return; } @@ -326,7 +367,7 @@ if (progressToolResourcePath == nil) { SULog(SULogLevelError, @"Error: Cannot submit progress tool because the progress tool could not be located"); - completionHandler(SUInstallerLauncherFailure); + completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); return; } @@ -342,7 +383,7 @@ NSString *launcherCachePath = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:rootLauncherCachePath]; if (launcherCachePath == nil) { SULog(SULogLevelError, @"Failed to create cache directory for progress tool in %@", rootLauncherCachePath); - completionHandler(SUInstallerLauncherFailure); + completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); return; } @@ -352,7 +393,7 @@ // SUFileManager is more reliable for copying files around if (![[[SUFileManager alloc] init] copyItemAtURL:[NSURL fileURLWithPath:progressToolResourcePath] toURL:[NSURL fileURLWithPath:progressToolPath] error:©Error]) { SULog(SULogLevelError, @"Failed to copy progress tool to cache: %@", copyError); - completionHandler(SUInstallerLauncherFailure); + completionHandler(SUInstallerLauncherFailure, needsSystemAuthorization); return; } @@ -370,9 +411,9 @@ } if (installerStatus == SUInstallerLauncherCanceled) { - completionHandler(installerStatus); + completionHandler(installerStatus, needsSystemAuthorization); } else { - completionHandler(submittedProgressTool ? SUInstallerLauncherSuccess : SUInstallerLauncherFailure); + completionHandler(submittedProgressTool ? SUInstallerLauncherSuccess : SUInstallerLauncherFailure, needsSystemAuthorization); } }); } diff --git a/InstallerLauncher/SUInstallerLauncherProtocol.h b/InstallerLauncher/SUInstallerLauncherProtocol.h index c3c03bce..c03e01a7 100644 --- a/InstallerLauncher/SUInstallerLauncherProtocol.h +++ b/InstallerLauncher/SUInstallerLauncherProtocol.h @@ -11,7 +11,7 @@ @protocol SUInstallerLauncherProtocol -- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus))completionHandler; +- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler; - (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL requiresAuthorization))reply; diff --git a/InstallerStatus/SUInstallerStatus.m b/InstallerStatus/SUInstallerStatus.m index edad00d6..bf513981 100644 --- a/InstallerStatus/SUInstallerStatus.m +++ b/InstallerStatus/SUInstallerStatus.m @@ -7,7 +7,6 @@ // #import "SUInstallerStatus.h" -#import "SPUSystemAuthorization.h" #include "AppKitPrevention.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 7860b693..d38c7db3 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -130,6 +130,9 @@ 7205C4631E1306B500E370AE /* libxar.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E07681CA616A4001A286B /* libxar.tbd */; }; 7205C4641E1306BE00E370AE /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E076A1CA616B3001A286B /* libbz2.tbd */; }; 720767D31E2EE9C200F9A850 /* SUTouchBarForwardDeclarations.h in Headers */ = {isa = PBXBuildFile; fileRef = 720767D21E2EE9C200F9A850 /* SUTouchBarForwardDeclarations.h */; }; + 720AC2A42618E85700E25A3E /* SPUInstallationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5B51D3D8AEE00D1BF90 /* SPUInstallationInfo.m */; }; + 720AC2C92618E89500E25A3E /* SUAppcastItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */; }; + 720AC2DC2618E8A500E25A3E /* SPUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */; }; 720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 720B16431C66433D006985FB /* SUTestApplicationTest.swift */; }; 720E217B1D0D00BF003A311C /* SPUUpdaterCycle.h in Headers */ = {isa = PBXBuildFile; fileRef = 720E21791D0D00BF003A311C /* SPUUpdaterCycle.h */; }; 720E217C1D0D00BF003A311C /* SPUUpdaterCycle.m in Sources */ = {isa = PBXBuildFile; fileRef = 720E217A1D0D00BF003A311C /* SPUUpdaterCycle.m */; }; @@ -139,7 +142,6 @@ 7214B8831D456C2400CB5CED /* SUBundleIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7214B8801D456A8500CB5CED /* SUBundleIcon.m */; }; 7214B8841D456C9500CB5CED /* SUBundleIcon.m in Sources */ = {isa = PBXBuildFile; fileRef = 7214B8801D456A8500CB5CED /* SUBundleIcon.m */; }; 72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B071C82C9600013C1C5 /* SULocalizations.h */; }; - 721652621D3C44A100FD13D8 /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; 721BC20E1D1CDE55002BC71E /* SPULocalCacheDirectory.h in Headers */ = {isa = PBXBuildFile; fileRef = 721BC20C1D1CDE55002BC71E /* SPULocalCacheDirectory.h */; }; 721BC20F1D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; }; 721BC2101D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; }; @@ -208,10 +210,6 @@ 724BB3A81D33461B005D534A /* SUXPCInstallerStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 724BB3A61D33461B005D534A /* SUXPCInstallerStatus.h */; }; 724BB3A91D33461B005D534A /* SUXPCInstallerStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3A71D33461B005D534A /* SUXPCInstallerStatus.m */; }; 724BB3AA1D3347C2005D534A /* SUInstallerStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3971D333832005D534A /* SUInstallerStatus.m */; }; - 724BB3AF1D34828A005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; - 724BB3B01D3482BA005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; - 724BB3B11D3484B2005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; - 724BB3B21D34862A005D534A /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; 724BB3B71D35ABA8005D534A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; 724F76F91D6EAD0D00ECD062 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; }; 725264A91D5FBD9100CD6400 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; @@ -337,7 +335,6 @@ 72A5D5B51D6929F80009E5AC /* SPUMessageTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5B01D3D8AD500D1BF90 /* SPUMessageTypes.m */; }; 72A5D5B61D6929F80009E5AC /* SPUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */; }; 72A5D5B71D6929F80009E5AC /* SPUInstallationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5B51D3D8AEE00D1BF90 /* SPUInstallationInfo.m */; }; - 72A5D5B81D6929F80009E5AC /* SPUSystemAuthorization.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */; }; 72A5D5B91D6929F80009E5AC /* SUAppcast.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FB9509C4F04600B25A18 /* SUAppcast.m */; }; 72A5D5BA1D6929F80009E5AC /* SUAppcastItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */; }; 72A5D5BB1D6929F80009E5AC /* SPUURLDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 72B09CE61CE6BCBD0052EF9E /* SPUURLDownload.m */; }; @@ -1198,8 +1195,6 @@ 724BB3A51D3338C8005D534A /* ConfigInstallerStatusDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigInstallerStatusDebug.xcconfig; sourceTree = ""; }; 724BB3A61D33461B005D534A /* SUXPCInstallerStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUXPCInstallerStatus.h; sourceTree = ""; }; 724BB3A71D33461B005D534A /* SUXPCInstallerStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUXPCInstallerStatus.m; sourceTree = ""; }; - 724BB3AB1D347EDE005D534A /* SPUSystemAuthorization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUSystemAuthorization.h; path = Sparkle/SPUSystemAuthorization.h; sourceTree = SOURCE_ROOT; }; - 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUSystemAuthorization.m; path = Sparkle/SPUSystemAuthorization.m; sourceTree = SOURCE_ROOT; }; 724BB3B51D35AAC3005D534A /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; }; 725602D31C83551C00DAA70E /* SUApplicationInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUApplicationInfo.h; sourceTree = ""; }; 725602D41C83551C00DAA70E /* SUApplicationInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUApplicationInfo.m; sourceTree = ""; }; @@ -2225,8 +2220,6 @@ 7267E5B01D3D8AD500D1BF90 /* SPUMessageTypes.m */, 726E075A1CA3A6D6001A286B /* SPUSecureCoding.h */, 726E075B1CA3A6D6001A286B /* SPUSecureCoding.m */, - 724BB3AB1D347EDE005D534A /* SPUSystemAuthorization.h */, - 724BB3AC1D347EDE005D534A /* SPUSystemAuthorization.m */, ); name = IPC; path = Autoupdate; @@ -3395,13 +3388,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 720AC2DC2618E8A500E25A3E /* SPUSecureCoding.m in Sources */, + 720AC2C92618E89500E25A3E /* SUAppcastItem.m in Sources */, + 720AC2A42618E85700E25A3E /* SPUInstallationInfo.m in Sources */, 72D954811CBACC35006F28BD /* InstallerProgressAppController.m in Sources */, 72D954831CBAD34F006F28BD /* main.m in Sources */, 72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */, 727F340E2605321D00020E85 /* SULog+NSError.m in Sources */, 7267E5DC1D3D8F1E00D1BF90 /* SPUMessageTypes.m in Sources */, 723C8A561E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */, - 721652621D3C44A100FD13D8 /* SPUSystemAuthorization.m in Sources */, 5AA89BA623FE276A0094DAB8 /* SUSignatures.m in Sources */, 7267E5FA1D3DAC3600D1BF90 /* StatusInfo.m in Sources */, 720595EF1D700568000572E8 /* SUApplicationInfo.m in Sources */, @@ -3421,7 +3416,6 @@ buildActionMask = 2147483647; files = ( 724BB3731D31D0B7005D534A /* main.m in Sources */, - 724BB3B11D3484B2005D534A /* SPUSystemAuthorization.m in Sources */, 72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */, 724BB3711D31D0B7005D534A /* SUInstallerConnection.m in Sources */, ); @@ -3432,7 +3426,6 @@ buildActionMask = 2147483647; files = ( 724BB39A1D333832005D534A /* main.m in Sources */, - 724BB3B21D34862A005D534A /* SPUSystemAuthorization.m in Sources */, 72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */, 724BB3981D333832005D534A /* SUInstallerStatus.m in Sources */, ); @@ -3455,7 +3448,6 @@ 726E07B41CAF08D6001A286B /* main.m in Sources */, 721D8A7B1D4963190032E472 /* SPULocalCacheDirectory.m in Sources */, 7267E5E11D3D901600D1BF90 /* SPUMessageTypes.m in Sources */, - 724BB3AF1D34828A005D534A /* SPUSystemAuthorization.m in Sources */, 5AA89BA523FE27660094DAB8 /* SUSignatures.m in Sources */, 7214B8841D456C9500CB5CED /* SUBundleIcon.m in Sources */, 726E07BF1CAF0C6C001A286B /* SUConstants.m in Sources */, @@ -3512,7 +3504,6 @@ 72A5D5CA1D6929F80009E5AC /* SPUProbingUpdateDriver.m in Sources */, 72A5D5C91D6929F80009E5AC /* SPUScheduledUpdateDriver.m in Sources */, 72A5D5B61D6929F80009E5AC /* SPUSecureCoding.m in Sources */, - 72A5D5B81D6929F80009E5AC /* SPUSystemAuthorization.m in Sources */, 72A5D5CC1D6929F80009E5AC /* SPUUIBasedUpdateDriver.m in Sources */, 72A5D5D61D6929F80009E5AC /* SPUUpdatePermissionRequest.m in Sources */, 72A5D5D41D6929F80009E5AC /* SPUUpdater.m in Sources */, @@ -3623,7 +3614,6 @@ 726E075D1CA3A6D6001A286B /* SPUSecureCoding.m in Sources */, 7246E0A41C83B685003B4E75 /* SPUStandardUpdaterController.m in Sources */, 725CB95B1C7121830064365A /* SPUStandardUserDriver.m in Sources */, - 724BB3B01D3482BA005D534A /* SPUSystemAuthorization.m in Sources */, 723C8A551E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */, 72B767DB1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.m in Sources */, 72DBA37E1D60CC34002594A8 /* SPUUpdatePermissionRequest.m in Sources */, diff --git a/Sparkle/InstallerProgress/InstallerProgressAppController.m b/Sparkle/InstallerProgress/InstallerProgressAppController.m index 5e698aea..4bba0dc2 100644 --- a/Sparkle/InstallerProgress/InstallerProgressAppController.m +++ b/Sparkle/InstallerProgress/InstallerProgressAppController.m @@ -19,6 +19,8 @@ #import "SUErrors.h" #import "SUNormalization.h" #import "SUConstants.h" +#import "SPUSecureCoding.h" +#import "SPUInstallationInfo.h" /*! * Terminate the application after a delay from launching the new update to avoid OS activation issues @@ -37,6 +39,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; @property (nonatomic, readonly) SUHost *oldHost; @property (nonatomic, readonly) BOOL shouldRelaunchHostBundle; @property (nonatomic, readonly) NSString *oldHostBundlePath; +@property (nonatomic, readonly) BOOL systemDomain; @property (nonatomic) StatusInfo *statusInfo; @property (nonatomic) BOOL submittedLauncherJob; @property (nonatomic) BOOL willTerminate; @@ -58,6 +61,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; @synthesize oldHost = _oldHost; @synthesize shouldRelaunchHostBundle = _shouldRelaunchHostBundle; @synthesize oldHostBundlePath = _oldHostBundlePath; +@synthesize systemDomain = _systemDomain; @synthesize statusInfo = _statusInfo; @synthesize submittedLauncherJob = _submittedLauncherJob; @synthesize willTerminate = _willTerminate; @@ -104,6 +108,8 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; // nor have a model where a process that runs at the highest level (the installer can run as root) tries to connect to a user level agent or process BOOL systemDomain = arguments[2].boolValue; NSXPCConnectionOptions connectionOptions = systemDomain ? NSXPCConnectionPrivileged : 0; + + _systemDomain = systemDomain; _connection = [[NSXPCConnection alloc] initWithMachServiceName:SPUProgressAgentServiceNameForBundleIdentifier(hostBundleIdentifier) options:connectionOptions]; _statusInfo = [[StatusInfo alloc] initWithHostBundleIdentifier:hostBundleIdentifier]; @@ -264,8 +270,15 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; - (void)registerInstallationInfoData:(NSData *)installationInfoData { dispatch_async(dispatch_get_main_queue(), ^{ - if (self.statusInfo.installationInfoData == nil) { - self.statusInfo.installationInfoData = installationInfoData; + if (self.statusInfo.installationInfoData == nil && installationInfoData != nil) { + SPUInstallationInfo *installationInfo = (SPUInstallationInfo *)SPUUnarchiveRootObjectSecurely(installationInfoData, [SPUInstallationInfo class]); + + if (installationInfo != nil) { + installationInfo.systemDomain = self.systemDomain; + self.statusInfo.installationInfoData = SPUArchiveRootObjectSecurely(installationInfo); + } else { + SULog(SULogLevelError, @"Error: Failed to decode initial installation info from installer: %@", installationInfoData); + } } }); } diff --git a/Sparkle/SPUBasicUpdateDriver.h b/Sparkle/SPUBasicUpdateDriver.h index a8de86e3..8598024f 100644 --- a/Sparkle/SPUBasicUpdateDriver.h +++ b/Sparkle/SPUBasicUpdateDriver.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SPUBasicUpdateDriverDelegate -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain; - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index 4f05033f..fa072a6b 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -79,7 +79,7 @@ } } -- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem +- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem systemDomain:(NSNumber * _Nullable)systemDomain { if (updateItem == nil) { [self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Failed to resume installing update.", nil) }]]; @@ -88,7 +88,7 @@ [self notifyFinishLoadingAppcast]; SUAppcastItem *nonNullUpdateItem = updateItem; - [self didFindValidUpdateWithAppcastItem:nonNullUpdateItem preventsAutoupdate:NO]; + [self notifyFoundValidUpdateWithAppcastItem:nonNullUpdateItem preventsAutoupdate:NO systemDomain:systemDomain]; } } @@ -100,7 +100,7 @@ assert(hostBundleIdentifier != nil); [SPUProbeInstallStatus probeInstallerUpdateItemForHostBundleIdentifier:hostBundleIdentifier completion:^(SPUInstallationInfo * _Nullable installationInfo) { dispatch_async(dispatch_get_main_queue(), ^{ - [self notifyResumableUpdateItem:installationInfo.appcastItem]; + [self notifyResumableUpdateItem:installationInfo.appcastItem systemDomain:@(installationInfo.systemDomain)]; }); }]; } @@ -109,7 +109,7 @@ { self.completionBlock = completionBlock; - [self notifyResumableUpdateItem:resumableUpdate.updateItem]; + [self notifyResumableUpdateItem:resumableUpdate.updateItem systemDomain:nil]; } - (SUAppcastItem *)nonDeltaUpdateItem @@ -142,7 +142,7 @@ } } -- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain { if (!self.aborted) { [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification @@ -153,10 +153,15 @@ [self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem]; } - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate systemDomain:systemDomain]; } } +- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate +{ + [self notifyFoundValidUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate systemDomain:nil]; +} + - (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult { if (!self.aborted) { diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index 40eadf4c..8537aa2e 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -145,12 +145,13 @@ } } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain { self.updateItem = updateItem; if (self.resumingInstallingUpdate) { - [self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem]; + assert(systemDomain != nil); + [self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem systemDomain:systemDomain.boolValue]; [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem preventsAutoupdate:preventsAutoupdate]; } else { if (!self.preventsInstallerInteraction) { diff --git a/Sparkle/SPUInstallerDriver.h b/Sparkle/SPUInstallerDriver.h index 3819c8dc..9ab98a2a 100644 --- a/Sparkle/SPUInstallerDriver.h +++ b/Sparkle/SPUInstallerDriver.h @@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id)updaterDelegate delegate:(nullable id)delegate; -- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem; +- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem systemDomain:(BOOL)systemDomain; - (void)checkIfApplicationInstallationRequiresAuthorizationWithReply:(void (^)(BOOL requiresAuthorization))reply; diff --git a/Sparkle/SPUInstallerDriver.m b/Sparkle/SPUInstallerDriver.m index 60dd99e7..c69f49f1 100644 --- a/Sparkle/SPUInstallerDriver.m +++ b/Sparkle/SPUInstallerDriver.m @@ -54,6 +54,8 @@ @property (nonatomic, weak, readonly) id updaterDelegate; @property (nonatomic) BOOL willRelaunch; +@property (nonatomic) BOOL systemDomain; + @property (nonatomic) SUAppcastItem *updateItem; @property (nonatomic, copy) NSString *downloadName; @property (nonatomic, copy) NSString *temporaryDirectory; @@ -77,6 +79,7 @@ @synthesize updater = _updater; @synthesize updaterDelegate = _updaterDelegate; @synthesize willRelaunch = _willRelaunch; +@synthesize systemDomain = _systemDomain; @synthesize updateItem = _updateItem; @synthesize downloadName = _downloadName; @synthesize temporaryDirectory = _temporaryDirectory; @@ -137,7 +140,7 @@ NSString *installationType = self.updateItem.installationType; assert(installationType != nil); - [self.installerConnection setServiceName:serviceName hostPath:self.host.bundlePath installationType:installationType]; + [self.installerConnection setServiceName:serviceName systemDomain:self.systemDomain]; [self sendInstallationData]; } @@ -160,9 +163,10 @@ } } -- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem +- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem systemDomain:(BOOL)systemDomain { self.updateItem = updateItem; + self.systemDomain = systemDomain; } - (void)sendInstallationData @@ -433,7 +437,7 @@ // 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 launchInstallerWithHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:!preventsInstallerInteraction completion:^(SUInstallerLauncherStatus result) { + [installerLauncher launchInstallerWithHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:!preventsInstallerInteraction completion:^(SUInstallerLauncherStatus result, BOOL systemDomain) { dispatch_async(dispatch_get_main_queue(), ^{ retrievedLaunchStatus = YES; [launcherConnection invalidate]; @@ -450,6 +454,7 @@ completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationAuthorizeLaterError userInfo:nil]); break; case SUInstallerLauncherSuccess: + self.systemDomain = systemDomain; [self setUpConnection]; completionHandler(nil); break; @@ -463,12 +468,6 @@ return (!self.updaterDelegate || ![self.updaterDelegate respondsToSelector:@selector((updaterShouldRelaunchApplication:))] || [self.updaterDelegate updaterShouldRelaunchApplication:self.updater]); } -// Only implemented due to backwards compability reasons; see -installWithToolAndRelaunch:displayingUserInterface: below -- (void)installWithToolAndRelaunch:(BOOL)relaunch -{ - [self installWithToolAndRelaunch:relaunch displayingUserInterface:relaunch]; -} - - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI { assert(self.updateItem); diff --git a/Sparkle/SPUProbingUpdateDriver.m b/Sparkle/SPUProbingUpdateDriver.m index 61a1b7c6..965f4b71 100644 --- a/Sparkle/SPUProbingUpdateDriver.m +++ b/Sparkle/SPUProbingUpdateDriver.m @@ -54,7 +54,7 @@ [self.basicDriver resumeUpdate:resumableUpdate completion:completionBlock]; } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate systemDomain:(NSNumber * _Nullable)__unused systemDomain { // Stop as soon as we have an answer [self abortUpdate]; diff --git a/Sparkle/SPUSecureCoding.h b/Sparkle/SPUSecureCoding.h index 85d149bb..fa773b7b 100644 --- a/Sparkle/SPUSecureCoding.h +++ b/Sparkle/SPUSecureCoding.h @@ -8,6 +8,9 @@ #import +// If we are using XPC without using XPC Services, our custom classes will not be (de)serialized automatically, +// hence needing functions to archive/unarchive NSSecureCoding objects. + NS_ASSUME_NONNULL_BEGIN NSData * _Nullable SPUArchiveRootObjectSecurely(id rootObject); diff --git a/Sparkle/SPUSystemAuthorization.h b/Sparkle/SPUSystemAuthorization.h deleted file mode 100644 index 9aa45652..00000000 --- a/Sparkle/SPUSystemAuthorization.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// SPUSystemAuthorization.h -// Sparkle -// -// Created by Mayur Pawashe on 7/11/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType); - -NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUSystemAuthorization.m b/Sparkle/SPUSystemAuthorization.m deleted file mode 100644 index 87411019..00000000 --- a/Sparkle/SPUSystemAuthorization.m +++ /dev/null @@ -1,55 +0,0 @@ -// -// SPUSystemAuthorization.m -// Sparkle -// -// Created by Mayur Pawashe on 7/11/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import "SPUSystemAuthorization.h" -#import "SPUInstallationType.h" -#import "SUFileManager.h" - - -#include "AppKitPrevention.h" - -BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installationType) -{ - BOOL needsAuthorization; - if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) { - needsAuthorization = YES; - } else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) { - needsAuthorization = NO; - } else { - NSFileManager *fileManager = [NSFileManager defaultManager]; - BOOL hasWritability = [fileManager isWritableFileAtPath:path] && [fileManager isWritableFileAtPath:[path stringByDeletingLastPathComponent]]; - if (!hasWritability) { - needsAuthorization = YES; - } else { - // Just because we have writability access does not mean we can set the correct owner/group - // Test if we can set the owner/group on a temporarily created file - // If we can, then we can probably perform an update without authorization - - NSString *tempFilename = @"permission_test" ; - - SUFileManager *suFileManager = [[SUFileManager alloc] init]; - NSURL *tempDirectoryURL = [suFileManager makeTemporaryDirectoryWithPreferredName:tempFilename appropriateForDirectoryURL:[NSURL fileURLWithPath:NSTemporaryDirectory()] error:NULL]; - - if (tempDirectoryURL == nil) { - // I don't imagine this ever happening but in case it does, requesting authorization may be the better option - needsAuthorization = YES; - } else { - NSURL *tempFileURL = [tempDirectoryURL URLByAppendingPathComponent:tempFilename]; - if (![[NSData data] writeToURL:tempFileURL atomically:NO]) { - // Obvious indicator we may need authorization - needsAuthorization = YES; - } else { - needsAuthorization = ![suFileManager changeOwnerAndGroupOfItemAtRootURL:tempFileURL toMatchURL:[NSURL fileURLWithPath:path] error:NULL]; - } - - [suFileManager removeItemAtURL:tempDirectoryURL error:NULL]; - } - } - } - return needsAuthorization; -}