mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
This patch prevents malicious downgrades, which are still possible with DSA validation: suppose there's some (signed) version with a security hole. A malicious attacker could serve an appcast with that version's URL and DSA signature, but a higher version number, forcing the user to "upgrade" to the version with the security hole. While I was at it, I fixed a bug that should have completely stopped .pkg installation from working since 1.5b1. Why didn't I hear anything about that? Does anyone actually use .pkgs? It still needs testing to be sure it works.
56 lines
2.4 KiB
Objective-C
56 lines
2.4 KiB
Objective-C
//
|
|
// SUPlainInstaller.m
|
|
// Sparkle
|
|
//
|
|
// Created by Andy Matuschak on 4/10/08.
|
|
// Copyright 2008 Andy Matuschak. All rights reserved.
|
|
//
|
|
|
|
#import "SUPlainInstaller.h"
|
|
#import "SUPlainInstallerInternals.h"
|
|
|
|
NSString *SUInstallerPathKey = @"SUInstallerPath";
|
|
NSString *SUInstallerHostKey = @"SUInstallerHost";
|
|
NSString *SUInstallerDelegateKey = @"SUInstallerDelegate";
|
|
NSString *SUInstallerVersionComparatorKey = @"SUInstallerVersionComparator";
|
|
|
|
@implementation SUPlainInstaller
|
|
|
|
+ (void)installPath:(NSString *)path overHost:(SUHost *)bundle delegate:delegate versionComparator:(id <SUVersionComparison>)comparator
|
|
{
|
|
NSError *error;
|
|
BOOL result = YES;
|
|
|
|
// Prevent malicious downgrades:
|
|
if ([comparator compareVersion:[bundle version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]] == NSOrderedDescending)
|
|
{
|
|
NSString * errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [bundle version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
|
result = NO;
|
|
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
|
}
|
|
|
|
if (result)
|
|
result = [self copyPathWithAuthentication:path overPath:[bundle bundlePath] error:&error];
|
|
[self _finishInstallationWithResult:result host:bundle error:error delegate:delegate];
|
|
}
|
|
|
|
+ (void)_performInstallationWithInfo:(NSDictionary *)info
|
|
{
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
[self installPath:[info objectForKey:SUInstallerPathKey] overHost:[info objectForKey:SUInstallerHostKey] delegate:[info objectForKey:SUInstallerDelegateKey] versionComparator:[info objectForKey:SUInstallerVersionComparatorKey]];
|
|
|
|
[pool drain];
|
|
}
|
|
|
|
+ (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
|
|
{
|
|
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, host, SUInstallerHostKey, delegate, SUInstallerDelegateKey, comparator, SUInstallerVersionComparatorKey, nil];
|
|
if (synchronously)
|
|
[self _performInstallationWithInfo:info];
|
|
else
|
|
[NSThread detachNewThreadSelector:@selector(_performInstallationWithInfo:) toTarget:self withObject:info];
|
|
}
|
|
|
|
@end
|