diff --git a/Sparkle/Autoupdate/AppInstaller.m b/Sparkle/Autoupdate/AppInstaller.m index 4cecac78..c4fcb248 100644 --- a/Sparkle/Autoupdate/AppInstaller.m +++ b/Sparkle/Autoupdate/AppInstaller.m @@ -232,8 +232,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; - (void)extractAndInstallUpdate { -#warning passing nothing for password atm - id unarchiver = [SUUnarchiver unarchiverForPath:self.installationData.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:nil delegate:self]; + id unarchiver = [SUUnarchiver unarchiverForPath:self.installationData.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.installationData.decryptionPassword delegate:self]; if (!unarchiver) { SULog(@"Error: No valid unarchiver for %@!", self.installationData.downloadPath); [self unarchiverDidFail]; diff --git a/Sparkle/Autoupdate/SUInstallationInputData.h b/Sparkle/Autoupdate/SUInstallationInputData.h index 88202e0d..c7bd4ae3 100644 --- a/Sparkle/Autoupdate/SUInstallationInputData.h +++ b/Sparkle/Autoupdate/SUInstallationInputData.h @@ -12,13 +12,14 @@ NS_ASSUME_NONNULL_BEGIN @interface SUInstallationInputData : NSObject -- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature; +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath 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 *downloadPath; @property (nonatomic, copy, readonly) NSString *dsaSignature; +@property (nonatomic, copy, readonly, nullable) NSString *decryptionPassword; @end diff --git a/Sparkle/Autoupdate/SUInstallationInputData.m b/Sparkle/Autoupdate/SUInstallationInputData.m index c4499adf..5c09a16f 100644 --- a/Sparkle/Autoupdate/SUInstallationInputData.m +++ b/Sparkle/Autoupdate/SUInstallationInputData.m @@ -13,6 +13,7 @@ static NSString *SUHostBundlePathKey = @"SUHostBundlePath"; static NSString *SUUpdateDirectoryPathKey = @"SUUpdateDirectoryPath"; static NSString *SUDownloadPathKey = @"SUDownloadPath"; static NSString *SUDSASignatureKey = @"SUDSASignature"; +static NSString *SUDecryptionPasswordKey = @"SUDecryptionPassword"; @implementation SUInstallationInputData @@ -21,8 +22,9 @@ static NSString *SUDSASignatureKey = @"SUDSASignature"; @synthesize updateDirectoryPath = _updateDirectoryPath; @synthesize downloadPath = _downloadPath; @synthesize dsaSignature = _dsaSignature; +@synthesize decryptionPassword = _decryptionPassword; -- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature +- (instancetype)initWithRelaunchPath:(NSString *)relaunchPath hostBundlePath:(NSString *)hostBundlePath updateDirectoryPath:(NSString *)updateDirectoryPath downloadPath:(NSString *)downloadPath dsaSignature:(NSString *)dsaSignature decryptionPassword:(nullable NSString *)decryptionPassword { self = [super init]; if (self != nil) { @@ -31,6 +33,7 @@ static NSString *SUDSASignatureKey = @"SUDSASignature"; _updateDirectoryPath = [updateDirectoryPath copy]; _downloadPath = [downloadPath copy]; _dsaSignature = [dsaSignature copy]; + _decryptionPassword = [decryptionPassword copy]; } return self; } @@ -62,7 +65,9 @@ static NSString *SUDSASignatureKey = @"SUDSASignature"; return nil; } - return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadPath:downloadPath dsaSignature:dsaSignature]; + NSString *decryptionPassword = [decoder decodeObjectOfClass:[NSString class] forKey:SUDecryptionPasswordKey]; + + return [self initWithRelaunchPath:relaunchPath hostBundlePath:hostBundlePath updateDirectoryPath:updateDirectoryPath downloadPath:downloadPath dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; } - (void)encodeWithCoder:(NSCoder *)coder @@ -72,6 +77,9 @@ static NSString *SUDSASignatureKey = @"SUDSASignature"; [coder encodeObject:self.updateDirectoryPath forKey:SUUpdateDirectoryPathKey]; [coder encodeObject:self.downloadPath forKey:SUDownloadPathKey]; [coder encodeObject:self.dsaSignature forKey:SUDSASignatureKey]; + if (self.decryptionPassword != nil) { + [coder encodeObject:self.decryptionPassword forKey:SUDecryptionPasswordKey]; + } } + (BOOL)supportsSecureCoding diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index f07cc8a5..0302db57 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -217,7 +217,12 @@ 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]; + NSString *decryptionPassword = nil; + if ([self.updaterDelegate respondsToSelector:@selector(decryptionPasswordForUpdater:)]) { + decryptionPassword = [self.updaterDelegate decryptionPasswordForUpdater:self.updater]; + } + + SUInstallationInputData *installationData = [[SUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadPath:self.downloadPath dsaSignature:dsaSignature decryptionPassword:decryptionPassword]; NSData *archivedData = SUArchiveRootObjectSecurely(installationData); diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 43d26bcf..d09c672e 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -70,8 +70,6 @@ SU_EXPORT @interface SUUpdater : NSObject @property BOOL automaticallyDownloadsUpdates; -@property (nonatomic, copy) NSString *decryptionPassword; - /*! Checks for updates, and displays progress while doing so diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index a0b1f959..412a1136 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -53,7 +53,6 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize driver; @synthesize host; @synthesize sparkleBundle; -@synthesize decryptionPassword; - (instancetype)initWithHostBundle:(NSBundle *)bundle userDriver:(id )userDriver delegate:(id )theDelegate { diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 8bb918f1..b4e30877 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -206,6 +206,15 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater; +/*! + Returns the decryption password (if any) which is used to extract the update archive DMG. + + Return nil if no password should be used. + + \param updater The SUUpdater instance. + */ +- (NSString *)decryptionPasswordForUpdater:(SUUpdater *)updater; + /*! Called before an updater shows a modal alert window, to give the host the opportunity to hide attached windows that may get in the way.