Skip to content

Commit

Permalink
Updated to current KeePassKit
Browse files Browse the repository at this point in the history
  • Loading branch information
mstarke committed Sep 9, 2020
1 parent 171d6e4 commit f626266
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "sparkle-project/Sparkle" ~> 1.22
github "MacPass/TransformerKit" "b28de3a7de9249dd886979cae4985092523b6dd1"
github "MacPass/KeePassKit" ~> 2.4
github "MacPass/KeePassKit" "86266c8211b19f50a55bfdfd293adc783fb0a7b1"
github "mstarke/HNHUi" ~> 3.0
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github "MacPass/KeePassKit" "2.4.7"
github "MacPass/KeePassKit" "86266c8211b19f50a55bfdfd293adc783fb0a7b1"
github "MacPass/TransformerKit" "b28de3a7de9249dd886979cae4985092523b6dd1"
github "mstarke/HNHUi" "3.0"
github "robbiehanson/KissXML" "5.3.1"
github "sparkle-project/Sparkle" "1.22.0"
github "sparkle-project/Sparkle" "v1.23.0"
2 changes: 1 addition & 1 deletion MacPass/MPAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
- (void)menuNeedsUpdate:(NSMenu *)menu {
if(menu == self.saveMenuItem.menu) {
MPDocument *document = NSDocumentController.sharedDocumentController.currentDocument;
BOOL displayDots = (document.fileURL == nil || !document.compositeKey.hasPasswordOrKeyFile);
BOOL displayDots = (document.fileURL == nil || !document.compositeKey.hasKeys);
NSString *saveTitle = displayDots ? NSLocalizedString(@"SAVE_WITH_DOTS", "Save file menu item title when save will prompt for a location to save or ask for a password/key") : NSLocalizedString(@"SAVE", "Save file menu item title when save will just save the file");
self.saveMenuItem.title = saveTitle;
}
Expand Down
25 changes: 14 additions & 11 deletions MacPass/MPDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ - (BOOL)checkAutosavingSafetyAndReturnError:(NSError **)outError {
if(self.encryptedData) {
return YES;
}
if(self.compositeKey.hasPasswordOrKeyFile) {
if(self.compositeKey.hasKeys) {
return YES; // key is set, so autosave should be save
}

Expand Down Expand Up @@ -186,7 +186,7 @@ - (NSData *)dataOfType:(NSString *)typeName error:(NSError * _Nullable __autorel
NSLog(@"%@ should not be called on locked databases!", NSStringFromSelector(_cmd));
return self.encryptedData;
}
if(!self.compositeKey.hasPasswordOrKeyFile) {
if(!self.compositeKey.hasKeys) {
if(outError != NULL) {
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: NSLocalizedString(@"WARNING_ON_SAVE_NO_PASSWORD_OR_KEY_SET", "") };
*outError = [NSError errorWithDomain:MPDefaultErrorDomain code:0 userInfo:userInfo];
Expand Down Expand Up @@ -421,7 +421,9 @@ - (void)_mergeWithContentsFromURL:(NSURL *)url key:(KPKCompositeKey *)key option
[self.windowForSheet endSheet:sheet returnCode:(didCancel ? NSModalResponseCancel : NSModalResponseOK)];
if(!didCancel) {
NSData *keyFileData = keyURL ? [NSData dataWithContentsOfURL:keyURL] : nil;
KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] initWithPassword:password keyFileData:keyFileData];
KPKCompositeKey *compositeKey = [[KPKCompositeKey alloc] init];
[compositeKey addKey:[KPKKey keyWithPassword:password]];
[compositeKey addKey:[KPKKey keyWithKeyFileData:keyFileData]];
[self _mergeWithContentsFromURL:url key:compositeKey options:options];
}
// just return yes regardless since we will display the sheet again if needed!
Expand Down Expand Up @@ -490,7 +492,10 @@ - (void)_lockDatabaseForDocument:(NSDocument *)document didSave:(BOOL)didSave co
- (BOOL)unlockWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL error:(NSError *__autoreleasing*)error{
// TODO: Make this API asynchronous
NSData *keyFileData = keyFileURL ? [NSData dataWithContentsOfURL:keyFileURL] : nil;
self.compositeKey = [[KPKCompositeKey alloc] initWithPassword:password keyFileData:keyFileData];

self.compositeKey = [[KPKCompositeKey alloc] init];
[self.compositeKey addKey:[KPKKey keyWithPassword:password]];
[self.compositeKey addKey:[KPKKey keyWithKeyFileData:keyFileData]];
self.tree = [[KPKTree alloc] initWithData:self.encryptedData key:self.compositeKey error:error];

BOOL isUnlocked = (nil != self.tree);
Expand All @@ -514,13 +519,11 @@ - (BOOL)changePassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL {
return NO;
}
NSData *keyFileData = keyFileURL ? [NSData dataWithContentsOfURL:keyFileURL] : nil;
if(!self.compositeKey) {
self.compositeKey = [[KPKCompositeKey alloc] initWithPassword:password keyFileData:keyFileData];
}
else {
[self.compositeKey setPassword:password andKeyFileData:keyFileData];
}
self.tree.metaData.masterKeyChanged = [NSDate date];
self.compositeKey = [[KPKCompositeKey alloc] init];
[self.compositeKey addKey:[KPKKey keyWithPassword:password]];
[self.compositeKey addKey:[KPKKey keyWithKeyFileData:keyFileData]];

self.tree.metaData.masterKeyChanged = NSDate.date;
/* Key change is not undoable so just recored the change as done */
[self updateChangeCount:NSChangeDone];
/*
Expand Down

0 comments on commit f626266

Please sign in to comment.