mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-29 05:24:26 +00:00
Thanks to Mattt Thompson (@mattt) for tag-team-ing this with me. With this change, if your app deploys only to 10.6+, then you can dispense altogether with the DSA signatures on future updates to your application: just make sure the "to" version satisfies the "from" version's Apple code signing requirements. Most of you are probably already doing that, and if you're not, you should be anyway. Specifically, Sparkle validates the designated requirement of the "from" version against the "to" version. By default, as of this writing, that means that the bundle identifiers must be the same, and that the leaf certificate of the signature is the same. So if you keep code signing your app with the same cert, Sparkle will Just Work without any additional DSA signature nonsense for you to deal with. Traditional Sparkle DSA signatures will still be honored. This support has only been extended to updates to the main app bundle. If you're updating some other bundle, you will have to use DSA signatures to secure your updates in the future. ***IMPORTANT: previously, Sparkle considered an update "safe" if both the appcast and update were distributed over https. That is nowhere near as strong a verification measure as code signing or the old-school DSA signatures, so with this change, support for unsigned, https-distributed updates has been removed. If you're targeting 10.6+, start code-signing your apps if you haven't already, and everything will be fine. If you're targeting earlier OS Xs, you'll need to start adding DSA signatures to your appcasts. When you link this changed version of Sparkle into your app, it will warn you on launch if you are not code signed and do not have a DSA public key specified in your Info.plist.
183 lines
5.8 KiB
Objective-C
183 lines
5.8 KiB
Objective-C
//
|
|
// SUInstaller.m
|
|
// Sparkle
|
|
//
|
|
// Created by Andy Matuschak on 4/10/08.
|
|
// Copyright 2008 Andy Matuschak. All rights reserved.
|
|
//
|
|
|
|
#import "SUInstaller.h"
|
|
#import "SUPlainInstaller.h"
|
|
#import "SUPackageInstaller.h"
|
|
#import "SUHost.h"
|
|
#import "SUConstants.h"
|
|
#import "SULog.h"
|
|
|
|
|
|
@implementation SUInstaller
|
|
|
|
static NSString* sUpdateFolder = nil;
|
|
|
|
+(NSString*) updateFolder
|
|
{
|
|
return sUpdateFolder;
|
|
}
|
|
|
|
+ (BOOL)isAliasFolderAtPath:(NSString *)path
|
|
{
|
|
FSRef fileRef;
|
|
OSStatus err = noErr;
|
|
Boolean aliasFileFlag, folderFlag;
|
|
NSURL *fileURL = [NSURL fileURLWithPath:path];
|
|
|
|
if (FALSE == CFURLGetFSRef((CFURLRef)fileURL, &fileRef))
|
|
err = coreFoundationUnknownErr;
|
|
|
|
if (noErr == err)
|
|
err = FSIsAliasFile(&fileRef, &aliasFileFlag, &folderFlag);
|
|
|
|
if (noErr == err)
|
|
return (BOOL)(aliasFileFlag && folderFlag);
|
|
else
|
|
return NO;
|
|
}
|
|
|
|
+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr
|
|
{
|
|
// Search subdirectories for the application
|
|
NSString *currentFile,
|
|
*newAppDownloadPath = nil,
|
|
*bundleFileName = [[host bundlePath] lastPathComponent],
|
|
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
|
BOOL isPackage = NO;
|
|
NSString *fallbackPackagePath = nil;
|
|
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath: inUpdateFolder];
|
|
|
|
[sUpdateFolder release];
|
|
sUpdateFolder = [inUpdateFolder retain];
|
|
|
|
while ((currentFile = [dirEnum nextObject]))
|
|
{
|
|
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
|
if ([[currentFile lastPathComponent] isEqualToString:bundleFileName] ||
|
|
[[currentFile lastPathComponent] isEqualToString:alternateBundleFileName]) // We found one!
|
|
{
|
|
isPackage = NO;
|
|
newAppDownloadPath = currentPath;
|
|
break;
|
|
}
|
|
else if ([[currentFile pathExtension] isEqualToString:@"pkg"] ||
|
|
[[currentFile pathExtension] isEqualToString:@"mpkg"])
|
|
{
|
|
if ([[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]])
|
|
{
|
|
isPackage = YES;
|
|
newAppDownloadPath = currentPath;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
// Remember any other non-matching packages we have seen should we need to use one of them as a fallback.
|
|
fallbackPackagePath = currentPath;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Try matching on bundle identifiers in case the user has changed the name of the host app
|
|
NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath];
|
|
if(incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]])
|
|
{
|
|
isPackage = NO;
|
|
newAppDownloadPath = currentPath;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Some DMGs have symlinks into /Applications! That's no good!
|
|
if ([self isAliasFolderAtPath:currentPath])
|
|
[dirEnum skipDescendents];
|
|
}
|
|
|
|
// We don't have a valid path. Try to use the fallback package.
|
|
|
|
if (newAppDownloadPath == nil && fallbackPackagePath != nil)
|
|
{
|
|
isPackage = YES;
|
|
newAppDownloadPath = fallbackPackagePath;
|
|
}
|
|
|
|
if (isPackagePtr) *isPackagePtr = isPackage;
|
|
return newAppDownloadPath;
|
|
}
|
|
|
|
+ (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host
|
|
{
|
|
BOOL isPackage = NO;
|
|
NSString *path = [self installSourcePathInUpdateFolder:updateFolder forHost:host isPackage:&isPackage];
|
|
return isPackage ? nil : path;
|
|
}
|
|
|
|
+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
|
|
{
|
|
BOOL isPackage = NO;
|
|
NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage];
|
|
|
|
if (newAppDownloadPath == nil)
|
|
{
|
|
[self finishInstallationWithResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate];
|
|
}
|
|
else
|
|
{
|
|
[(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationWithPath:newAppDownloadPath host:host delegate:delegate synchronously:synchronously versionComparator:comparator];
|
|
}
|
|
}
|
|
|
|
+ (void)mdimportHost:(SUHost *)host
|
|
{
|
|
// *** GETS CALLED ON NON-MAIN THREAD!
|
|
|
|
SULog( @"mdimporting" );
|
|
|
|
NSTask *mdimport = [[[NSTask alloc] init] autorelease];
|
|
[mdimport setLaunchPath:@"/usr/bin/mdimport"];
|
|
[mdimport setArguments:[NSArray arrayWithObject:[host installationPath]]];
|
|
@try
|
|
{
|
|
[mdimport launch];
|
|
[mdimport waitUntilExit];
|
|
}
|
|
@catch (NSException * launchException)
|
|
{
|
|
// No big deal.
|
|
SULog(@"Sparkle Error: %@", [launchException description]);
|
|
}
|
|
}
|
|
|
|
|
|
#define SUNotifyDictHostKey @"SUNotifyDictHost"
|
|
#define SUNotifyDictErrorKey @"SUNotifyDictError"
|
|
#define SUNotifyDictDelegateKey @"SUNotifyDictDelegate"
|
|
|
|
+ (void)finishInstallationWithResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate
|
|
{
|
|
if (result)
|
|
{
|
|
[self mdimportHost:host];
|
|
if ([delegate respondsToSelector:@selector(installerFinishedForHost:)])
|
|
[delegate performSelectorOnMainThread: @selector(installerFinishedForHost:) withObject: host waitUntilDone: NO];
|
|
}
|
|
else
|
|
{
|
|
if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)])
|
|
[self performSelectorOnMainThread: @selector(notifyDelegateOfFailure:) withObject: [NSDictionary dictionaryWithObjectsAndKeys: host, SUNotifyDictHostKey, error, SUNotifyDictErrorKey, delegate, SUNotifyDictDelegateKey, nil] waitUntilDone: NO];
|
|
}
|
|
}
|
|
|
|
|
|
+(void) notifyDelegateOfFailure: (NSDictionary*)dict
|
|
{
|
|
[[dict objectForKey: SUNotifyDictDelegateKey] installerForHost: [dict objectForKey: SUNotifyDictHostKey] failedWithError: [dict objectForKey: SUNotifyDictErrorKey]];
|
|
}
|
|
|
|
@end
|