Optimized Locking timer

Disabled re-locking of already locked documents
Disabled locking of documents without a password
This commit is contained in:
michael starke
2013-06-24 21:54:05 +02:00
parent 6056ff3722
commit 1b20ce0628
5 changed files with 43 additions and 17 deletions

View File

@@ -25,13 +25,18 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
@interface MPDocument : NSDocument @interface MPDocument : NSDocument
@property (assign, readonly) BOOL isProtected; /* true, if password and/or keyfile are set */
@property (assign, readonly, getter = isSecured) BOOL secured;
/* true, if lock screen is present (no phyiscal locking) */
@property (assign, getter = isLocked) BOOL locked;
/* true, if document is loaded and decrypted (tree is loaded) */
@property (assign, readonly, getter = isDecrypted) BOOL decrypted;
@property (retain, readonly) KdbTree *tree; @property (retain, readonly) KdbTree *tree;
@property (assign, readonly) KdbGroup *root; @property (assign, readonly) KdbGroup *root;
@property (nonatomic,retain) NSString *password; @property (nonatomic,retain) NSString *password;
@property (nonatomic, retain) NSURL *key; @property (nonatomic, retain) NSURL *key;
@property (assign, readonly) MPDatabaseVersion version; @property (assign, readonly) MPDatabaseVersion version;
@property (assign, readonly) BOOL isDecrypted;
- (id)initWithVersion:(MPDatabaseVersion)version; - (id)initWithVersion:(MPDatabaseVersion)version;
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL; - (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL;

View File

@@ -31,11 +31,11 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
@interface MPDocument () @interface MPDocument ()
@property (assign, nonatomic) BOOL isProtected; @property (assign, nonatomic) BOOL secured;
@property (retain) KdbTree *tree; @property (retain) KdbTree *tree;
@property (nonatomic, readonly) KdbPassword *passwordHash; @property (nonatomic, readonly) KdbPassword *passwordHash;
@property (assign) MPDatabaseVersion version; @property (assign) MPDatabaseVersion version;
@property (assign) BOOL isDecrypted; @property (assign) BOOL decrypted;
@end @end
@@ -50,8 +50,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
- (id)initWithVersion:(MPDatabaseVersion)version { - (id)initWithVersion:(MPDatabaseVersion)version {
self = [super init]; self = [super init];
if(self) { if(self) {
_isDecrypted = YES; _decrypted = YES;
_isProtected = NO; _secured = NO;
_locked = NO;
switch(version) { switch(version) {
case MPDatabaseVersion3: case MPDatabaseVersion3:
_tree = [Kdb3Tree newTemplateTree]; _tree = [Kdb3Tree newTemplateTree];
@@ -92,12 +93,12 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
} }
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError { - (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
self.isDecrypted = NO; self.decrypted = NO;
return YES; return YES;
} }
- (BOOL)isEntireFileLoaded { - (BOOL)isEntireFileLoaded {
return _isDecrypted; return _decrypted;
} }
#pragma mark Protection #pragma mark Protection
@@ -117,7 +118,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
else if( [self.tree isKindOfClass:[Kdb3Tree class]]) { else if( [self.tree isKindOfClass:[Kdb3Tree class]]) {
self.version = MPDatabaseVersion3; self.version = MPDatabaseVersion3;
} }
_isDecrypted = YES; _decrypted = YES;
return YES; return YES;
} }
@@ -125,7 +126,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
if(![_password isEqualToString:password]) { if(![_password isEqualToString:password]) {
[_password release]; [_password release];
_password = [password retain]; _password = [password retain];
self.isProtected = ([_password length] > 0); _secured |= ([_password length] > 0);
} }
} }
@@ -133,7 +134,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
if(![[_key absoluteString] isEqualToString:[key absoluteString]]) { if(![[_key absoluteString] isEqualToString:[key absoluteString]]) {
[_key release]; [_key release];
_key = [key retain]; _key = [key retain];
self.isProtected = (_key != nil); _secured |= (_key != nil);
} }
} }

View File

@@ -172,7 +172,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
if( itemAction == [MPActionHelper actionOfType:MPActionLock]) { if( itemAction == [MPActionHelper actionOfType:MPActionLock]) {
MPDocument *document = [self document]; MPDocument *document = [self document];
BOOL showsNoLockScreen = (nil == [[_passwordInputController view] superview]); BOOL showsNoLockScreen = (nil == [[_passwordInputController view] superview]);
return showsNoLockScreen && document.isProtected; return showsNoLockScreen && document.isSecured;
} }
if(itemAction == [MPActionHelper actionOfType:MPActionAddEntry]) { if(itemAction == [MPActionHelper actionOfType:MPActionAddEntry]) {
return (nil != _outlineViewController.outlineDelegate.selectedGroup); return (nil != _outlineViewController.outlineDelegate.selectedGroup);
@@ -203,7 +203,14 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
} }
- (void)lock:(id)sender { - (void)lock:(id)sender {
// Test if document is lockable MPDocument *document = [self document];
if(!document.isSecured) {
return; // Document needs a password/keyfile to be lockable
}
if(document.isLocked) {
return; // Document already locked
}
document.locked = YES;
[self showPasswordInput]; [self showPasswordInput];
} }
@@ -286,6 +293,10 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
[inspectorView removeFromSuperview]; [inspectorView removeFromSuperview];
} }
[contentView layout]; [contentView layout];
MPDocument *document = [self document];
document.locked = NO;
[_entryViewController updateResponderChain]; [_entryViewController updateResponderChain];
[_inspectorViewController updateResponderChain]; [_inspectorViewController updateResponderChain];
[_outlineViewController updateResponderChain]; [_outlineViewController updateResponderChain];

View File

@@ -78,9 +78,13 @@ NSString *const MPShouldLockDatabaseNotification = @"com.hicknhack.macpass.MPSho
idleCheckTimer = nil; idleCheckTimer = nil;
} }
else { else {
[idleCheckTimer invalidate]; if( idleCheckTimer ) {
[idleCheckTimer release]; NSAssert([idleCheckTimer isValid], @"Timer needs to be valid");
idleCheckTimer = [[NSTimer timerWithTimeInterval:15 target:self selector:@selector(_checkIdleTime:) userInfo:nil repeats:YES] retain]; [idleCheckTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:_idleLockTime ]];
return; // Done
}
/* Create new timer and schedule it with runloop */
idleCheckTimer = [[NSTimer timerWithTimeInterval:_idleLockTime target:self selector:@selector(_checkIdleTime:) userInfo:nil repeats:YES] retain];
[[NSRunLoop mainRunLoop] addTimer:idleCheckTimer forMode:NSDefaultRunLoopMode]; [[NSRunLoop mainRunLoop] addTimer:idleCheckTimer forMode:NSDefaultRunLoopMode];
} }
} }
@@ -94,6 +98,11 @@ NSString *const MPShouldLockDatabaseNotification = @"com.hicknhack.macpass.MPSho
CFTimeInterval interval = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState,kCGAnyInputEventType); CFTimeInterval interval = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState,kCGAnyInputEventType);
if(interval >= _idleLockTime) { if(interval >= _idleLockTime) {
[[NSApp delegate] lockAllDocuments]; [[NSApp delegate] lockAllDocuments];
/* Reset the timer to full intervall */
[idleCheckTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:_idleLockTime]];
}
else {
[idleCheckTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:(_idleLockTime - interval) ]];
} }
} }

View File

@@ -48,7 +48,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1000</string> <string>1007</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string> <string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>