Changeset 23 for trunk

Show
Ignore:
Timestamp:
03/13/08 17:52:16 (10 months ago)
Author:
mgorbach
Message:

Security system, UI refinement and other fixes. Ready for beta 1

Location:
trunk
Files:
27 added
7 removed
38 modified

Legend:

Unmodified
Added
Removed
  • trunk/MFClient.h

    r19 r23  
    2121        id <MFServerProtocol> server; 
    2222        id delegate; 
     23        bool triedBootstrap; 
    2324} 
    2425 
     
    3233- (MFClientFS*)mountRecent:(MFClientRecent*)recent 
    3334                                         error:(NSError**)error; 
     35- (void)deleteFilesystem:(MFClientFS*)fs; 
    3436 
    3537// Accessors 
  • trunk/MFClient.m

    r20 r23  
    1212#import "MFConstants.h" 
    1313#import "MFClientRecent.h" 
     14#import <Security/Security.h> 
     15#import "MFCore.h" 
    1416 
    1517#define ORDERING_FILE_PATH @"~/Library/Application Support/Macfusion/Ordering.plist" 
     
    2022- (void)removeFilesystem:(MFClientFS*)fs; 
    2123- (void)loadOrdering; 
     24- (void)setupKeychainMonitoring; 
     25- (void)writeOrdering; 
     26// Security monitoring 
    2227 
    2328@property(readwrite, retain) NSMutableArray* persistentFilesystems; 
     
    100105                plugins = [NSMutableArray array]; 
    101106                recents = [NSMutableArray array]; 
     107                [self setupKeychainMonitoring]; 
     108                setStateForAgentLoginItem(YES); 
     109                triedBootstrap = NO; 
    102110        } 
    103111        return self; 
     
    160168                [self fillInitialStatus]; 
    161169                return YES; 
     170        } 
     171        else 
     172        { 
     173                // Try to start the server process 
     174                NSAlert* serverStartAlert = [NSAlert new]; 
     175                [serverStartAlert setMessageText: @"The macfusion agent process is not started"]; 
     176                [serverStartAlert setInformativeText: @"Would you like to start the agent?\nOtherwise, Macfusion will Quit."]; 
     177                [serverStartAlert setShowsSuppressionButton: YES]; 
     178                [serverStartAlert addButtonWithTitle:@"Start"]; 
     179                [serverStartAlert addButtonWithTitle:@"Quit"]; 
     180                [[serverStartAlert suppressionButton] setTitle: @"Start agent automatically on login"]; 
     181                NSInteger returnValue = [serverStartAlert runModal]; 
     182                // MFLogS(self, @"Return %d supression state %d", returnValue, [[serverStartAlert suppressionButton] state]); 
     183                 
     184                if ([[serverStartAlert suppressionButton] state]) 
     185                        setStateForAgentLoginItem(YES); 
     186                         
     187                if (returnValue == NSAlertSecondButtonReturn) 
     188                { 
     189                        [NSApp terminate: self]; 
     190                } 
     191                else if (returnValue == NSAlertFirstButtonReturn) 
     192                { 
     193                        NSString* agentPath = [[NSBundle bundleWithPath: mainUIBundlePath()] pathForResource:@"macfusionAgent" ofType:nil]; 
     194                        [NSTask launchedTaskWithLaunchPath: agentPath arguments:[NSArray array]]; 
     195                        [[NSRunLoop currentRunLoop] runUntilDate:[[NSDate date] addTimeInterval: 1.5]]; 
     196                         
     197                        if ([self establishCommunication]) 
     198                        { 
     199                                [self fillInitialStatus]; 
     200                                return YES; 
     201                        } 
     202                        else 
     203                        { 
     204                                NSAlert* faliureAlert = [NSAlert alertWithMessageText:@"Could not start or connect to the macfusion agent" 
     205                                                                                                                defaultButton:@"OK" 
     206                                                                                                          alternateButton:@"" 
     207                                                                                                                  otherButton:@"" 
     208                                                                                        informativeTextWithFormat:@"Macfusion will Quit."]; 
     209                                [faliureAlert setAlertStyle: NSCriticalAlertStyle]; 
     210                                [faliureAlert runModal]; 
     211                                [NSApp terminate: self]; 
     212                        } 
     213                } 
    162214        } 
    163215         
     
    236288} 
    237289 
     290- (void)deleteFilesystem:(MFClientFS*)fs 
     291{ 
     292        NSString* uuid = [fs uuid]; 
     293        [server deleteFilesystemWithUUID: uuid]; 
     294} 
     295 
    238296#pragma mark Recents 
    239297- (void)handleRecentsUpdatedNotification:(NSNotification*)note 
     
    260318         
    261319        return nil; 
     320} 
     321 
     322#pragma mark Security 
     323OSStatus myKeychainCallback ( 
     324                                                         SecKeychainEvent keychainEvent, 
     325                                                         SecKeychainCallbackInfo *info, 
     326                                                         void *context 
     327) 
     328{ 
     329        MFClient* self = (MFClient*)context; 
     330        // MFLogS(self, @"Keychain callback received event is %d", keychainEvent); 
     331        SecKeychainItemRef itemRef = info -> item; 
     332        NSString* uuid = (NSString*)uuidForKeychainItemRef(itemRef); 
     333        MFClientFS* fs = [self filesystemWithUUID:uuid]; 
     334        if (fs) 
     335        { 
     336                // MFLogS(self, @"Updating secrets for fs %@ due to keychain change", fs); 
     337                [fs updateSecrets]; 
     338        } 
     339        return 0; 
     340} 
     341 
     342- (void)setupKeychainMonitoring 
     343{ 
     344        SecKeychainEventMask eventMask = kSecUpdateEventMask | kSecAddEventMask; 
     345        SecKeychainAddCallback(myKeychainCallback , eventMask, self); 
    262346} 
    263347 
     
    375459                [fs setDisplayOrder: [persistentFilesystems indexOfObject: fs]]; 
    376460        } 
     461         
     462        [self writeOrdering]; 
    377463} 
    378464 
     
    407493- (void)handleApplicationTerminatingNotification:(NSNotification*)note 
    408494{ 
    409         [self writeOrdering]; 
     495        // [self writeOrdering]; 
    410496} 
    411497 
  • trunk/MFClientFS.h

    r19 r23  
    1818        MFClientPlugin* plugin; 
    1919        NSDictionary* backupParameters; 
     20        NSDictionary* backupSecrets; 
    2021        BOOL isEditing; 
    2122        NSInteger displayOrder; 
     
    3233- (void)handleStatusInfoChangedNotification:(NSNotification*)note; 
    3334- (void)handleParametersChangedNotification:(NSNotification*)note; 
     35- (void)setPauseTimeout:(BOOL)p; 
    3436 
    3537// Editing 
     
    3840- (NSDictionary*)displayDictionary; 
    3941 
     42// UI 
     43- (NSDictionary*)configurationViewControllers; 
     44 
    4045@property(readwrite, assign) NSInteger displayOrder; 
    4146@property(readwrite, retain) id<MFClientFSDelegateProtocol> clientFSDelegate;  
     47@property(readonly) NSImage* iconImage; 
    4248@end 
  • trunk/MFClientFS.m

    r20 r23  
    1111#import "MFClientPlugin.h" 
    1212#import "MFServerFSProtocol.h" 
     13#import "MFSecurity.h" 
    1314 
    1415@interface MFClientFS (PrivateAPI) 
     
    5455                [self registerNotifications]; 
    5556                displayOrder = 9999; 
     57                [self updateSecrets]; 
    5658        } 
    5759         
     
    176178        backupParameters = [NSDictionary dictionaryWithDictionary:  
    177179                                                [self parameters]]; 
     180        backupSecrets = [NSDictionary dictionaryWithDictionary: secrets]; 
    178181} 
    179182 
     
    192195                if (result) 
    193196                { 
     197                        // Validation failed 
    194198                        return result; 
    195199                } 
    196200                else 
    197201                { 
     202                        // Update secure information 
     203                        if (![secrets isEqualToDictionary: backupSecrets]) 
     204                        { 
     205                                setSecretsDictionaryForFilesystem( secrets, self ); 
     206                        } 
    198207                        isEditing = NO; 
    199208                        return nil; 
     
    204213                isEditing = NO; 
    205214                [self setParameters: [backupParameters mutableCopy] ]; 
     215                [self setSecrets: [backupSecrets mutableCopy]]; 
     216 
    206217        } 
    207218         
     
    209220} 
    210221 
    211 - (void)willChangeValueForKey:(NSString*)key 
    212 { 
    213         if ([key isLike:@"parameters.*"] && !isEditing) 
    214         { 
    215                 [[NSException exceptionWithName:kMFBadAPIUsageException 
    216                                                                 reason:@"Trying to modify parameters without beginEditing" 
    217                                                           userInfo:nil] raise]; 
    218         } 
    219          
    220         [super willChangeValueForKey:key]; 
     222- (NSImage*)iconImage 
     223{ 
     224        return [[NSImage alloc] initWithContentsOfFile:  
     225                        self.iconPath]; 
     226} 
     227 
     228- (void)setPauseTimeout:(BOOL)p 
     229{ 
     230        [remoteFilesystem setPauseTimeout: p]; 
     231} 
     232 
     233# pragma mark UI 
     234- (NSDictionary*)configurationViewControllers 
     235{ 
     236        NSMutableDictionary* myControllers = [NSMutableDictionary dictionary]; 
     237        NSViewController* macfusionAdvancedController = [[NSViewController alloc] initWithNibName: @"macfusionAdvancedView" 
     238                                                                                                                                                                           bundle: [NSBundle bundleForClass: [self class]]]; 
     239        [myControllers setObject: macfusionAdvancedController forKey:kMFUIMacfusionAdvancedViewKey]; 
     240        NSDictionary* delegateControllers = [delegate configurationViewControllers]; 
     241        if (!delegateControllers) 
     242        { 
     243                MFLogS(self, @"No view controllers specified by delegate"); 
     244        } 
     245         
     246        [myControllers addEntriesFromDictionary: delegateControllers]; 
     247        return [myControllers copy]; 
    221248} 
    222249 
  • trunk/MFCommunicationServer.m

    r19 r23  
    219219} 
    220220                                  
     221- (void)deleteFilesystemWithUUID:(NSString*)uuid 
     222{ 
     223        MFServerFS* fs = [[MFFilesystemController sharedController] filesystemWithUUID: uuid]; 
     224        NSAssert(fs, @"CommunicationServer asked to remove filesystem with bad uuid"); 
     225        [[MFFilesystemController sharedController] deleteFilesystem: fs]; 
     226} 
     227 
     228#pragma mark Security Tokens 
     229- (NSString*)tokenForFilesystemWithUUID:(NSString*)uuid 
     230{ 
     231        MFServerFS* fs = [[MFFilesystemController sharedController] filesystemWithUUID: uuid]; 
     232        return [[MFFilesystemController sharedController] tokenForFilesystem: fs]; 
     233} 
     234 
     235- (MFServerFS*)filesystemForToken:(NSString*)token 
     236{ 
     237        MFServerFS* fs = [[MFFilesystemController sharedController] filesystemForToken: token]; 
     238        if (fs) 
     239                [[MFFilesystemController sharedController] invalidateToken: token]; 
     240        return fs; 
     241} 
    221242 
    222243#pragma mark Sever Protocol Methods 
  • trunk/MFConstants.h

    r21 r23  
    6666#define kMFFSPersistentParameter @"isPersistent" 
    6767#define kMFFSDescriptionParameter @"description" 
     68#define kMFFSVolumeImagePathParameter @"imagePath" 
    6869 
    6970// Status keys 
     
    106107extern NSString* kMFUIMainViewKey; 
    107108extern NSString* kMFUIAdvancedViewKey; 
     109extern NSString* kMFUIMacfusionAdvancedViewKey; 
    108110 
  • trunk/MFConstants.m

    r21 r23  
    3030*/ 
    3131 
    32 NSString* kMFUIMainViewKey=@"main2"; 
     32NSString* kMFUIMainViewKey=@"main"; 
    3333NSString* kMFUIAdvancedViewKey=@"advanced"; 
     34NSString* kMFUIMacfusionAdvancedViewKey=@"macfusion"; 
  • trunk/MFFSDelegateProtocol.h

    r21 r23  
    11/* 
    2  *  MFServerProtocol.h 
     2 *  MFFSDelegate.h 
    33 *  MacFusion2 
    44 * 
     
    4343- (NSError*)errorForParameters:(NSDictionary*)parameters  
    4444                                                output:(NSString*)output; 
     45 
     46// Security 
     47- (NSArray*)secretsList; 
     48- (NSArray*)secretsClientsList; 
    4549@end 
  • trunk/MFFilesystem.h

    r21 r23  
    11// 
    22//  MFFilesystem.h 
    3 //  macfusiond 
     3//  MacFusion2 
    44// 
    55//  Created by Michael Gorbach on 11/5/07. 
     
    1616        NSMutableDictionary* statusInfo; 
    1717        id <MFFSDelegateProtocol> delegate; 
     18        NSMutableDictionary* secrets; 
    1819} 
    1920 
     
    3536- (NSMutableDictionary*)fillParametersWithImpliedValues:(NSDictionary*)params; 
    3637- (NSError*)error; 
    37  
    3838- (id <MFFSDelegateProtocol>)delegate; 
     39- (void)updateSecrets; 
    3940 
    4041@property(readwrite, assign) NSString* status; 
     
    4445@property(readonly) NSMutableDictionary* parameters; 
    4546@property(readonly) NSDictionary* statusInfo; 
     47@property (readwrite, retain) NSMutableDictionary* secrets; 
    4648@property(readonly) NSString* pluginID; 
    4749@property(readonly) NSString* descriptionString; 
    4850@property(readonly) NSString* iconPath; 
    4951@property(readonly) NSString* filePath; 
     52@property(readonly) NSString* imagePath; 
    5053 
    5154@end 
  • trunk/MFFilesystem.m

    r21 r23  
    11// 
    22//  MFFilesystem.m 
    3 //  macfusiond 
     3//  MacFusion2 
    44// 
    55//  Created by Michael Gorbach on 11/5/07. 
     
    1010//#import "MFPluginController.h" 
    1111#import "MFPlugin.h" 
    12 #import "MFConstants.h" 
     12#import "MFConstants.h"] 
     13#import "MFSecurity.h" 
    1314 
    1415#define FS_DIR_PATH @"~/Library/Application Support/Macfusion/Filesystems" 
     
    184185} 
    185186 
     187- (void)updateSecrets 
     188{ 
     189        NSMutableDictionary* updateSecrets = [getSecretsDictionaryForFilesystem( self ) mutableCopy]; 
     190        self.secrets = updateSecrets ? updateSecrets : [NSMutableDictionary dictionary]; 
     191} 
     192 
    186193- (NSMutableDictionary*)parametersWithImpliedValues 
    187194{ 
     
    192199{ 
    193200        return [self valueForParameterNamed: kMFFSVolumeIconPathParameter ]; 
     201} 
     202 
     203- (NSString*)imagePath 
     204{ 
     205        return [self valueForParameterNamed: kMFFSVolumeImagePathParameter ]; 
    194206} 
    195207 
     
    230242} 
    231243 
     244- (NSString*)description 
     245{ 
     246        return [NSString stringWithFormat: @"%@ (%@)", [super description], self.name]; 
     247} 
     248 
     249@synthesize secrets; 
    232250@end 
  • trunk/MFFilesystemController.h

    r19 r23  
    1515        NSMutableArray* recents; 
    1616        NSMutableArray* mountedPaths; 
     17        NSMutableDictionary* tokens; 
    1718         
    1819        DASessionRef appearSession; 
    1920        DASessionRef disappearSession; 
    20          
    21         BOOL firstTimeMounting; 
    2221} 
    2322 
     23// Init 
    2424+ (MFFilesystemController*)sharedController; 
    2525- (void)loadFilesystems; 
    26 - (NSDictionary*)filesystemsDictionary; 
    27 - (NSMutableArray*)filesystems; 
     26 
     27 
     28// Action methods 
    2829- (MFServerFS*)newFilesystemWithPlugin:(MFServerPlugin*)plugin; 
    2930- (MFServerFS*)quickMountWithURL:(NSURL*)url  
    3031                                                   error:(NSError**)error; 
     32- (void)deleteFilesystem:(MFServerFS*)fs; 
    3133 
    32 - (void)storeFilesystem:(MFServerFS*)fs; 
    3334- (MFServerFS*)filesystemWithUUID:(NSString*)uuid; 
    3435 
    35 - (void)addMountedPath:(NSString*)path; 
    36 - (void)removeMountedPath:(NSString*)path; 
     36// Security Tokens 
     37- (NSString*)tokenForFilesystem:(MFServerFS*)fs; 
     38- (void)invalidateToken:(NSString*)token; 
     39- (MFServerFS*)filesystemForToken:(NSString*)token; 
    3740 
    38  
     41// Accessors 
     42- (NSDictionary*)filesystemsDictionary; 
    3943@property(readonly, retain) NSMutableArray* filesystems; 
    4044@property(readonly, retain) NSMutableArray* recents; 
  • trunk/MFFilesystemController.m

    r20 r23  
    2626- (void)recordRecentFilesystem:(MFServerFS*)fs; 
    2727- (NSString*)getUUIDXattrAtPath:(NSString*)path; 
     28- (void)addMountedPath:(NSString*)path; 
     29- (void)removeMountedPath:(NSString*)path; 
     30- (void)storeFilesystem:(MFServerFS*)fs; 
     31- (void)removeFilesystem:(MFServerFS*)fs; 
    2832 
    2933@property(readwrite, retain) NSMutableArray* filesystems; 
     
    8084                mountedPaths = [NSMutableArray array]; 
    8185                recents = [NSMutableArray array]; 
     86                tokens = [NSMutableDictionary dictionary]; 
    8287                [self loadRecentFilesystems]; 
    8388                [self setUpVolumeMonitoring]; 
     
    150155                                        [[self getUUIDXattrAtPath: mountedPath] isEqualToString: fs.uuid]) 
    151156                                { 
    152                                         MFLogS(self, @"Premounth hit"); 
     157//                                      MFLogS(self, @"Pre-mount condition hit on %@", fs.uuid); 
    153158                                        [fs handleMountNotification]; 
    154159                                } 
     
    204209        [fs performSelector:@selector(mount) withObject:nil afterDelay:0]; 
    205210        return fs; 
     211} 
     212 
     213- (void)deleteFilesystem:(MFServerFS*)fs 
     214{ 
     215        if (fs.filePath) 
     216                [[NSFileManager defaultManager] removeFileAtPath:fs.filePath handler:nil]; 
     217        [self removeFilesystem: fs]; 
    206218} 
    207219 
     
    269281                if (equal)  
    270282                { 
    271                         MFLogS(self, @"Duplicate recents detected, %@ and %@", 
    272                                    params, recent); 
     283                        // MFLogS(self, @"Duplicate recents detected, %@ and %@", 
     284                        //         params, recent); 
    273285