mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 20:32:43 +00:00
Optimized Locking timer
Disabled re-locking of already locked documents Disabled locking of documents without a password
This commit is contained in:
@@ -25,13 +25,18 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey;
|
||||
|
||||
@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 (assign, readonly) KdbGroup *root;
|
||||
@property (nonatomic,retain) NSString *password;
|
||||
@property (nonatomic, retain) NSURL *key;
|
||||
@property (assign, readonly) MPDatabaseVersion version;
|
||||
@property (assign, readonly) BOOL isDecrypted;
|
||||
|
||||
|
||||
- (id)initWithVersion:(MPDatabaseVersion)version;
|
||||
- (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL;
|
||||
|
||||
@@ -31,11 +31,11 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
|
||||
@interface MPDocument ()
|
||||
|
||||
@property (assign, nonatomic) BOOL isProtected;
|
||||
@property (assign, nonatomic) BOOL secured;
|
||||
@property (retain) KdbTree *tree;
|
||||
@property (nonatomic, readonly) KdbPassword *passwordHash;
|
||||
@property (assign) MPDatabaseVersion version;
|
||||
@property (assign) BOOL isDecrypted;
|
||||
@property (assign) BOOL decrypted;
|
||||
|
||||
@end
|
||||
|
||||
@@ -50,8 +50,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
- (id)initWithVersion:(MPDatabaseVersion)version {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_isDecrypted = YES;
|
||||
_isProtected = NO;
|
||||
_decrypted = YES;
|
||||
_secured = NO;
|
||||
_locked = NO;
|
||||
switch(version) {
|
||||
case MPDatabaseVersion3:
|
||||
_tree = [Kdb3Tree newTemplateTree];
|
||||
@@ -92,12 +93,12 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
}
|
||||
|
||||
- (BOOL)readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
|
||||
self.isDecrypted = NO;
|
||||
self.decrypted = NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)isEntireFileLoaded {
|
||||
return _isDecrypted;
|
||||
return _decrypted;
|
||||
}
|
||||
|
||||
#pragma mark Protection
|
||||
@@ -117,7 +118,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
else if( [self.tree isKindOfClass:[Kdb3Tree class]]) {
|
||||
self.version = MPDatabaseVersion3;
|
||||
}
|
||||
_isDecrypted = YES;
|
||||
_decrypted = YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -125,7 +126,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey";
|
||||
if(![_password isEqualToString:password]) {
|
||||
[_password release];
|
||||
_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]]) {
|
||||
[_key release];
|
||||
_key = [key retain];
|
||||
self.isProtected = (_key != nil);
|
||||
_secured |= (_key != nil);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
|
||||
if( itemAction == [MPActionHelper actionOfType:MPActionLock]) {
|
||||
MPDocument *document = [self document];
|
||||
BOOL showsNoLockScreen = (nil == [[_passwordInputController view] superview]);
|
||||
return showsNoLockScreen && document.isProtected;
|
||||
return showsNoLockScreen && document.isSecured;
|
||||
}
|
||||
if(itemAction == [MPActionHelper actionOfType:MPActionAddEntry]) {
|
||||
return (nil != _outlineViewController.outlineDelegate.selectedGroup);
|
||||
@@ -203,7 +203,14 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
|
||||
}
|
||||
|
||||
- (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];
|
||||
}
|
||||
|
||||
@@ -286,6 +293,10 @@ NSString *const MPCurrentItemChangedNotification = @"com.hicknhack.macpass.MPCur
|
||||
[inspectorView removeFromSuperview];
|
||||
}
|
||||
[contentView layout];
|
||||
|
||||
MPDocument *document = [self document];
|
||||
document.locked = NO;
|
||||
|
||||
[_entryViewController updateResponderChain];
|
||||
[_inspectorViewController updateResponderChain];
|
||||
[_outlineViewController updateResponderChain];
|
||||
|
||||
@@ -78,9 +78,13 @@ NSString *const MPShouldLockDatabaseNotification = @"com.hicknhack.macpass.MPSho
|
||||
idleCheckTimer = nil;
|
||||
}
|
||||
else {
|
||||
[idleCheckTimer invalidate];
|
||||
[idleCheckTimer release];
|
||||
idleCheckTimer = [[NSTimer timerWithTimeInterval:15 target:self selector:@selector(_checkIdleTime:) userInfo:nil repeats:YES] retain];
|
||||
if( idleCheckTimer ) {
|
||||
NSAssert([idleCheckTimer isValid], @"Timer needs to be valid");
|
||||
[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];
|
||||
}
|
||||
}
|
||||
@@ -94,6 +98,11 @@ NSString *const MPShouldLockDatabaseNotification = @"com.hicknhack.macpass.MPSho
|
||||
CFTimeInterval interval = CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateCombinedSessionState,kCGAnyInputEventType);
|
||||
if(interval >= _idleLockTime) {
|
||||
[[NSApp delegate] lockAllDocuments];
|
||||
/* Reset the timer to full intervall */
|
||||
[idleCheckTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:_idleLockTime]];
|
||||
}
|
||||
else {
|
||||
[idleCheckTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:(_idleLockTime - interval) ]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1000</string>
|
||||
<string>1007</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
Reference in New Issue
Block a user