Permalink
Browse files

support for encrypted disk images

  • Loading branch information...
1 parent 6960045 commit 4ba453f337e4f19d38c48c1d2f8405ee96f70c9f @rudyrichter rudyrichter committed May 22, 2012
View
@@ -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
View
@@ -128,6 +128,7 @@ - (id)init;
[[self task] setStandardInput:[self inputPipe]];
[[self task] setStandardOutput:[self outputPipe]];
+ [[self task] setStandardError:[self outputPipe]];
}
return self;
View
@@ -11,7 +11,7 @@
#import "NTSynchronousTask.h"
#import "SULog.h"
#import <CoreServices/CoreServices.h>
-
+#import "SUPasswordPrompt.h"
@implementation SUDiskImageUnarchiver
@@ -48,18 +48,64 @@ - (void)extractDMG
}
}
while (noErr == FSPathMakeRefWithOptions((UInt8 *)[mountPoint fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &tmpRef, NULL));
+
+/* ASW_ADDITION */
+#pragma mark ASW_ADDITION
+ BOOL isEncrypted = NO;
+ NSData *result = [NTSynchronousTask task:@"/usr/bin/hdiutil" directory:@"/" withArgs:[NSArray arrayWithObjects: @"isencrypted", archivePath, nil] input:NULL];
+ if([self isEncrypted:result])
+ isEncrypted = YES;
+/* ASW_ADDITION */
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];
+/* ASW_ADDITION */
+#pragma mark ASW_ADDITION
+ NSData* promptData;
+ if(isEncrypted) {
+ SUPasswordPrompt *prompt = [[SUPasswordPrompt alloc] initWithHost:(SUHost*)[delegate host]];
+ if([prompt run])
+ {
+ NSString *password = [prompt password];
+ if(![password length])
+ goto reportError;
+ 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
+ {
+ goto reportError;
+ }
+ [prompt release];
+ }
+ else
+ promptData = [NSData dataWithBytes:"yes\n" length:4];
+/* ASW_ADDITION */
+
+ 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 );
+ SULog( @"hdiutil failed with code: %d data: <<%@>>", taskResult, resultStr );
goto reportError;
}
mountedSuccessfully = YES;
@@ -132,4 +178,21 @@ + (void)load
[self registerImplementation:self];
}
+/* ASW_ADDITION */
+#pragma mark ASW_ADDITION
+- (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;
+}
+/* ASW_ADDITION */
+
@end
View
@@ -0,0 +1,35 @@
+//
+// SUPasswordPrompt.h
+// Sparkle
+//
+// Created by rudy on 8/18/09.
+// Copyright 2009 Ambrosia Software, Inc.. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#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;
+- (void)awakeFromNib;
+- (void)setName:(NSString*)name;
+- (NSString*)name;
+- (void)setIcon:(NSImage*)icon;
+- (NSImage*)icon;
+- (NSString *)password;
+- (void)setPassword:(NSString*)password;
+- (NSInteger)run;
+- (IBAction)accept:(id)sender;
+- (IBAction)cancel:(id)sender;
+- (void)replaceTitle:(NSString*)name;
+
+@end
View
@@ -0,0 +1,94 @@
+//
+// 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
+{
+ [self replaceTitle:[self name]];
+ [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];
+}
+
+- (void)replaceTitle:(NSString*)name
+{
+ NSString *textString = [mTextDescription stringValue];
+ NSString *replacementString = [textString stringByReplacingOccurrencesOfString:@"<APPLICATION>" withString:name];
+ [mTextDescription setStringValue:replacementString];
+}
+
+@end
View
@@ -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
View
@@ -42,4 +42,15 @@ - (void)dealloc
[super dealloc];
}
+- (SUHost*)host
+{
+ return host;
+}
+
+- (void)setHost:(SUHost*)newHost
+{
+ [host release];
+ host = [newHost retain];
+}
+
@end
Oops, something went wrong.

0 comments on commit 4ba453f

Please sign in to comment.