diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 5571c932..df28dff9 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -75,20 +75,14 @@ 5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */; }; 5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; }; 5D06E8EA0FD68CDB005AE3F6 /* SUBinaryDeltaTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */; }; - 5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - 5D06E8FD0FD68D6B005AE3F6 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; }; 5D06E8FF0FD68D6D005AE3F6 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; }; 5D06E9050FD68D7D005AE3F6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; - 5D06E9390FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D06E9370FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h */; }; - 5D1AF58A0FD7678C0065DB48 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; }; 5D1AF58B0FD7678C0065DB48 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; }; 5D1AF5900FD767AD0065DB48 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF58F0FD767AD0065DB48 /* libxml2.dylib */; }; 5D1AF59A0FD767E50065DB48 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5990FD767E50065DB48 /* libz.dylib */; }; - 5D1AF82B0FD768180065DB48 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5990FD767E50065DB48 /* libz.dylib */; }; 6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */; settings = {ATTRIBUTES = (); }; }; - 611142E910FB1BE5009810AA /* bspatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 611142E810FB1BE5009810AA /* bspatch.h */; }; 61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */; settings = {ATTRIBUTES = (); }; }; 61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A5B09CA6D4500B7442F /* SUConstants.h */; settings = {ATTRIBUTES = (); }; }; 61299A6009CA6EB100B7442F /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; @@ -159,6 +153,18 @@ 725F97A81C8B42D700265BE4 /* SUStandardUserDriverProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 725F97A71C8B42D700265BE4 /* SUStandardUserDriverProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7268AC631AD634C200C3E0C1 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */; }; 726DF88E1C84277600188804 /* SUStatusCompletionResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 726DF88D1C84277500188804 /* SUStatusCompletionResults.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 726E075C1CA3A6D6001A286B /* SUSecureCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E075A1CA3A6D6001A286B /* SUSecureCoding.h */; }; + 726E075D1CA3A6D6001A286B /* SUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SUSecureCoding.m */; }; + 726E07601CA4E9A5001A286B /* SUInstallationInputData.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E075E1CA4E9A5001A286B /* SUInstallationInputData.h */; }; + 726E07611CA4E9A5001A286B /* SUInstallationInputData.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075F1CA4E9A5001A286B /* SUInstallationInputData.m */; }; + 726E07621CA4E9A5001A286B /* SUInstallationInputData.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075F1CA4E9A5001A286B /* SUInstallationInputData.m */; }; + 726E07631CA4F35F001A286B /* SUSecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E075B1CA3A6D6001A286B /* SUSecureCoding.m */; }; + 726E07641CA615ED001A286B /* SUBinaryDeltaUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */; }; + 726E07651CA61603001A286B /* SUBinaryDeltaApply.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E00FD68CC7005AE3F6 /* SUBinaryDeltaApply.m */; }; + 726E07661CA61621001A286B /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; }; + 726E07671CA61648001A286B /* SUBinaryDeltaCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */; }; + 726E07691CA616A4001A286B /* libxar.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E07681CA616A4001A286B /* libxar.tbd */; }; + 726E076B1CA616B3001A286B /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E076A1CA616B3001A286B /* libbz2.tbd */; }; 726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E4A101C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E4A1B1C86C88F00C57C6A /* TestAppHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E4A1A1C86C88F00C57C6A /* TestAppHelper.m */; }; @@ -662,6 +668,12 @@ 7268AC641AD634E400C3E0C1 /* SUBinaryDeltaCreate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaCreate.h; sourceTree = ""; }; 726B2B5D1C645FC900388755 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 726DF88D1C84277500188804 /* SUStatusCompletionResults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStatusCompletionResults.h; sourceTree = ""; }; + 726E075A1CA3A6D6001A286B /* SUSecureCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUSecureCoding.h; path = Sparkle/SUSecureCoding.h; sourceTree = SOURCE_ROOT; }; + 726E075B1CA3A6D6001A286B /* SUSecureCoding.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUSecureCoding.m; path = Sparkle/SUSecureCoding.m; sourceTree = SOURCE_ROOT; }; + 726E075E1CA4E9A5001A286B /* SUInstallationInputData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUInstallationInputData.h; sourceTree = ""; }; + 726E075F1CA4E9A5001A286B /* SUInstallationInputData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallationInputData.m; sourceTree = ""; }; + 726E07681CA616A4001A286B /* libxar.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxar.tbd; path = usr/lib/libxar.tbd; sourceTree = SDKROOT; }; + 726E076A1CA616B3001A286B /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverUIDelegate.h; sourceTree = ""; }; 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverRemoteDelegate.h; sourceTree = ""; }; 726E4A111C86C44A00C57C6A /* Sparkle-Test-App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Sparkle-Test-App.entitlements"; sourceTree = ""; }; @@ -766,6 +778,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 726E076B1CA616B3001A286B /* libbz2.tbd in Frameworks */, + 726E07691CA616A4001A286B /* libxar.tbd in Frameworks */, 14950071195FCE3D00BC5B5B /* AppKit.framework in Frameworks */, 14950070195FCE3A00BC5B5B /* Foundation.framework in Frameworks */, 55C14F9A136F045400649790 /* Security.framework in Frameworks */, @@ -829,9 +843,6 @@ files = ( 1495006E195FCE1100BC5B5B /* AppKit.framework in Frameworks */, 1495006F195FCE1800BC5B5B /* Foundation.framework in Frameworks */, - 5D06E8FD0FD68D6B005AE3F6 /* libbz2.dylib in Frameworks */, - 5D1AF58A0FD7678C0065DB48 /* libxar.1.dylib in Frameworks */, - 5D1AF82B0FD768180065DB48 /* libz.dylib in Frameworks */, 61B5F8F709C4CEB300B25A18 /* Security.framework in Frameworks */, 55C14F32136EFC2400649790 /* SystemConfiguration.framework in Frameworks */, 61B5FC4C09C4FD5E00B25A18 /* WebKit.framework in Frameworks */, @@ -876,6 +887,8 @@ 0867D69AFE84028FC02AAC07 /* Frameworks */ = { isa = PBXGroup; children = ( + 726E076A1CA616B3001A286B /* libbz2.tbd */, + 726E07681CA616A4001A286B /* libxar.tbd */, 0867D6A5FE840307C02AAC07 /* AppKit.framework */, 525A278F133D6AE900FD8D70 /* Cocoa.framework */, 0867D69BFE84028FC02AAC07 /* Foundation.framework */, @@ -1002,6 +1015,8 @@ 729746221C8E8F1100FC134E /* AppInstaller.m */, 7297461E1C8E8D9A00FC134E /* TerminationListener.h */, 7297461F1C8E8D9A00FC134E /* TerminationListener.m */, + 726E075E1CA4E9A5001A286B /* SUInstallationInputData.h */, + 726E075F1CA4E9A5001A286B /* SUInstallationInputData.m */, 729746481C91483B00FC134E /* IPC */, ); path = Autoupdate; @@ -1264,6 +1279,8 @@ 729746441C91212400FC134E /* SURemoteMessagePort.m */, 729746551C936D5E00FC134E /* SUMessageTypes.h */, 729746561C936D5E00FC134E /* SUMessageTypes.m */, + 726E075A1CA3A6D6001A286B /* SUSecureCoding.h */, + 726E075B1CA3A6D6001A286B /* SUSecureCoding.m */, ); name = IPC; sourceTree = ""; @@ -1341,7 +1358,6 @@ 729746571C936D5E00FC134E /* SUMessageTypes.h in Headers */, 726DF88E1C84277600188804 /* SUStatusCompletionResults.h in Headers */, 72A450531C69A68900D67EEA /* SUUpdatePermissionPromptResult.h in Headers */, - 611142E910FB1BE5009810AA /* bspatch.h in Headers */, 7229E1B61C97C91100CB50D0 /* SUUpdateDriver.h in Headers */, 729746401C9119F300FC134E /* SULocalMessagePort.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, @@ -1352,7 +1368,6 @@ 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */, 72B767D61C9C8B5C00A07552 /* SUBasicUpdateDriver.h in Headers */, 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, - 5D06E9390FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h in Headers */, 61B078CE15A5FB6100600039 /* SUCodeSigningVerifier.h in Headers */, 61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */, 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */, @@ -1360,6 +1375,7 @@ 55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */, 14652F8419A978C200959E44 /* SUExport.h in Headers */, 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */, + 726E07601CA4E9A5001A286B /* SUInstallationInputData.h in Headers */, 725602D51C83551C00DAA70E /* SUApplicationInfo.h in Headers */, 767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */, 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */, @@ -1370,6 +1386,7 @@ 728337A61C9E6FF40085AA99 /* SUProbeInstallStatus.h in Headers */, 72B767CA1C9B707000A07552 /* SUAppcastDriver.h in Headers */, 6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */, + 726E075C1CA3A6D6001A286B /* SUSecureCoding.h in Headers */, 618FA5050DAE8AB80026945C /* SUPlainInstaller.h in Headers */, 72B767E21C9CE90A00A07552 /* SUCoreBasedUpdateDriver.h in Headers */, 61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */, @@ -1814,6 +1831,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 726E07671CA61648001A286B /* SUBinaryDeltaCommon.m in Sources */, + 726E07661CA61621001A286B /* bspatch.c in Sources */, + 726E07651CA61603001A286B /* SUBinaryDeltaApply.m in Sources */, + 726E07641CA615ED001A286B /* SUBinaryDeltaUnarchiver.m in Sources */, + 726E07631CA4F35F001A286B /* SUSecureCoding.m in Sources */, 7297463A1C8FCA4900FC134E /* SUDSAVerifier.m in Sources */, 729746391C8FC04F00FC134E /* SUDiskImageUnarchiver.m in Sources */, 729746381C8FC04B00FC134E /* SUPipedUnarchiver.m in Sources */, @@ -1834,6 +1856,7 @@ 55C14F21136EF84D00649790 /* SUPlainInstaller.m in Sources */, 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 729746421C9119F300FC134E /* SULocalMessagePort.m in Sources */, + 726E07621CA4E9A5001A286B /* SUInstallationInputData.m in Sources */, 729746591C936D5E00FC134E /* SUMessageTypes.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1927,7 +1950,6 @@ 72B767E31C9CE90A00A07552 /* SUCoreBasedUpdateDriver.m in Sources */, 7297463C1C8FF6AE00FC134E /* SUCodeSigningVerifier.m in Sources */, 72B767E71C9CFD7200A07552 /* SUAutomaticUpdateDriver.m in Sources */, - 5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 7229E1BE1C98EFF200CB50D0 /* SUDownloadDriver.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, @@ -1940,6 +1962,7 @@ 72A450541C69A68900D67EEA /* SUUpdatePermissionPromptResult.m in Sources */, 7229E1BA1C97CC4D00CB50D0 /* SUScheduledUpdateDriver.m in Sources */, 729746411C9119F300FC134E /* SULocalMessagePort.m in Sources */, + 726E07611CA4E9A5001A286B /* SUInstallationInputData.m in Sources */, 7275F9C21B5F1F2900B1D19E /* SUFileManager.m in Sources */, 725CB95B1C7121830064365A /* SUStandardUserDriver.m in Sources */, 61EF67560E25B58D00F754E0 /* SUHost.m in Sources */, @@ -1955,6 +1978,7 @@ 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */, 61B5F8EE09C4CE3C00B25A18 /* SUUpdater.m in Sources */, 72B767CB1C9B707000A07552 /* SUAppcastDriver.m in Sources */, + 726E075D1CA3A6D6001A286B /* SUSecureCoding.m in Sources */, 72B767DB1C9CD2E400A07552 /* SUUIBasedUpdateDriver.m in Sources */, 729746461C91212400FC134E /* SURemoteMessagePort.m in Sources */, 729746581C936D5E00FC134E /* SUMessageTypes.m in Sources */, diff --git a/Sparkle/Autoupdate/AppInstaller.h b/Sparkle/Autoupdate/AppInstaller.h index ce82b40c..32f80bc4 100644 --- a/Sparkle/Autoupdate/AppInstaller.h +++ b/Sparkle/Autoupdate/AppInstaller.h @@ -11,8 +11,8 @@ @interface AppInstaller : NSObject -- (instancetype)initWithHostPath:(NSString *)hostPath relaunchPath:(NSString *)relaunchPath updateFolderPath:(NSString *)updateFolderPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature; +- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier; -- (void)extractAndInstallUpdate; +- (void)start; @end diff --git a/Sparkle/Autoupdate/AppInstaller.m b/Sparkle/Autoupdate/AppInstaller.m index 2603cc98..704e1909 100644 --- a/Sparkle/Autoupdate/AppInstaller.m +++ b/Sparkle/Autoupdate/AppInstaller.m @@ -19,6 +19,8 @@ #import "SURemoteMessagePort.h" #import "SULocalMessagePort.h" #import "SUMessageTypes.h" +#import "SUSecureCoding.h" +#import "SUInstallationInputData.h" /*! * Terminate the application after a delay from launching the new update to avoid OS activation issues @@ -32,18 +34,15 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; @property (nonatomic, strong) TerminationListener *terminationListener; @property (nonatomic, strong) SUStatusController *statusController; +@property (nonatomic, readonly, copy) NSString *hostBundleIdentifier; @property (nonatomic) SUHost *host; @property (nonatomic) SULocalMessagePort *localPort; @property (nonatomic) SURemoteMessagePort *remotePort; -@property (nonatomic, copy) NSString *updateFolderPath; -@property (nonatomic, copy) NSString *downloadPath; -@property (nonatomic, copy) NSString *dsaSignature; -@property (nonatomic, copy) NSString *relaunchPath; +@property (nonatomic) SUInstallationInputData *installationData; @property (nonatomic, assign) BOOL shouldRelaunch; @property (nonatomic, assign) BOOL shouldShowUI; @property (nonatomic) NSData *updateItemData; -@property (nonatomic, assign) BOOL isTerminating; @property (nonatomic) id installer; @property (nonatomic) BOOL willCompleteInstallation; @@ -55,19 +54,16 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; @implementation AppInstaller +@synthesize hostBundleIdentifier = _hostBundleIdentifier; @synthesize terminationListener = _terminationListener; @synthesize statusController = _statusController; @synthesize localPort = _localPort; @synthesize remotePort = _remotePort; @synthesize host = _host; -@synthesize updateFolderPath = _updateFolderPath; -@synthesize downloadPath = _downloadPath; -@synthesize dsaSignature = _dsaSignature; -@synthesize relaunchPath = _relaunchPath; +@synthesize installationData = _installationData; @synthesize shouldRelaunch = _shouldRelaunch; @synthesize shouldShowUI = _shouldShowUI; @synthesize updateItemData = _updateItemData; -@synthesize isTerminating = _isTerminating; @synthesize installer = _installer; @synthesize willCompleteInstallation = _willCompleteInstallation; @synthesize installerQueue = _installerQueue; @@ -83,24 +79,18 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; * shouldRelaunch - indicates if the new installed app should re-launched * shouldShowUI - indicates if we should show the status window when installing the update */ -- (instancetype)initWithHostPath:(NSString *)hostPath relaunchPath:(NSString *)relaunchPath updateFolderPath:(NSString *)updateFolderPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature + +- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier { if (!(self = [super init])) { return nil; } - NSBundle *bundle = [NSBundle bundleWithPath:hostPath]; - self.host = [[SUHost alloc] initWithBundle:bundle]; - - self.relaunchPath = relaunchPath; - self.terminationListener = [[TerminationListener alloc] initWithBundle:bundle]; - self.updateFolderPath = updateFolderPath; - self.downloadPath = downloadPath; - self.dsaSignature = dsaSignature; + _hostBundleIdentifier = [hostBundleIdentifier copy]; self.localPort = [[SULocalMessagePort alloc] - initWithServiceName:SUAutoUpdateServiceNameForHost(self.host) + initWithServiceName:SUAutoUpdateServiceNameForBundleIdentifier(hostBundleIdentifier) messageCallback:^NSData *(int32_t identifier, NSData * _Nonnull data) { return [self handleMessageWithIdentifier:identifier data:data]; } @@ -117,7 +107,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; [self cleanupAndExitWithStatus:EXIT_FAILURE]; } - if (![self resetRemotePort]) { + if (![self startRemotePort]) { SULog(@"Failed creating remote message port from installer"); [self cleanupAndExitWithStatus:EXIT_FAILURE]; } @@ -125,20 +115,20 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; return self; } -- (BOOL)resetRemotePort +- (BOOL)startRemotePort { - [self.remotePort invalidate]; - self.remotePort = nil; - - self.remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUUpdateDriverServiceNameForHost(self.host) invalidationCallback:^{ - dispatch_async(dispatch_get_main_queue(), ^{ - if (self.remotePort != nil && !self.willCompleteInstallation) { - SULog(@"Invalidation on remote port being called, and installation is not close enough to completion!"); - [self cleanupAndExitWithStatus:EXIT_FAILURE]; - } - }); - }]; - + if (self.remotePort == nil) { + self.remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUUpdateDriverServiceNameForBundleIdentifier(self.hostBundleIdentifier) invalidationCallback:^{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (self.remotePort != nil && !self.willCompleteInstallation) { + SULog(@"Invalidation on remote port being called, and installation is not close enough to completion!"); + [self cleanupAndExitWithStatus:EXIT_FAILURE]; + } + self.remotePort = nil; + }); + }]; + } + return (self.remotePort != nil); } @@ -227,13 +217,25 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; return YES; } +- (void)start +{ + [self.remotePort sendMessageWithIdentifier:SURequestInstallationParameters data:[NSData data] completion:^(BOOL success) { + if (!success) { + dispatch_async(dispatch_get_main_queue(), ^{ + SULog(@"Error: Failed to send request for installation parameters"); + [self cleanupAndExitWithStatus:EXIT_FAILURE]; + }); + } + }]; +} + - (void)extractAndInstallUpdate { #warning passing nothing for password atm - SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath withPassword:nil]; + SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.installationData.downloadPath updatingHostBundlePath:self.host.bundlePath withPassword:nil]; if (!unarchiver) { - SULog(@"Error: No valid unarchiver for %@!", self.downloadPath); + SULog(@"Error: No valid unarchiver for %@!", self.installationData.downloadPath); [self unarchiverDidFail:nil]; } else { unarchiver.delegate = self; @@ -253,6 +255,10 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; - (void)unarchiverDidFail:(SUUnarchiver *)__unused unarchiver { + // Client could try update again with different inputs + // Eg: one common case is if a delta update fails, client may want to fall back to regular update + self.installationData = nil; + [self.remotePort sendMessageWithIdentifier:SUArchiveExtractionFailed data:[NSData data] completion:^(BOOL success) { if (!success) { SULog(@"Error sending extraction failed"); @@ -268,7 +274,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; } }]; - BOOL validationSuccess = [self validateUpdateForHost:self.host downloadedToPath:self.downloadPath extractedToPath:self.updateFolderPath DSASignature:self.dsaSignature]; + BOOL validationSuccess = [self validateUpdateForHost:self.host downloadedToPath:self.installationData.downloadPath extractedToPath:self.installationData.updateDirectoryPath DSASignature:self.installationData.dsaSignature]; if (!validationSuccess) { SULog(@"Error: update validation was a failure"); @@ -288,7 +294,32 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; { NSData *replyData = nil; - if (identifier == SUSentUpdateAppcastItemData) { + if (identifier == SUInstallationData && self.installationData == nil) { + dispatch_async(dispatch_get_main_queue(), ^{ + SUInstallationInputData * _Nullable installationData = SUUnarchiveRootObjectSecurely(data, [SUInstallationInputData class]); + if (installationData == nil) { + SULog(@"Error: Failed to unarchive input installation data"); + [self cleanupAndExitWithStatus:EXIT_FAILURE]; + } else { + SUInstallationInputData *nonNullInstallationData = installationData; + 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); + [self cleanupAndExitWithStatus:EXIT_FAILURE]; + } else { + self.host = host; + self.installationData = installationData; + + self.terminationListener = [[TerminationListener alloc] initWithBundle:hostBundle]; + + [self extractAndInstallUpdate]; + } + } + }); + } else if (identifier == SUSentUpdateAppcastItemData) { self.updateItemData = data; } else if (identifier == SUReceiveUpdateAppcastItemData) { replyData = self.updateItemData; @@ -304,9 +335,9 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; self.shouldRelaunch = (BOOL)relaunch; #warning todo: handle this message even if we aren't ready for stage 2 yet. - // We should try re-creating the remote port, in case the client has + // We should try re-creating the remote port if necessary, in case the client has // restarted since and wants a reply back when we say it's OK to terminate the app - if (![self resetRemotePort]) { + if (![self startRemotePort]) { SULog(@"Installer failed to set up remote port to updater before resuming installation"); } @@ -326,7 +357,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; dispatch_async(self.installerQueue, ^{ NSError *installerError = nil; - id installer = [SUInstaller installerForHost:self.host updateDirectory:self.updateFolderPath versionComparator:[SUStandardVersionComparator defaultComparator] error:&installerError]; + id installer = [SUInstaller installerForHost:self.host updateDirectory:self.installationData.updateDirectoryPath versionComparator:[SUStandardVersionComparator defaultComparator] error:&installerError]; if (installer == nil) { SULog(@"Error: Failed to create installer instance with error: %@", installerError); @@ -453,10 +484,10 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; NSString *pathToRelaunch = nil; // If the installation path differs from the host path, we give higher precedence for it than // if the desired relaunch path differs from the host path - if (![installationPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents] || [self.relaunchPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents]) { + if (![installationPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents] || [self.installationData.relaunchPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents]) { pathToRelaunch = installationPath; } else { - pathToRelaunch = self.relaunchPath; + pathToRelaunch = self.installationData.relaunchPath; } [self relaunchAtPath:pathToRelaunch]; @@ -487,7 +518,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; self.remotePort = nil; NSError *theError = nil; - if (![[NSFileManager defaultManager] removeItemAtPath:self.updateFolderPath error:&theError]) { + if (![[NSFileManager defaultManager] removeItemAtPath:self.installationData.updateDirectoryPath error:&theError]) { SULog(@"Couldn't remove update folder: %@.", theError); } diff --git a/Sparkle/Autoupdate/Autoupdate.m b/Sparkle/Autoupdate/Autoupdate.m index 86fb6980..ccb5cd38 100644 --- a/Sparkle/Autoupdate/Autoupdate.m +++ b/Sparkle/Autoupdate/Autoupdate.m @@ -23,7 +23,7 @@ - (void)applicationDidFinishLaunching:(NSNotification __unused *)notification { - [self.appInstaller extractAndInstallUpdate]; + [self.appInstaller start]; } @end @@ -33,16 +33,11 @@ int main(int __unused argc, const char __unused *argv[]) @autoreleasepool { NSArray *args = [[NSProcessInfo processInfo] arguments]; - if (args.count != 7) { + if (args.count != 3) { return EXIT_FAILURE; } - NSString *relaunchPath = args[1]; - NSString *hostBundlePath = args[2]; - NSString *updateDirectoryPath = args[3]; - NSString *downloadPath = args[4]; - NSString *dsaSignature = args[5]; - BOOL shouldRelaunchTool = [args[6] boolValue]; + BOOL shouldRelaunchTool = [args[2] boolValue]; if (shouldRelaunchTool) { NSURL *mainBundleURL = [[NSBundle mainBundle] bundleURL]; @@ -73,13 +68,9 @@ int main(int __unused argc, const char __unused *argv[]) return EXIT_SUCCESS; } - AppInstaller *appInstaller = - [[AppInstaller alloc] - initWithHostPath:hostBundlePath - relaunchPath:relaunchPath - updateFolderPath:updateDirectoryPath - downloadPath:downloadPath - dsaSignature:dsaSignature]; + NSString *hostBundleIdentifier = args[1]; + + AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier]; AppDelegate *delegate = [[AppDelegate alloc] initWithAppInstaller:appInstaller]; diff --git a/Sparkle/Autoupdate/SUInstallationInputData.h b/Sparkle/Autoupdate/SUInstallationInputData.h new file mode 100644 index 00000000..88202e0d --- /dev/null +++ b/Sparkle/Autoupdate/SUInstallationInputData.h @@ -0,0 +1,25 @@ +// +// SUInstallationInputData.h +// Sparkle +// +// Created by Mayur Pawashe on 3/24/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SUInstallationInputData : NSObject + +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature; + +@property (nonatomic, copy, readonly) NSString *relaunchPath; +@property (nonatomic, copy, readonly) NSString *hostBundlePath; +@property (nonatomic, copy, readonly) NSString *updateDirectoryPath; +@property (nonatomic, copy, readonly) NSString *downloadPath; +@property (nonatomic, copy, readonly) NSString *dsaSignature; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/Autoupdate/SUInstallationInputData.m b/Sparkle/Autoupdate/SUInstallationInputData.m new file mode 100644 index 00000000..c4499adf --- /dev/null +++ b/Sparkle/Autoupdate/SUInstallationInputData.m @@ -0,0 +1,82 @@ +// +// SUInstallationInputData.m +// Sparkle +// +// Created by Mayur Pawashe on 3/24/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SUInstallationInputData.h" + +static NSString *SURelaunchPathKey = @"SURelaunchPath"; +static NSString *SUHostBundlePathKey = @"SUHostBundlePath"; +static NSString *SUUpdateDirectoryPathKey = @"SUUpdateDirectoryPath"; +static NSString *SUDownloadPathKey = @"SUDownloadPath"; +static NSString *SUDSASignatureKey = @"SUDSASignature"; + +@implementation SUInstallationInputData + +@synthesize relaunchPath = _relaunchPath; +@synthesize hostBundlePath = _hostBundlePath; +@synthesize updateDirectoryPath = _updateDirectoryPath; +@synthesize downloadPath = _downloadPath; +@synthesize dsaSignature = _dsaSignature; + +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature +{ + self = [super init]; + if (self != nil) { + _relaunchPath = [relaunchPath copy]; + _hostBundlePath = [hostBundlePath copy]; + _updateDirectoryPath = [updateDirectoryPath copy]; + _downloadPath = [downloadPath copy]; + _dsaSignature = [dsaSignature copy]; + } + return self; +} + +- (nullable instancetype)initWithCoder:(NSCoder *)decoder +{ + NSString *relaunchPath = [decoder decodeObjectOfClass:[NSString class] forKey:SURelaunchPathKey]; + if (relaunchPath == nil) { + return nil; + } + + NSString *hostBundlePath = [decoder decodeObjectOfClass:[NSString class] forKey:SUHostBundlePathKey]; + if (hostBundlePath == nil) { + return nil; + } + + NSString *updateDirectoryPath = [decoder decodeObjectOfClass:[NSString class] forKey:SUUpdateDirectoryPathKey]; + if (updateDirectoryPath == nil) { + return nil; + } + + NSString *downloadPath = [decoder decodeObjectOfClass:[NSString class] forKey:SUDownloadPathKey]; + if (downloadPath == nil) { + return nil; + } + + NSString *dsaSignature = [decoder decodeObjectOfClass:[NSString class] forKey:SUDSASignatureKey]; + if (dsaSignature == nil) { + return nil; + } + + return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadPath:downloadPath dsaSignature:dsaSignature]; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:self.relaunchPath forKey:SURelaunchPathKey]; + [coder encodeObject:self.hostBundlePath forKey:SUHostBundlePathKey]; + [coder encodeObject:self.updateDirectoryPath forKey:SUUpdateDirectoryPathKey]; + [coder encodeObject:self.downloadPath forKey:SUDownloadPathKey]; + [coder encodeObject:self.dsaSignature forKey:SUDSASignatureKey]; +} + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +@end diff --git a/Sparkle/Autoupdate/SUMessageTypes.h b/Sparkle/Autoupdate/SUMessageTypes.h index 177f4cf3..6df6f45a 100644 --- a/Sparkle/Autoupdate/SUMessageTypes.h +++ b/Sparkle/Autoupdate/SUMessageTypes.h @@ -18,19 +18,21 @@ extern NSString *SUAppcastItemArchiveKey; typedef NS_ENUM(int32_t, SUInstallerMessageType) { SUInstallerNotStarted = 0, - SUExtractedArchiveWithProgress = 1, - SUArchiveExtractionFailed = 2, - SUValidationStarted = 3, - SUInstallationStartedStage1 = 4, - SUInstallationFinishedStage1 = 5, - SUInstallationFinishedStage2 = 6 + SURequestInstallationParameters = 1, + SUExtractedArchiveWithProgress = 2, + SUArchiveExtractionFailed = 3, + SUValidationStarted = 4, + SUInstallationStartedStage1 = 5, + SUInstallationFinishedStage1 = 6, + SUInstallationFinishedStage2 = 7 }; typedef NS_ENUM(int32_t, SUUpdaterMessageType) { - SUSentUpdateAppcastItemData = 0, - SUReceiveUpdateAppcastItemData = 1, - SUResumeInstallationToStage2 = 2 + SUInstallationData = 0, + SUSentUpdateAppcastItemData = 1, + SUReceiveUpdateAppcastItemData = 2, + SUResumeInstallationToStage2 = 3 }; typedef NS_ENUM(int32_t, SUInstallStatusMessageType) @@ -41,8 +43,8 @@ typedef NS_ENUM(int32_t, SUInstallStatusMessageType) BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInstallerMessageType newMessageType); -NSString *SUUpdateDriverServiceNameForHost(SUHost *host); +NSString *SUUpdateDriverServiceNameForBundleIdentifier(NSString *bundleIdentifier); -NSString *SUAutoUpdateServiceNameForHost(SUHost *host); +NSString *SUAutoUpdateServiceNameForBundleIdentifier(NSString *bundleIdentifier); NS_ASSUME_NONNULL_END diff --git a/Sparkle/Autoupdate/SUMessageTypes.m b/Sparkle/Autoupdate/SUMessageTypes.m index e85c692d..0fcd39da 100644 --- a/Sparkle/Autoupdate/SUMessageTypes.m +++ b/Sparkle/Autoupdate/SUMessageTypes.m @@ -18,12 +18,15 @@ BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInst case SUInstallerNotStarted: legal = (oldMessageType == SUInstallerNotStarted); break; + case SURequestInstallationParameters: + legal = (oldMessageType == SUInstallerNotStarted); + break; case SUExtractedArchiveWithProgress: case SUArchiveExtractionFailed: - legal = (oldMessageType == SUInstallerNotStarted || oldMessageType == SUExtractedArchiveWithProgress); + legal = (oldMessageType == SURequestInstallationParameters || oldMessageType == SUExtractedArchiveWithProgress); break; case SUValidationStarted: - legal = (oldMessageType == SUInstallerNotStarted || oldMessageType == SUExtractedArchiveWithProgress); + legal = (oldMessageType == SURequestInstallationParameters || oldMessageType == SUExtractedArchiveWithProgress); break; case SUInstallationStartedStage1: legal = (oldMessageType == SUValidationStarted); @@ -38,12 +41,12 @@ BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInst return legal; } -NSString *SUUpdateDriverServiceNameForHost(SUHost *host) +NSString *SUUpdateDriverServiceNameForBundleIdentifier(NSString *bundleIdentifier) { - return [NSString stringWithFormat:@"%@-sparkle-updater", host.bundle.bundleIdentifier]; + return [NSString stringWithFormat:@"%@-sparkle-updater", bundleIdentifier]; } -NSString *SUAutoUpdateServiceNameForHost(SUHost *host) +NSString *SUAutoUpdateServiceNameForBundleIdentifier(NSString *bundleIdentifier) { - return [NSString stringWithFormat:@"%@-sparkle-installer", host.bundle.bundleIdentifier]; + return [NSString stringWithFormat:@"%@-sparkle-installer", bundleIdentifier]; } diff --git a/Sparkle/SUCoreBasedUpdateDriver.m b/Sparkle/SUCoreBasedUpdateDriver.m index 1063f7de..c62df9e2 100644 --- a/Sparkle/SUCoreBasedUpdateDriver.m +++ b/Sparkle/SUCoreBasedUpdateDriver.m @@ -192,6 +192,9 @@ { SUAppcastItem *nonDeltaUpdateItem = self.basicDriver.nonDeltaUpdateItem; assert(nonDeltaUpdateItem != nil); + + self.updateItem = nonDeltaUpdateItem; + [self downloadUpdateFromAppcastItem:nonDeltaUpdateItem]; } diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index 35a57695..556019e3 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -18,6 +18,8 @@ #import "SUErrors.h" #import "SUHost.h" #import "SUFileManager.h" +#import "SUSecureCoding.h" +#import "SUInstallationInputData.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -75,9 +77,12 @@ return YES; } + NSString *hostBundleIdentifier = self.host.bundle.bundleIdentifier; + assert(hostBundleIdentifier != nil); + self.localPort = [[SULocalMessagePort alloc] - initWithServiceName:SUUpdateDriverServiceNameForHost(self.host) + initWithServiceName:SUUpdateDriverServiceNameForBundleIdentifier(hostBundleIdentifier) messageCallback:^NSData *(int32_t identifier, NSData * _Nonnull data) { dispatch_async(dispatch_get_main_queue(), ^{ [self handleMessageWithIdentifier:identifier data:data]; @@ -125,7 +130,10 @@ return YES; } - self.remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForHost(self.host) invalidationCallback:^{ + NSString *hostBundleIdentifier = self.host.bundle.bundleIdentifier; + assert(hostBundleIdentifier != nil); + + self.remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForBundleIdentifier(hostBundleIdentifier) invalidationCallback:^{ dispatch_async(dispatch_get_main_queue(), ^{ if (self.remotePort != nil) { NSError *remoteError = @@ -189,11 +197,43 @@ if (self.localPort == nil) { return [self launchInstallTool:error]; + } else { + // The Install tool is already alive; just send out installation input data again + [self sendInstallationData]; } return YES; } +- (void)sendInstallationData +{ + NSString *pathToRelaunch = [self.host bundlePath]; + if ([self.updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { + pathToRelaunch = [self.updaterDelegate pathToRelaunchForUpdater:self.updater]; + } + + NSString *dsaSignature = (self.updateItem.DSASignature == nil) ? @"" : self.updateItem.DSASignature; + + SUInstallationInputData *installationData = [[SUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadPath:self.downloadPath dsaSignature:dsaSignature]; + + NSData *archivedData = SUArchiveRootObjectSecurely(installationData); + + NSError *remoteError = nil; + if (![self setUpRemotePort:&remoteError]) { + [self.delegate installerIsRequestingAbortInstallWithError:remoteError]; + } else { + [self.remotePort sendMessageWithIdentifier:SUInstallationData data:archivedData completion:^(BOOL success) { + if (!success) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate installerIsRequestingAbortInstallWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while starting the installer parameters. Please try again later.", nil) }]]; + }); + } + }]; + + self.currentStage = SURequestInstallationParameters; + } +} + - (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data { if (!SUInstallerMessageTypeIsLegal(self.currentStage, identifier)) { @@ -201,7 +241,9 @@ return; } - if (identifier == SUExtractedArchiveWithProgress) { + if (identifier == SURequestInstallationParameters) { + [self sendInstallationData]; + } else if (identifier == SUExtractedArchiveWithProgress) { if (data.length == sizeof(double)) { double progress = *(const double *)data.bytes; [self.delegate installerDidExtractUpdateWithProgress:progress]; @@ -222,32 +264,23 @@ [self.delegate installerDidStartInstalling]; } else if (identifier == SUInstallationFinishedStage1) { - NSError *remoteError = nil; - if (![self setUpRemotePort:&remoteError]) { - [self.delegate installerIsRequestingAbortInstallWithError:remoteError]; + self.currentStage = identifier; + + // Let the installer keep a copy of the appcast item data + // We may want to ask for it later (note the updater can relaunch without the app necessarily having relaunched) + NSData *updateItemData = SUArchiveRootObjectSecurely(self.updateItem); + + if (updateItemData != nil) { + [self.remotePort sendMessageWithIdentifier:SUSentUpdateAppcastItemData data:updateItemData completion:^(BOOL success) { + if (!success) { + SULog(@"Error: Failed to send update appcast item to installer"); + } + }]; } else { - self.currentStage = identifier; - - // Let the installer keep a copy of the appcast item data - // We may want to ask for it later (note the updater can relaunch without the app necessarily having relaunched) - NSMutableData *updateItemData = [NSMutableData data]; - NSKeyedArchiver *keyedArchiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:updateItemData]; - keyedArchiver.requiresSecureCoding = YES; - [keyedArchiver encodeObject:self.updateItem forKey:SUAppcastItemArchiveKey]; - [keyedArchiver finishEncoding]; - - if (updateItemData != nil) { - [self.remotePort sendMessageWithIdentifier:SUSentUpdateAppcastItemData data:updateItemData completion:^(BOOL success) { - if (!success) { - SULog(@"Error: Failed to send update appcast item to installer"); - } - }]; - } else { - SULog(@"Error: Archived data to send for appcast item is nil"); - } - - [self.delegate installerDidFinishRelaunchPreparation]; + SULog(@"Error: Archived data to send for appcast item is nil"); } + + [self.delegate installerDidFinishRelaunchPreparation]; } else if (identifier == SUInstallationFinishedStage2) { // Don't have to store current stage because we're severing our connection to the installer @@ -351,21 +384,14 @@ return NO; } - NSString *pathToRelaunch = [self.host bundlePath]; - if ([self.updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { - pathToRelaunch = [self.updaterDelegate pathToRelaunchForUpdater:self.updater]; + NSString *hostBundleIdentifier = self.host.bundle.bundleIdentifier; + if (hostBundleIdentifier == nil) { + if (outError != NULL) { + *outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while finding the application's bundle identifier. Please try again later.", nil) }]; + } + return NO; } - NSString *dsaSignature = (self.updateItem.DSASignature == nil) ? @"" : self.updateItem.DSASignature; - - NSArray *launchArguments = @[ - pathToRelaunch, - self.host.bundlePath, - self.temporaryDirectory, - self.downloadPath, - dsaSignature, - @"1"]; // last one signifies the relaunch tool should exit & reply back to us immediately - // Make sure the launched task finishes & replies back. // If it succeeds, it will have launched a second instance of the tool through LaunchServices // This is necessary if we are a XPC process, because otherwise we risk exiting prematurely @@ -373,7 +399,7 @@ int terminationStatus = 0; BOOL taskDidLaunch = NO; @try { - NSTask *launchedTask = [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:launchArguments]; + NSTask *launchedTask = [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[hostBundleIdentifier, @"1"]]; [launchedTask waitUntilExit]; taskDidLaunch = YES; terminationStatus = launchedTask.terminationStatus; diff --git a/Sparkle/SUProbeInstallStatus.m b/Sparkle/SUProbeInstallStatus.m index 97afe8dd..3a1270b3 100644 --- a/Sparkle/SUProbeInstallStatus.m +++ b/Sparkle/SUProbeInstallStatus.m @@ -12,19 +12,26 @@ #import "SUHost.h" #import "SUMessageTypes.h" #import "SUAppcastItem.h" +#import "SUSecureCoding.h" @implementation SUProbeInstallStatus + (BOOL)probeInstallerInProgressForHost:(SUHost *)host { - SURemoteMessagePort *remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForHost(host) invalidationCallback:^{}]; + NSString *hostBundleIdentifier = host.bundle.bundleIdentifier; + assert(hostBundleIdentifier != nil); + + SURemoteMessagePort *remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForBundleIdentifier(hostBundleIdentifier) invalidationCallback:^{}]; [remotePort invalidate]; return (remotePort != nil); } + (void)probeInstallerUpdateItemForHost:(SUHost *)host completion:(void (^)(SUAppcastItem * _Nullable))completionHandler { - SURemoteMessagePort *remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForHost(host) invalidationCallback:^{}]; + NSString *hostBundleIdentifier = host.bundle.bundleIdentifier; + assert(hostBundleIdentifier != nil); + + SURemoteMessagePort *remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForBundleIdentifier(hostBundleIdentifier) invalidationCallback:^{}]; if (remotePort == nil) { completionHandler(nil); return; @@ -35,12 +42,7 @@ completionHandler(nil); } else { NSData *nonNullReplyData = replyData; - - // This boilerplate is the only way I've found to decode a class securely - NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:nonNullReplyData]; - unarchiver.requiresSecureCoding = YES; - SUAppcastItem *updateItem = [unarchiver decodeObjectOfClass:[SUAppcastItem class] forKey:SUAppcastItemArchiveKey]; - [unarchiver finishDecoding]; + SUAppcastItem * _Nullable updateItem = SUUnarchiveRootObjectSecurely(nonNullReplyData, [SUAppcastItem class]); if (updateItem != nil) { completionHandler(updateItem); diff --git a/Sparkle/SUSecureCoding.h b/Sparkle/SUSecureCoding.h new file mode 100644 index 00000000..41548aba --- /dev/null +++ b/Sparkle/SUSecureCoding.h @@ -0,0 +1,17 @@ +// +// SUSecureCoding.h +// Sparkle +// +// Created by Mayur Pawashe on 3/24/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +NSData *SUArchiveRootObjectSecurely(id rootObject); + +id _Nullable SUUnarchiveRootObjectSecurely(NSData *data, Class klass); + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUSecureCoding.m b/Sparkle/SUSecureCoding.m new file mode 100644 index 00000000..865fed72 --- /dev/null +++ b/Sparkle/SUSecureCoding.m @@ -0,0 +1,34 @@ +// +// SUSecureCoding.m +// Sparkle +// +// Created by Mayur Pawashe on 3/24/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SUSecureCoding.h" + +static NSString *SURootObjectArchiveKey = @"SURootObjectArchive"; + +NSData *SUArchiveRootObjectSecurely(id rootObject) +{ + NSMutableData *data = [NSMutableData data]; + NSKeyedArchiver *keyedArchiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; + keyedArchiver.requiresSecureCoding = YES; + + [keyedArchiver encodeObject:rootObject forKey:SURootObjectArchiveKey]; + [keyedArchiver finishEncoding]; + + return [data copy]; +} + +id _Nullable SUUnarchiveRootObjectSecurely(NSData *data, Class klass) +{ + NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; + unarchiver.requiresSecureCoding = YES; + + id rootObject = [unarchiver decodeObjectOfClass:klass forKey:SURootObjectArchiveKey]; + [unarchiver finishDecoding]; + + return rootObject; +}