diff --git a/NTSynchronousTask.h b/NTSynchronousTask.h index e8510731..be74ce38 100644 --- a/NTSynchronousTask.h +++ b/NTSynchronousTask.h @@ -25,6 +25,12 @@ // returns the result +(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData; ++(NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input; + +- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input; +- (int)result; +- (NSData *)output; + @end #endif diff --git a/NTSynchronousTask.m b/NTSynchronousTask.m index d564d243..1d2e3ef0 100644 --- a/NTSynchronousTask.m +++ b/NTSynchronousTask.m @@ -128,6 +128,7 @@ [[self task] setStandardInput:[self inputPipe]]; [[self task] setStandardOutput:[self outputPipe]]; + [[self task] setStandardError:[self outputPipe]]; } return self; diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index a905ee6b..c8425aef 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -12,7 +12,6 @@ #import "SULog.h" #import - @implementation SUDiskImageUnarchiver + (BOOL)canUnarchivePath:(NSString *)path @@ -20,11 +19,28 @@ return [[path pathExtension] isEqualToString:@"dmg"]; } +// Called on a non-main thread. - (void)extractDMG -{ - // GETS CALLED ON NON-MAIN THREAD!!! +{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSData *result = [NTSynchronousTask task:@"/usr/bin/hdiutil" directory:@"/" withArgs:[NSArray arrayWithObjects: @"isencrypted", archivePath, nil] input:NULL]; + if([self isEncrypted:result] && [delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)]) { + [self performSelectorOnMainThread:@selector(requestPasswordFromDelegate) withObject:nil waitUntilDone:NO]; + } else { + [self extractDMGWithPassword:nil]; + } + + [pool release]; +} + +// Called on a non-main thread. +- (void)extractDMGWithPassword:(NSString *)password +{ + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + BOOL mountedSuccessfully = NO; SULog(@"Extracting %@ as a DMG", archivePath); @@ -48,19 +64,46 @@ } } while (noErr == FSPathMakeRefWithOptions((UInt8 *)[mountPoint fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &tmpRef, NULL)); + + NSData *promptData = nil; + if (password) { + NSString *data = [NSString stringWithFormat:@"%@\nyes\n", password]; + const char *bytes = [data cStringUsingEncoding:NSUTF8StringEncoding]; + NSUInteger length = [data lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + promptData = [NSData dataWithBytes:bytes length:length]; + } + else + promptData = [NSData dataWithBytes:"yes\n" length:4]; - NSArray* arguments = [NSArray arrayWithObjects:@"attach", archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen", nil]; - // set up a pipe and push "yes" (y works too), this will accept any license agreement crap - // not every .dmg needs this, but this will make sure it works with everyone - NSData* yesData = [[[NSData alloc] initWithBytes:"yes\n" length:4] autorelease]; + NSArray* arguments = [NSArray arrayWithObjects:@"attach", archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen", nil]; + + NSData *output = nil; + NSInteger taskResult = -1; + @try + { + NTSynchronousTask* task = [[NTSynchronousTask alloc] init]; + + [task run:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:promptData]; + + taskResult = [task result]; + output = [[[task output] copy] autorelease]; + [task release]; + } + @catch (NSException *localException) + { + goto reportError; + } - NSData *output = nil; - int returnCode = [NTSynchronousTask task:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:yesData output: &output]; - if ( returnCode != 0 ) + if (taskResult != 0) { NSString* resultStr = output ? [[[NSString alloc] initWithData: output encoding: NSUTF8StringEncoding] autorelease] : nil; - SULog( @"hdiutil failed with code: %d data: <<%@>>", returnCode, resultStr ); - goto reportError; + if (password != nil && [resultStr rangeOfString:@"Authentication error"].location != NSNotFound && [delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)]) { + [self performSelectorOnMainThread:@selector(requestPasswordFromDelegate) withObject:nil waitUntilDone:NO]; + goto finally; + } else { + SULog( @"hdiutil failed with code: %d data: <<%@>>", taskResult, resultStr ); + goto reportError; + } } mountedSuccessfully = YES; @@ -132,4 +175,32 @@ finally: [self registerImplementation:self]; } +- (BOOL)isEncrypted:(NSData*)resultData +{ + BOOL result = NO; + if(resultData) + { + NSString *data = [NSString stringWithCString:(char*)[resultData bytes] encoding:NSUTF8StringEncoding]; + if (!NSEqualRanges([data rangeOfString:@"passphrase-count"], NSMakeRange(NSNotFound, 0))) + { + result = YES; + } + } + return result; +} + +- (void)requestPasswordFromDelegate +{ + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(continueWithPassword:)]]; + [invocation setSelector:@selector(continueWithPassword:)]; + [invocation setTarget:self]; + [invocation retainArguments]; + [delegate unarchiver:self requiresPasswordReturnedViaInvocation:invocation]; +} + +- (void)continueWithPassword:(NSString *)password +{ + [NSThread detachNewThreadSelector:@selector(extractDMGWithPassword:) toTarget:self withObject:password]; +} + @end diff --git a/SUPasswordPrompt.h b/SUPasswordPrompt.h new file mode 100644 index 00000000..c70372a5 --- /dev/null +++ b/SUPasswordPrompt.h @@ -0,0 +1,26 @@ +// +// SUPasswordPrompt.h +// Sparkle +// +// Created by rudy on 8/18/09. +// Copyright 2009 Ambrosia Software, Inc.. All rights reserved. +// + +#import +#import "Sparkle/SUWindowController.h" + +@interface SUPasswordPrompt : SUWindowController +{ + IBOutlet NSImageView *mIconView; + IBOutlet NSTextField *mTextDescription; + IBOutlet NSSecureTextField *mPasswordField; + NSString *mPassword; + NSString *mName; + NSImage *mIcon; +} + +- (id)initWithHost:(SUHost *)aHost; +- (NSInteger)run; +- (NSString *)password; + +@end diff --git a/SUPasswordPrompt.m b/SUPasswordPrompt.m new file mode 100644 index 00000000..4cff46dc --- /dev/null +++ b/SUPasswordPrompt.m @@ -0,0 +1,86 @@ +// +// SUPasswordPrompt.m +// Sparkle +// +// Created by rudy on 8/18/09. +// Copyright 2009 Ambrosia Software, Inc.. All rights reserved. +// + +#import "SUPasswordPrompt.h" + + +@implementation SUPasswordPrompt + +- (id)initWithHost:(SUHost *)aHost +{ + self = [super initWithHost:aHost windowNibName:@"SUPasswordPrompt"]; + if (self) + { + [self setName:[aHost name]]; + [self setIcon:[aHost icon]]; + mPassword = nil; + [self setShouldCascadeWindows:NO]; + } + return self; +} + +- (void)awakeFromNib +{ + [mIconView setImage:[self icon]]; +} + +- (void)setName:(NSString*)name +{ + [mName release]; + mName = [name retain]; +} + +- (NSString*)name +{ + return mName; +} + +- (void)setIcon:(NSImage*)icon +{ + [mIcon release]; + mIcon = [icon retain]; +} + +- (NSImage*)icon +{ + return mIcon; +} + +- (NSString *)password +{ + return mPassword; +} + +- (void)setPassword:(NSString*)password +{ + [mPassword release]; + mPassword = [password retain]; +} + +- (NSInteger)run +{ + //modally run a password prompt + NSInteger result = [NSApp runModalForWindow:[self window]]; + if(result) + [self setPassword:[mPasswordField stringValue]]; + return result; +} + +- (IBAction)accept:(id)sender +{ + [[self window] orderOut:self]; + [NSApp stopModalWithCode:1]; +} + +- (IBAction)cancel:(id)sender +{ + [[self window] orderOut:self]; + [NSApp stopModalWithCode:0]; +} + +@end diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index 2b209590..dc37e056 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -13,6 +13,7 @@ #import "SUHost.h" #import "SUStatusController.h" #import "SUConstants.h" +#import "SUPasswordPrompt.h" @implementation SUUIBasedUpdateDriver @@ -160,6 +161,19 @@ [NSApp requestUserAttention:NSInformationalRequest]; } +- (void)unarchiver:(SUUnarchiver *)unarchiver requiresPasswordReturnedViaInvocation:(NSInvocation *)invocation +{ + SUPasswordPrompt *prompt = [[SUPasswordPrompt alloc] initWithHost:host]; + NSString *password = nil; + if([prompt run]) + { + password = [prompt password]; + } + [prompt release]; + [invocation setArgument:&password atIndex:2]; + [invocation invoke]; +} + - (void)installAndRestart: (id)sender { [self installWithToolAndRelaunch:YES]; diff --git a/SUUnarchiver.h b/SUUnarchiver.h index 261187c5..c726d174 100644 --- a/SUUnarchiver.h +++ b/SUUnarchiver.h @@ -28,6 +28,7 @@ - (void)unarchiver:(SUUnarchiver *)unarchiver extractedLength:(unsigned long)length; - (void)unarchiverDidFinish:(SUUnarchiver *)unarchiver; - (void)unarchiverDidFail:(SUUnarchiver *)unarchiver; +- (void)unarchiver:(SUUnarchiver *)unarchiver requiresPasswordReturnedViaInvocation:(NSInvocation *)invocation; @end #endif diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index 1a305d11..9e8a73e2 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -27,6 +27,8 @@ extern NSString * const SUUpdateDriverFinishedNotification; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (void)abortUpdate; - (BOOL)finished; +- (SUHost*)host; +- (void)setHost:(SUHost*)newHost; @end diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index d98282a9..e1bae4ee 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -42,4 +42,15 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; [super dealloc]; } +- (SUHost*)host +{ + return host; +} + +- (void)setHost:(SUHost*)newHost +{ + [host release]; + host = [newHost retain]; +} + @end diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 022976a5..57900f36 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -131,6 +131,9 @@ 61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */; }; 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 61FA52880E2D9EA400EF58AD /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (Required, ); }; }; + 93FB277A156BD80D001937C7 /* SUPasswordPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 93FB2778156BD80D001937C7 /* SUPasswordPrompt.h */; }; + 93FB277B156BD80D001937C7 /* SUPasswordPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 93FB2779156BD80D001937C7 /* SUPasswordPrompt.m */; }; + 93FB277F156BD826001937C7 /* SUPasswordPrompt.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93FB277D156BD826001937C7 /* SUPasswordPrompt.xib */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -381,6 +384,9 @@ 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBasicUpdateDriver.m; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 8DC2EF5B0486A6940098B216 /* Sparkle.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Sparkle.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 93FB2778156BD80D001937C7 /* SUPasswordPrompt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPasswordPrompt.h; sourceTree = ""; }; + 93FB2779156BD80D001937C7 /* SUPasswordPrompt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPasswordPrompt.m; sourceTree = ""; }; + 93FB277E156BD826001937C7 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/SUPasswordPrompt.xib; sourceTree = ""; }; FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigFrameworkDebug.xcconfig; sourceTree = ""; }; FA1941CB0D94A70100DD942E /* ConfigTestAppDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigTestAppDebug.xcconfig; sourceTree = ""; }; FA1941CC0D94A70100DD942E /* ConfigCommonRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigCommonRelease.xcconfig; sourceTree = ""; }; @@ -518,6 +524,7 @@ 55C14BF0136EF26100649790 /* SUUpdateAlert.xib */, 55C14BDA136EF20D00649790 /* SUAutomaticUpdateAlert.xib */, 55C14BD8136EF00C00649790 /* SUStatus.xib */, + 93FB277D156BD826001937C7 /* SUPasswordPrompt.xib */, ); name = "Framework Resources"; sourceTree = ""; @@ -608,6 +615,8 @@ 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 61180BC80D64138900B4E0D1 /* SUWindowController.h */, 61180BC90D64138900B4E0D1 /* SUWindowController.m */, + 93FB2778156BD80D001937C7 /* SUPasswordPrompt.h */, + 93FB2779156BD80D001937C7 /* SUPasswordPrompt.m */, ); name = "User Interface"; sourceTree = ""; @@ -772,6 +781,7 @@ 55C14F06136EF6DB00649790 /* SULog.h in Headers */, 55C14F0F136EF73600649790 /* finish_installation.pch in Headers */, 6158A1C5137904B300487EC1 /* SUUpdater_Private.h in Headers */, + 93FB277A156BD80D001937C7 /* SUPasswordPrompt.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -981,6 +991,7 @@ 55C14C04136EF26100649790 /* SUUpdateAlert.xib in Resources */, 55C14C19136EF2C700649790 /* SUUpdatePermissionPrompt.xib in Resources */, 55C14F3B136EFCB300649790 /* finish_installation.app in Resources */, + 93FB277F156BD826001937C7 /* SUPasswordPrompt.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1144,6 +1155,7 @@ 5D06E8ED0FD68CE4005AE3F6 /* SUBinaryDeltaCommon.m in Sources */, 5D06E93A0FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m in Sources */, 55C14F07136EF6DB00649790 /* SULog.m in Sources */, + 93FB277B156BD80D001937C7 /* SUPasswordPrompt.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1307,6 +1319,14 @@ name = MainMenu.nib; sourceTree = ""; }; + 93FB277D156BD826001937C7 /* SUPasswordPrompt.xib */ = { + isa = PBXVariantGroup; + children = ( + 93FB277E156BD826001937C7 /* en */, + ); + name = SUPasswordPrompt.xib; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ diff --git a/en.lproj/SUPasswordPrompt.xib b/en.lproj/SUPasswordPrompt.xib new file mode 100644 index 00000000..2002c8e7 --- /dev/null +++ b/en.lproj/SUPasswordPrompt.xib @@ -0,0 +1,606 @@ + + + + 1050 + 12A251 + 2488 + 1183 + 622.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 2488 + + + YES + NSButton + NSButtonCell + NSCustomObject + NSImageCell + NSImageView + NSSecureTextField + NSSecureTextFieldCell + NSTextField + NSTextFieldCell + NSView + NSWindowTemplate + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + PluginDependencyRecalculationVersion + + + + YES + + SUPasswordPrompt + + + FirstResponder + + + NSApplication + + + 1 + 2 + {{196, 372}, {394, 118}} + 544736256 + Password + NSWindow + + + + + 256 + + YES + + + 290 + {{179, 49}, {195, 22}} + + + + YES + + 342884416 + 272630784 + + + LucidaGrande + 13 + 1044 + + + YES + + 6 + System + textBackgroundColor + + 3 + MQA + + + + 6 + System + textColor + + 3 + MAA + + + + YES + NSAllRomanInputSourcesLocaleIdentifier + + + NO + + + + 292 + {{106, 51}, {68, 17}} + + + + YES + + 68157504 + 272630784 + Password: + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2NjY3AA + + + + 6 + System + controlTextColor + + + + NO + + + + 289 + {{297, 13}, {83, 32}} + + + YES + + 67108864 + 134217728 + Unlock + + + -2038284288 + 129 + + DQ + 200 + 25 + + NO + + + + 289 + {{215, 13}, {82, 32}} + + + + YES + + 67108864 + 134217728 + Cancel + + + -2038284288 + 129 + + Gw + 200 + 25 + + NO + + + + 266 + {{106, 86}, {271, 17}} + + + + YES + + 67108864 + 272629760 + This update is locked with a password. + + LucidaGrande-Bold + 13 + 16 + + + + + + NO + + + + 268 + + YES + + YES + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + NSFilenamesPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT TIFF v4.0 pasteboard type + + + {{20, 39}, {64, 64}} + + + + YES + + 0 + 33554432 + 0 + 0 + 0 + NO + + NO + YES + + + {394, 118} + + + + + {{0, 0}, {1440, 878}} + {10000000000000, 10000000000000} + YES + + + + + YES + + + mPasswordField + + + + 19 + + + + window + + + + 20 + + + + cancel: + + + + 21 + + + + accept: + + + + 22 + + + + mTextDescription + + + + 25 + + + + mIconView + + + + 26 + + + + + YES + + 0 + + YES + + + + + + -2 + + + File's Owner + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + YES + + + + + + 2 + + + YES + + + + + + + + + + + 3 + + + YES + + + + + + 4 + + + + + 5 + + + YES + + + + + + 6 + + + + + 7 + + + YES + + + + + + 8 + + + + + 9 + + + YES + + + + + + 10 + + + + + 15 + + + YES + + + + + + 16 + + + + + 17 + + + YES + + + + + + 18 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 1.IBPluginDependency + 1.IBWindowTemplateEditedContentRect + 1.NSWindowTemplate.visibleAtLaunch + 10.IBPluginDependency + 15.IBPluginDependency + 16.IBPluginDependency + 17.IBPluginDependency + 18.IBPluginDependency + 2.IBPluginDependency + 3.IBPluginDependency + 4.IBPluginDependency + 5.IBPluginDependency + 6.IBPluginDependency + 7.IBPluginDependency + 8.IBPluginDependency + 9.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{316, 826}, {362, 138}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + + + + + YES + + + + + 26 + + + + YES + + SUPasswordPrompt + SUWindowController + + YES + + YES + accept: + cancel: + + + YES + id + id + + + + YES + + YES + accept: + cancel: + + + YES + + accept: + id + + + cancel: + id + + + + + YES + + YES + mIconView + mPasswordField + mTextDescription + + + YES + NSImageView + NSSecureTextField + NSTextField + + + + YES + + YES + mIconView + mPasswordField + mTextDescription + + + YES + + mIconView + NSImageView + + + mPasswordField + NSSecureTextField + + + mTextDescription + NSTextField + + + + + IBProjectSource + ./Classes/SUPasswordPrompt.h + + + + SUWindowController + NSWindowController + + IBProjectSource + ./Classes/SUWindowController.h + + + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES + 3 + +