diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h
index 9a536636..b97d55dd 100644
--- a/MacPass/MPDocument.h
+++ b/MacPass/MPDocument.h
@@ -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;
diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m
index 4e93fac7..408f3e44 100644
--- a/MacPass/MPDocument.m
+++ b/MacPass/MPDocument.m
@@ -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);
}
}
diff --git a/MacPass/MPDocumentWindowController.m b/MacPass/MPDocumentWindowController.m
index e1a9d86e..f43e75e1 100644
--- a/MacPass/MPDocumentWindowController.m
+++ b/MacPass/MPDocumentWindowController.m
@@ -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];
diff --git a/MacPass/MPLockDaemon.m b/MacPass/MPLockDaemon.m
index e9de529c..fd65b82a 100644
--- a/MacPass/MPLockDaemon.m
+++ b/MacPass/MPLockDaemon.m
@@ -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) ]];
}
}
diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist
index 4e3fee16..1e2d64b2 100644
--- a/MacPass/MacPass-Info.plist
+++ b/MacPass/MacPass-Info.plist
@@ -48,7 +48,7 @@
CFBundleSignature
????
CFBundleVersion
- 1000
+ 1007
LSMinimumSystemVersion
${MACOSX_DEPLOYMENT_TARGET}
NSHumanReadableCopyright