Changeset 35

Show
Ignore:
Timestamp:
02/16/05 23:22:30 (4 years ago)
Author:
bart
Message:

Added the option to unload keys after a period of time. Still need to be tested for stability, since it uses threads and locks.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Controller.m

    r33 r35  
    5959                        @"NO", 
    6060                        @"30", 
     61                        @"0", 
    6162                        nil 
    6263                ] 
     
    7677                        manageGlobalEnvironmentString, 
    7778                        checkScreensaverIntervalString, 
     79                        keyTimeoutString, 
    7880                        nil 
    7981                ] 
  • trunk/English.lproj/Preferences.nib/classes.nib

    r33 r35  
    7878            ACTIONS = { 
    7979                changeCheckScreensaverInterval = id;  
     80                changeKeyTimeout = id;  
    8081                changeMinutesOfSleep = id;  
    8182                changeOnScreensaver = id;  
    8283                changeOnSleep = id;  
    83                 myAction = id;  
    8484                toggleCustomSecuritySettings = id;  
    8585            };  
     
    9393                customSecuritySettingsView = id;  
    9494                followKeychain = id;  
     95                keyTimeout = id;  
     96                keyTimeoutTextfield = id;  
    9597                minutesOfSleep = id;  
    9698                minutesOfSleepTextfield = id;  
  • trunk/English.lproj/Preferences.nib/info.nib

    r33 r35  
    1010                <string>304 452 416 112 0 0 1024 746 </string> 
    1111                <key>640</key> 
    12                 <string>170 32 495 292 0 0 1024 746 </string> 
     12                <string>75 34 495 343 0 0 1024 746 </string> 
    1313                <key>722</key> 
    1414                <string>446 468 495 234 0 0 1440 878 </string> 
     
    2626                <string>446 468 495 234 0 0 1440 878 </string> 
    2727                <key>909</key> 
    28                 <string>56 312 495 234 0 0 1024 746 </string> 
     28                <string>264 391 495 234 0 0 1024 746 </string> 
    2929        </dict> 
    3030        <key>IBFramework Version</key> 
     
    3636        </array> 
    3737        <key>IBSystem Version</key> 
    38         <string>7S215</string> 
     38        <string>7U16</string> 
    3939</dict> 
    4040</plist> 
  • trunk/Libs/SSHKeychain.h

    r3 r35  
    99        NSString *agentSocketPath; 
    1010        BOOL addingKeys; 
     11         
     12        int lastAdded; 
    1113 
    1214        /* Locks */ 
    1315        NSLock *keychainLock; 
    1416        NSLock *addingKeysLock; 
     17        NSLock *lastAddedLock; 
    1518} 
    1619 
     
    3740- (BOOL)addKeysToAgent; 
    3841- (BOOL)addKeysToAgentWithInteraction:(BOOL)interaction; 
     42- (void)removeKeysAfterTimeout:(id)object; 
    3943- (BOOL)removeKeysFromAgent; 
    4044 
  • trunk/Libs/SSHKeychain.m

    r28 r35  
    11#import "SSHKeychain.h" 
     2#import "PreferenceController.h" 
    23 
    34#import "SSHKey.h" 
    45#import "SSHTool.h" 
     6 
     7#include <unistd.h> 
    58 
    69SSHKeychain *currentKeychain; 
     
    5053 
    5154        [keychainLock unlock]; 
    52  
     55         
     56        [lastAddedLock lock]; 
     57        lastAdded = -1; 
     58        [lastAddedLock unlock]; 
     59         
    5360        currentKeychain = self; 
    5461         
     
    6572        addingKeysLock = [[NSLock alloc] init]; 
    6673        keychainLock = [[NSLock alloc] init]; 
     74        lastAddedLock = [[NSLock alloc] init]; 
    6775 
    6876        return self; 
     
    8795 
    8896        [addingKeysLock dealloc]; 
    89  
     97        [lastAddedLock dealloc]; 
     98         
    9099        [super dealloc]; 
    91100} 
     
    242251        NSMutableArray *paths; 
    243252        SSHTool *theTool; 
    244         int i
     253        int i, ts
    245254 
    246255        paths = [self arrayOfPaths]; 
     
    300309                        return NO; 
    301310                } 
     311                 
     312                if([[NSUserDefaults standardUserDefaults] integerForKey:keyTimeoutString] > 0) 
     313                { 
     314                        ts = time(nil); 
     315                        [lastAddedLock lock]; 
     316                        lastAdded = ts; 
     317                        [lastAddedLock unlock]; 
     318                         
     319                        [NSThread detachNewThreadSelector:@selector(removeKeysAfterTimeout:) toTarget:self  
     320                                                                        withObject:[NSNumber numberWithInt:ts]]; 
     321                } 
    302322 
    303323                [[NSNotificationCenter defaultCenter]  postNotificationName:@"AgentFilled" object:nil]; 
     
    316336} 
    317337 
     338/* Remove all keys from the ssh-agent from a NSTimer object. */ 
     339- (void)removeKeysAfterTimeout:(id)object 
     340{ 
     341        int ts; 
     342        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
     343         
     344        ts = [object intValue]; 
     345         
     346        sleep([[NSUserDefaults standardUserDefaults] integerForKey:keyTimeoutString] * 60); 
     347         
     348        [lastAddedLock lock]; 
     349        if(ts == lastAdded)  
     350        { 
     351                [lastAddedLock unlock]; 
     352                [self removeKeysFromAgent]; 
     353        } 
     354         
     355        [lastAddedLock unlock]; 
     356         
     357        [pool release]; 
     358} 
     359 
    318360/* Remove all keys from the ssh-agent. */ 
    319361- (BOOL)removeKeysFromAgent 
    320362{ 
    321363        SSHTool *theTool = [SSHTool toolWithName:@"ssh-add"]; 
     364         
     365        [lastAddedLock lock]; 
     366        lastAdded = -1; 
     367        [lastAddedLock unlock]; 
    322368 
    323369        if((!agentSocketPath) || ([[NSFileManager defaultManager] isReadableFileAtPath:agentSocketPath] == NO)) 
  • trunk/PreferenceController.h

    r33 r35  
    1818#define useCustomSecuritySettingsString @"Use Custom Security Settings" 
    1919#define checkScreensaverIntervalString @"Check Screensaver Interval" 
     20#define keyTimeoutString @"Key Timeout" 
    2021 
    2122@interface PreferenceController : NSObject  
  • trunk/PreferenceViews/SecurityView.h

    r33 r35  
    99        IBOutlet id addKeysOnConnection, askForConfirmation, followKeychain, onScreensaver, onSleep; 
    1010        IBOutlet id minutesOfSleep, minutesOfSleepTextfield, checkScreensaverInterval, checkScreensaverIntervalTextfield; 
     11        IBOutlet id keyTimeout, keyTimeoutTextfield; 
    1112} 
    1213 
     
    1718- (IBAction)changeCheckScreensaverInterval:(id)sender; 
    1819 
     20- (IBAction)changeKeyTimeout:(id)sender; 
     21 
    1922- (IBAction)toggleCustomSecuritySettings:(id)sender; 
    2023 
  • trunk/PreferenceViews/SecurityView.m

    r33 r35  
    1313        [minutesOfSleepTextfield setRefusesFirstResponder:YES]; 
    1414        [checkScreensaverIntervalTextfield setRefusesFirstResponder:YES]; 
     15        [keyTimeoutTextfield setRefusesFirstResponder:YES]; 
    1516 
    1617        [addKeysOnConnection setState:[[NSUserDefaults standardUserDefaults] boolForKey:addKeysOnConnectionString]]; 
     
    5051        [checkScreensaverIntervalTextfield setIntValue:[prefs integerForKey:checkScreensaverIntervalString]]; 
    5152        [checkScreensaverInterval setIntValue:[prefs integerForKey:checkScreensaverIntervalString]]; 
     53         
     54        [keyTimeoutTextfield setIntValue:[prefs integerForKey:keyTimeoutString]]; 
     55        [keyTimeout setIntValue:[prefs integerForKey:keyTimeoutString]]; 
    5256 
    5357        [useCustomSecuritySettings setState:[[NSUserDefaults standardUserDefaults] boolForKey:useCustomSecuritySettingsString]]; 
     
    7983                 
    8084                [prefs setInteger:[checkScreensaverIntervalTextfield intValue] forKey:checkScreensaverIntervalString]; 
     85                [prefs setInteger:[keyTimeoutTextfield intValue] forKey:keyTimeoutString]; 
     86 
    8187        }  
    8288 
     
    9197                [prefs setInteger:0 forKey:minutesOfSleepString]; 
    9298                [prefs setInteger:30 forKey:checkScreensaverIntervalString]; 
     99                [prefs setInteger:0 forKey:keyTimeoutString]; 
    93100        } 
    94101 
     
    143150                [prefs setInteger:0 forKey:minutesOfSleepString];                
    144151                [prefs setInteger:30 forKey:checkScreensaverIntervalString]; 
     152                [prefs setInteger:0 forKey:keyTimeoutString]; 
    145153 
    146154                [prefs synchronize]; 
     
    182190                [checkScreensaverIntervalTextfield setIntValue:[prefs integerForKey:checkScreensaverIntervalString]]; 
    183191                [checkScreensaverInterval setIntValue:[prefs integerForKey:checkScreensaverIntervalString]]; 
     192                 
     193                [keyTimeoutTextfield setIntValue:[prefs integerForKey:keyTimeoutString]]; 
     194                [keyTimeout setIntValue:[prefs integerForKey:keyTimeoutString]]; 
    184195 
    185196        } 
     
    251262} 
    252263 
     264/* The key timeout slidebar has changed. */ 
     265- (IBAction)changeKeyTimeout:(id)sender 
     266{ 
     267        if(sender == keyTimeout) 
     268        { 
     269                [keyTimeoutTextfield setIntValue:[sender intValue]]; 
     270        } 
     271         
     272        else if(sender == keyTimeoutTextfield) 
     273        { 
     274                [keyTimeoutTextfield setIntValue:[sender intValue]]; 
     275                [keyTimeout setIntValue:[sender intValue]]; 
     276        } 
     277} 
     278 
     279 
    253280@end 
  • trunk/TODO

    r34 r35  
    44- Only add keys from keychain event if keychain holds keys 
    55- Admin wrapper for tunnel ports < 1024 
    6 - Option to unload keys after a period of time 
    76- The option to not display messages regarding tunnels (Nov 05 - Marc Liyanage  - Feature suggestion for SSHKeychain) 
    87- Listen to local forwarded ports and start up the tunnel on demand (that's going to require some hacking with random ports to have ssh listening on) 
     
    1090.8 DONE: 
    1110- Option for screensaver check interval (bart) 
     11- Option to unload keys after a period of time (bart)  
    1212 
    13131.0 TODO: