From 491569ba2e7804aa4148b8ef3ab0fa354ff9100b Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 18 Jun 2013 00:11:27 +0200 Subject: [PATCH] added more infrastructure for KeepassHttp --- MacPass.xcodeproj/project.pbxproj | 24 ++++--- MacPass/MPAssociateRequestHandler.m | 1 - MacPass/MPConnection.m | 5 +- MacPass/MPDocument.h | 4 ++ MacPass/MPDocument.m | 13 +++- MacPass/MPDocumentQueryService.h | 20 ++++++ MacPass/MPDocumentQueryService.m | 69 +++++++++++++++++++ MacPass/MPRequestHandlerService.h | 2 + MacPass/MPRequestHandlerService.m | 9 ++- ...lder.h => MPTestAssociateRequestHandler.h} | 2 +- MacPass/MPTestAssociateRequestHandler.m | 26 +++++++ MacPass/MPTestAssociateRequestHanlder.m | 21 ------ MacPass/MacPass-Info.plist | 2 +- 13 files changed, 160 insertions(+), 38 deletions(-) create mode 100644 MacPass/MPDocumentQueryService.h create mode 100644 MacPass/MPDocumentQueryService.m rename MacPass/{MPTestAssociateRequestHanlder.h => MPTestAssociateRequestHandler.h} (80%) create mode 100644 MacPass/MPTestAssociateRequestHandler.m delete mode 100644 MacPass/MPTestAssociateRequestHanlder.m diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index a5774e02..0f98ee73 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -134,6 +134,7 @@ 4CA0B2ED15BCADAC00654E32 /* SettingsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CA0B2EC15BCADAC00654E32 /* SettingsWindow.xib */; }; 4CA0B2F915BCAF6700654E32 /* MPGeneralSettingsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA0B2F815BCAF6700654E32 /* MPGeneralSettingsController.m */; }; 4CA0B2FC15BCAF8600654E32 /* MPSettingsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA0B2FB15BCAF8600654E32 /* MPSettingsWindowController.m */; }; + 4CA0E3A7176FAF99004D18CB /* MPDocumentQueryService.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA0E3A6176FAF99004D18CB /* MPDocumentQueryService.m */; }; 4CA2335A176DBFE100F0B6AC /* MPLockDaemon.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CA23359176DBFE100F0B6AC /* MPLockDaemon.m */; }; 4CAD747B15B887FD00104512 /* DDXMLElementAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAD745715B887FD00104512 /* DDXMLElementAdditions.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; 4CAD747C15B887FD00104512 /* NSString+DDXML.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CAD745A15B887FD00104512 /* NSString+DDXML.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; @@ -147,7 +148,7 @@ 4CBA2ABA17074C07006D8139 /* MPSettingsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */; }; 4CC1AEBE16D4467C006D2AAB /* KdbTree+MPAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC1AEBD16D4467C006D2AAB /* KdbTree+MPAdditions.m */; }; 4CC299FF176F99E50050C939 /* MPRequestHandlerService.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC299FE176F99E50050C939 /* MPRequestHandlerService.m */; }; - 4CC29A02176F9D140050C939 /* MPTestAssociateRequestHanlder.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC29A01176F9D140050C939 /* MPTestAssociateRequestHanlder.m */; }; + 4CC29A02176F9D140050C939 /* MPTestAssociateRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC29A01176F9D140050C939 /* MPTestAssociateRequestHandler.m */; }; 4CC3AABD175F4983003EF01B /* HNHRoundedTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC3AAB9175F4983003EF01B /* HNHRoundedTextFieldCell.m */; }; 4CC6259115BA1C99002F5B11 /* MPOutlineViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC6259015BA1C99002F5B11 /* MPOutlineViewDelegate.m */; }; 4CD78ABC16D155FF00768A1D /* 07_NotepadTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CD78AB716D155FF00768A1D /* 07_NotepadTemplate.pdf */; }; @@ -428,6 +429,8 @@ 4CA0B2FA15BCAF8600654E32 /* MPSettingsWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSettingsWindowController.h; sourceTree = ""; }; 4CA0B2FB15BCAF8600654E32 /* MPSettingsWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSettingsWindowController.m; sourceTree = ""; }; 4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPSettingsTab.h; sourceTree = ""; }; + 4CA0E3A5176FAF99004D18CB /* MPDocumentQueryService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPDocumentQueryService.h; sourceTree = ""; }; + 4CA0E3A6176FAF99004D18CB /* MPDocumentQueryService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPDocumentQueryService.m; sourceTree = ""; }; 4CA23357176DB8F000F0B6AC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/GeneralSettings.strings; sourceTree = ""; }; 4CA23358176DBFE100F0B6AC /* MPLockDaemon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPLockDaemon.h; sourceTree = ""; }; 4CA23359176DBFE100F0B6AC /* MPLockDaemon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPLockDaemon.m; sourceTree = ""; }; @@ -454,8 +457,8 @@ 4CC1AEBD16D4467C006D2AAB /* KdbTree+MPAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "KdbTree+MPAdditions.m"; sourceTree = ""; }; 4CC299FD176F99E50050C939 /* MPRequestHandlerService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPRequestHandlerService.h; sourceTree = ""; }; 4CC299FE176F99E50050C939 /* MPRequestHandlerService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPRequestHandlerService.m; sourceTree = ""; }; - 4CC29A00176F9D140050C939 /* MPTestAssociateRequestHanlder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTestAssociateRequestHanlder.h; sourceTree = ""; }; - 4CC29A01176F9D140050C939 /* MPTestAssociateRequestHanlder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPTestAssociateRequestHanlder.m; sourceTree = ""; }; + 4CC29A00176F9D140050C939 /* MPTestAssociateRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPTestAssociateRequestHandler.h; sourceTree = ""; }; + 4CC29A01176F9D140050C939 /* MPTestAssociateRequestHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPTestAssociateRequestHandler.m; sourceTree = ""; }; 4CC3AAB8175F4983003EF01B /* HNHRoundedTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHRoundedTextFieldCell.h; sourceTree = ""; }; 4CC3AAB9175F4983003EF01B /* HNHRoundedTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HNHRoundedTextFieldCell.m; sourceTree = ""; }; 4CC6258F15BA1C99002F5B11 /* MPOutlineViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOutlineViewDelegate.h; sourceTree = ""; }; @@ -659,7 +662,7 @@ path = Extensions; sourceTree = ""; }; - 4C245C11176E22150086100E /* Server */ = { + 4C245C11176E22150086100E /* KeepassHttp */ = { isa = PBXGroup; children = ( 4CF78055176E5CFD0032EE71 /* MPConnection.h */, @@ -668,12 +671,14 @@ 4CF7805C176E71170032EE71 /* MPServerDaemon.m */, 4CF6C716176F5234007A811D /* MPAssociateRequestHandler.h */, 4CF6C717176F5234007A811D /* MPAssociateRequestHandler.m */, - 4CC29A00176F9D140050C939 /* MPTestAssociateRequestHanlder.h */, - 4CC29A01176F9D140050C939 /* MPTestAssociateRequestHanlder.m */, + 4CC29A00176F9D140050C939 /* MPTestAssociateRequestHandler.h */, + 4CC29A01176F9D140050C939 /* MPTestAssociateRequestHandler.m */, 4CC299FD176F99E50050C939 /* MPRequestHandlerService.h */, 4CC299FE176F99E50050C939 /* MPRequestHandlerService.m */, + 4CA0E3A5176FAF99004D18CB /* MPDocumentQueryService.h */, + 4CA0E3A6176FAF99004D18CB /* MPDocumentQueryService.m */, ); - name = Server; + name = KeepassHttp; sourceTree = ""; }; 4C2C4C2516D3BCEA00D49295 /* KeePassLibAdditions */ = { @@ -922,7 +927,7 @@ 4C77E36C15B84A240093A587 /* MacPass */ = { isa = PBXGroup; children = ( - 4C245C11176E22150086100E /* Server */, + 4C245C11176E22150086100E /* KeepassHttp */, 4C46B8821706397A0046109A /* Security Additions */, 4C2C4C2516D3BCEA00D49295 /* KeePassLibAdditions */, 4C2E382016D141F700037A9D /* Helper */, @@ -1382,7 +1387,8 @@ 4CF6C711176F4533007A811D /* MPStringLengthValueTransformer.m in Sources */, 4CF6C718176F5234007A811D /* MPAssociateRequestHandler.m in Sources */, 4CC299FF176F99E50050C939 /* MPRequestHandlerService.m in Sources */, - 4CC29A02176F9D140050C939 /* MPTestAssociateRequestHanlder.m in Sources */, + 4CC29A02176F9D140050C939 /* MPTestAssociateRequestHandler.m in Sources */, + 4CA0E3A7176FAF99004D18CB /* MPDocumentQueryService.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MacPass/MPAssociateRequestHandler.m b/MacPass/MPAssociateRequestHandler.m index 31aac9b8..d3c13d35 100644 --- a/MacPass/MPAssociateRequestHandler.m +++ b/MacPass/MPAssociateRequestHandler.m @@ -15,7 +15,6 @@ } - (void)respondTo:(NSDictionary *)data { - // todo; } @end diff --git a/MacPass/MPConnection.m b/MacPass/MPConnection.m index f0dfb027..d42026e0 100644 --- a/MacPass/MPConnection.m +++ b/MacPass/MPConnection.m @@ -32,7 +32,7 @@ NSString *const MPRequestTypeKey = @"RequestType"; // See also: expectsRequestBodyFromMethod:atPath: if([method isEqualToString:@"POST"]) { - return YES; + return (requestContentLength < 500); } return [super supportsMethod:method atPath:path]; } @@ -55,6 +55,9 @@ NSString *const MPRequestTypeKey = @"RequestType"; } - (void)processBodyData:(NSData *)postDataChunk { + /* + Store the data in the message body + */ [request appendData:postDataChunk]; } diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 03102414..96cde642 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -20,6 +20,7 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; @class KdbGroup; @class KdbEntry; +@class UUID; @interface MPDocument : NSDocument @@ -33,6 +34,9 @@ APPKIT_EXTERN NSString *const MPDocumentGroupKey; - (id)initWithVersion:(MPDatabaseVersion)version; - (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL; +/* Lookup */ +- (KdbEntry *)findEntry:(UUID *)uuid; + /* Undoable Intiialization of elements */ - (KdbGroup *)createGroup:(KdbGroup *)parent; - (KdbEntry *)createEntry:(KdbGroup *)parent; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index c7c7400a..64ff19ce 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -15,6 +15,7 @@ #import "MPDatabaseVersion.h" #import "KdbGroup+Undo.h" #import "KdbGroup+KVOAdditions.h" +#import "KdbGroup+MPTreeTools.h" #import "KdbEntry+Undo.h" NSString *const MPDocumentDidAddGroupNotification = @"MPDocumentDidAddGroupNotification"; @@ -43,7 +44,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; { return [self initWithVersion:MPDatabaseVersion4]; } - +#pragma mark NSDocument essentials - (id)initWithVersion:(MPDatabaseVersion)version { self = [super init]; if(self) { @@ -67,7 +68,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; return self; } -- (void) makeWindowControllers { +- (void)makeWindowControllers { MPDocumentWindowController *windowController = [[MPDocumentWindowController alloc] init]; [self addWindowController:windowController]; [windowController release]; @@ -100,6 +101,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; return _isDecrypted; } +#pragma mark Protection - (BOOL)decryptWithPassword:(NSString *)password keyFileURL:(NSURL *)keyFileURL { self.password = password; @try { @@ -146,10 +148,17 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; return NO; } +#pragma mark Data Accesors - (KdbGroup *)root { return [self.tree root]; } +- (KdbEntry *)findEntry:(UUID *)uuid { + return [self.root entryForUUID:uuid]; +} + + +#pragma mark Data manipulation - (KdbEntry *)createEntry:(KdbGroup *)parent { KdbEntry *newEntry = [self.tree createEntry:parent]; newEntry.title = NSLocalizedString(@"DEFAULT_ENTRY_TITLE", @"Title for a newly created entry"); diff --git a/MacPass/MPDocumentQueryService.h b/MacPass/MPDocumentQueryService.h new file mode 100644 index 00000000..c94e4910 --- /dev/null +++ b/MacPass/MPDocumentQueryService.h @@ -0,0 +1,20 @@ +// +// MPDocumentQueryService.h +// MacPass +// +// Created by Michael Starke on 17.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +@class KdbEntry; + +@interface MPDocumentQueryService : NSObject + ++ (MPDocumentQueryService *)defaultService; + +- (KdbEntry *)configurationEntry; +- (KdbEntry *)createConfigurationEntry; + +@end diff --git a/MacPass/MPDocumentQueryService.m b/MacPass/MPDocumentQueryService.m new file mode 100644 index 00000000..8fdf613a --- /dev/null +++ b/MacPass/MPDocumentQueryService.m @@ -0,0 +1,69 @@ +// +// MPDocumentQueryService.m +// MacPass +// +// Created by Michael Starke on 17.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "MPDocumentQueryService.h" +#import "MPDocument.h" +#import "UUID.h" + +@interface MPDocumentQueryService () { +@private + UUID *rootUuid; +} + +@end + +@implementation MPDocumentQueryService + ++ (MPDocumentQueryService *)defaultService { + static id instance; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + instance = [[MPDocumentQueryService alloc] init]; + }); + return instance; +} + +- (id)init { + self = [super init]; + if (self) { + static const Byte uuidBytes[] = { + 0x34, 0x69, 0x7a, 0x40, 0x8a, 0x5b, 0x41, 0xc0, + 0x9f, 0x36, 0x89, 0x7d, 0x62, 0x3e, 0xcb, 0x31 + }; + NSData *data = [NSData dataWithBytes:uuidBytes length:16]; + rootUuid = [[UUID alloc] initWithData:data]; + } + return self; +} + +- (void)dealloc +{ + [rootUuid release]; + [super dealloc]; +} + +- (KdbEntry *)configurationEntry { + /* + We are looking in all document, + but only store the key in one. + */ + NSArray *documents = [[NSDocumentController sharedDocumentController] documents]; + for(MPDocument *document in documents) { + KdbEntry *entry = [document findEntry:rootUuid]; + if(entry) { + return entry; + } + } + return nil; +} + +- (KdbEntry *)createConfigurationEntry { + return nil; +} + +@end diff --git a/MacPass/MPRequestHandlerService.h b/MacPass/MPRequestHandlerService.h index 088cd325..7bf232d6 100644 --- a/MacPass/MPRequestHandlerService.h +++ b/MacPass/MPRequestHandlerService.h @@ -22,4 +22,6 @@ FOUNDATION_EXPORT NSString *const MPRequestTypeGeneratePassword; + (id)requestHandler:(NSString *)identifier; ++ (BOOL)validKeyProposal; + @end diff --git a/MacPass/MPRequestHandlerService.m b/MacPass/MPRequestHandlerService.m index d13a3547..afd8599f 100644 --- a/MacPass/MPRequestHandlerService.m +++ b/MacPass/MPRequestHandlerService.m @@ -9,7 +9,7 @@ #import "MPRequestHandlerService.h" #import "MPServerRequestHandler.h" #import "MPAssociateRequestHandler.h" -#import "MPTestAssociateRequestHanlder.h" +#import "MPTestAssociateRequestHandler.h" //NSString *const MPRequestTypeAssociate = @"associate"; //NSString *const MPRequestTypeTestAssociate = @"test-associate"; @@ -36,13 +36,18 @@ NSString *const MPRequestTypeGeneratePassword = @"generate-password"; + (NSDictionary *)_setupHandlerDictionary { MPAssociateRequestHandler *associateHandler = [[MPAssociateRequestHandler alloc] init]; - MPTestAssociateRequestHanlder *testAssociateHandler = [[MPTestAssociateRequestHanlder alloc] init]; + MPTestAssociateRequestHandler *testAssociateHandler = [[MPTestAssociateRequestHandler alloc] init]; NSDictionary *handlerDict = @{ [associateHandler identifier] : associateHandler, [testAssociateHandler identifier] : testAssociateHandler }; [associateHandler release]; + [testAssociateHandler release]; return handlerDict; } ++ (BOOL)validKeyProposal { + return NO; +} + @end diff --git a/MacPass/MPTestAssociateRequestHanlder.h b/MacPass/MPTestAssociateRequestHandler.h similarity index 80% rename from MacPass/MPTestAssociateRequestHanlder.h rename to MacPass/MPTestAssociateRequestHandler.h index df4f9f2a..201744cf 100644 --- a/MacPass/MPTestAssociateRequestHanlder.h +++ b/MacPass/MPTestAssociateRequestHandler.h @@ -9,6 +9,6 @@ #import #import "MPServerRequestHandler.h" -@interface MPTestAssociateRequestHanlder : NSObject +@interface MPTestAssociateRequestHandler : NSObject @end diff --git a/MacPass/MPTestAssociateRequestHandler.m b/MacPass/MPTestAssociateRequestHandler.m new file mode 100644 index 00000000..ab1f29b3 --- /dev/null +++ b/MacPass/MPTestAssociateRequestHandler.m @@ -0,0 +1,26 @@ +// +// MPTestAssociateRequestHanlder.m +// MacPass +// +// Created by Michael Starke on 17.06.13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "MPTestAssociateRequestHandler.h" +#import "MPDocumentQueryService.h" + +@implementation MPTestAssociateRequestHandler + +- (NSString *)identifier { + return @"test-associate"; +} + +- (void)respondTo:(NSDictionary *)data { + MPDocumentQueryService *service = [MPDocumentQueryService defaultService]; + if(![service configurationEntry]) { + return; //Nothing to do + } + //TestRequestedData +} + +@end diff --git a/MacPass/MPTestAssociateRequestHanlder.m b/MacPass/MPTestAssociateRequestHanlder.m deleted file mode 100644 index c8059ee2..00000000 --- a/MacPass/MPTestAssociateRequestHanlder.m +++ /dev/null @@ -1,21 +0,0 @@ -// -// MPTestAssociateRequestHanlder.m -// MacPass -// -// Created by Michael Starke on 17.06.13. -// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. -// - -#import "MPTestAssociateRequestHanlder.h" - -@implementation MPTestAssociateRequestHanlder - -- (NSString *)identifier { - return @"test-associate"; -} - -- (void)respondTo:(NSDictionary *)data { - -} - -@end diff --git a/MacPass/MacPass-Info.plist b/MacPass/MacPass-Info.plist index a281cc69..c1f34798 100644 --- a/MacPass/MacPass-Info.plist +++ b/MacPass/MacPass-Info.plist @@ -48,7 +48,7 @@ CFBundleSignature ???? CFBundleVersion - 573 + 579 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSHumanReadableCopyright