mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-23 05:29:26 +00:00
Removed CocoaHTTP server, KeePassHTTP Plugin will bring it's own server
Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
@@ -29,7 +29,6 @@
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPLockDaemon.h"
|
||||
#import "MPPasswordCreatorViewController.h"
|
||||
#import "MPServerDaemon.h"
|
||||
#import "MPSettingsHelper.h"
|
||||
#import "MPSettingsWindowController.h"
|
||||
#import "MPStringLengthValueTransformer.h"
|
||||
@@ -42,7 +41,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
||||
|
||||
@interface MPAppDelegate () {
|
||||
@private
|
||||
MPServerDaemon *serverDaemon;
|
||||
MPLockDaemon *lockDaemon;
|
||||
MPDockTileHelper *dockTileHelper;
|
||||
BOOL _shouldOpenFile; // YES if app was started to open a
|
||||
@@ -155,7 +153,6 @@ NSString *const MPDidChangeStoredKeyFilesSettings = @"com.hicknhack.macpass.MPDi
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
||||
serverDaemon = [[MPServerDaemon alloc] init];
|
||||
lockDaemon = [[MPLockDaemon alloc] init];
|
||||
self.autotypeDaemon = [[MPAutotypeDaemon alloc] init];
|
||||
//dockTileHelper = [[MPDockTileHelper alloc] init];
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
//
|
||||
// MPAssociateRequestHandler.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MPServerRequestHandling.h"
|
||||
|
||||
@interface MPAssociateRequestHandler : NSObject <MPServerRequestHandling>
|
||||
|
||||
@end
|
||||
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// MPAssociateRequestHandler.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPAssociateRequestHandler.h"
|
||||
|
||||
@implementation MPAssociateRequestHandler
|
||||
|
||||
- (NSString *)identifier {
|
||||
return @"associate";
|
||||
}
|
||||
|
||||
- (void)respondTo:(NSDictionary *)data {
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,17 +0,0 @@
|
||||
//
|
||||
// MPConnection.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 16.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "HTTPConnection.h"
|
||||
|
||||
/**
|
||||
* Default Connection to handle the KeepassHttp POST requests. The Connection doesn't do anything,
|
||||
* besides using the MPRequestHandlerService to handle any request from KeePassHttp and sends back the replies
|
||||
*/
|
||||
@interface MPConnection : HTTPConnection
|
||||
|
||||
@end
|
||||
@@ -1,74 +0,0 @@
|
||||
//
|
||||
// MPConnection.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 16.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPConnection.h"
|
||||
#import "HTTPMessage.h"
|
||||
#import "MPRequestHandlerService.h"
|
||||
#import "MPServerRequestHandling.h"
|
||||
|
||||
|
||||
NSString *const MPRequestTypeKey = @"RequestType";
|
||||
|
||||
@implementation MPConnection
|
||||
|
||||
- (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path
|
||||
{
|
||||
// Override me to support methods such as POST.
|
||||
//
|
||||
// Things you may want to consider:
|
||||
// - Does the given path represent a resource that is designed to accept this method?
|
||||
// - If accepting an upload, is the size of the data being uploaded too big?
|
||||
// To do this you can check the requestContentLength variable.
|
||||
//
|
||||
// For more information, you can always access the HTTPMessage request variable.
|
||||
//
|
||||
// You should fall through with a call to [super supportsMethod:method atPath:path]
|
||||
//
|
||||
// See also: expectsRequestBodyFromMethod:atPath:
|
||||
|
||||
if([method isEqualToString:@"POST"]) {
|
||||
return (requestContentLength < 500);
|
||||
}
|
||||
return [super supportsMethod:method atPath:path];
|
||||
}
|
||||
|
||||
- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path {
|
||||
|
||||
NSError *error = nil;
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:[request body] options:0 error:&error];
|
||||
if(error) {
|
||||
NSLog(@"Error while parsing JSON request data:%@", [error localizedDescription]);
|
||||
}
|
||||
if([obj isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *requestDict = obj;
|
||||
[self _parseRequest:requestDict];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Wrong Request format. Unable to use JSON data");
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)processBodyData:(NSData *)postDataChunk {
|
||||
/*
|
||||
Store the data in the message body
|
||||
*/
|
||||
[request appendData:postDataChunk];
|
||||
}
|
||||
|
||||
|
||||
- (void)_parseRequest:(NSDictionary *)aRequest {
|
||||
/* TODO: generate a response */
|
||||
NSString *requestType = aRequest[MPRequestTypeKey];
|
||||
if(!requestType) {
|
||||
NSLog(@"Malformed Request. Missing request type");
|
||||
}
|
||||
id<MPServerRequestHandling> handler = [MPRequestHandlerService requestHandler:requestType];
|
||||
[handler respondTo:aRequest];
|
||||
}
|
||||
@end
|
||||
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// MPDocumentQueryService.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class KPKEntry;
|
||||
@class MPDocument;
|
||||
|
||||
/**
|
||||
* Service for querying for result is withing a request
|
||||
* This shared instance handles creating of config entries,
|
||||
* and abstracts all open documents for the KeePassHttp interface.
|
||||
*/
|
||||
@interface MPDocumentQueryService : NSObject
|
||||
|
||||
/**
|
||||
* The MPDocument we currently use for our queries
|
||||
*/
|
||||
@property (readonly, weak) MPDocument *queryDocument;
|
||||
/**
|
||||
* The Config entry we did find in our query document
|
||||
*/
|
||||
@property (nonatomic, readonly, weak) KPKEntry *configurationEntry;
|
||||
|
||||
/**
|
||||
* Access the shared instance of the service
|
||||
*
|
||||
* @return shared MPDocumentQueryService instance
|
||||
*/
|
||||
+ (MPDocumentQueryService *)sharedService;
|
||||
|
||||
- (KPKEntry *)createConfigurationEntry;
|
||||
|
||||
@end
|
||||
@@ -1,75 +0,0 @@
|
||||
//
|
||||
// MPDocumentQueryService.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDocumentQueryService.h"
|
||||
#import "MPDocumentWindowController.h"
|
||||
#import "MPDocument.h"
|
||||
#import "KPKEntry.h"
|
||||
|
||||
#import "NSUUID+KeePassKit.h"
|
||||
|
||||
static NSUUID *_rootUuid = nil;
|
||||
|
||||
@interface MPDocumentQueryService ()
|
||||
|
||||
@property (weak) MPDocument *queryDocument;
|
||||
@property (nonatomic, weak) KPKEntry *configurationEntry;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPDocumentQueryService
|
||||
|
||||
+ (MPDocumentQueryService *)sharedService {
|
||||
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 uuid_t uuidBytes = {
|
||||
0x34, 0x69, 0x7a, 0x40, 0x8a, 0x5b, 0x41, 0xc0,
|
||||
0x9f, 0x36, 0x89, 0x7d, 0x62, 0x3e, 0xcb, 0x31
|
||||
};
|
||||
_rootUuid = [[NSUUID alloc] initWithUUIDBytes:uuidBytes];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (KPKEntry *)configurationEntry {
|
||||
/* TODO: lazy getter or do something different like init at first call? */
|
||||
if(nil != _configurationEntry) {
|
||||
return _configurationEntry;
|
||||
}
|
||||
/* no config entry there, start looking for it */
|
||||
NSArray *documents = [[NSDocumentController sharedDocumentController] documents];
|
||||
for(MPDocument *document in documents) {
|
||||
if(document.encrypted) {
|
||||
NSLog(@"Skipping locked Database: %@", [document displayName]);
|
||||
/* TODO: Show input window and open db with window */
|
||||
continue;
|
||||
}
|
||||
KPKEntry *configEntry = [document findEntry:_rootUuid];
|
||||
if(nil != configEntry) {
|
||||
self.configurationEntry = configEntry;
|
||||
self.queryDocument = document;
|
||||
return _configurationEntry;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (KPKEntry *)createConfigurationEntry {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,29 +0,0 @@
|
||||
//
|
||||
// MPRequestHandlerService.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol MPServerRequestHandling;
|
||||
|
||||
FOUNDATION_EXPORT NSString *const MPRequestTypeGetLogins;
|
||||
FOUNDATION_EXPORT NSString *const MPRequestTypeGetLoginsCount;
|
||||
FOUNDATION_EXPORT NSString *const MPRequestTypeGetAllLogins;
|
||||
FOUNDATION_EXPORT NSString *const MPRequestTypeSetLogin;
|
||||
FOUNDATION_EXPORT NSString *const MPRequestTypeGeneratePassword;
|
||||
|
||||
/**
|
||||
* Service class to be called for getting specific request handler for individual request
|
||||
* The service is identified by a string
|
||||
*/
|
||||
@interface MPRequestHandlerService : NSObject
|
||||
|
||||
+ (id<MPServerRequestHandling>)requestHandler:(NSString *)identifier;
|
||||
|
||||
+ (BOOL)validKeyProposal;
|
||||
|
||||
@end
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// MPRequestHandlerService.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPRequestHandlerService.h"
|
||||
#import "MPServerRequestHandling.h"
|
||||
#import "MPAssociateRequestHandler.h"
|
||||
#import "MPTestAssociateRequestHandler.h"
|
||||
|
||||
NSString *const MPRequestTypeGetLogins = @"get-logins";
|
||||
NSString *const MPRequestTypeGetLoginsCount = @"get-logins-count";
|
||||
NSString *const MPRequestTypeGetAllLogins = @"get-all-logins";
|
||||
NSString *const MPRequestTypeSetLogin = @"set-login";
|
||||
NSString *const MPRequestTypeGeneratePassword = @"generate-password";
|
||||
|
||||
@implementation MPRequestHandlerService
|
||||
|
||||
+ (id<MPServerRequestHandling>)requestHandler:(NSString *)identifier {
|
||||
return [self requestHandler][identifier];
|
||||
}
|
||||
|
||||
+ (NSDictionary *)requestHandler {
|
||||
static NSDictionary *requestHandler;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
requestHandler = [self _setupHandlerDictionary];
|
||||
});
|
||||
return requestHandler;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)_setupHandlerDictionary {
|
||||
MPAssociateRequestHandler *associateHandler = [[MPAssociateRequestHandler alloc] init];
|
||||
MPTestAssociateRequestHandler *testAssociateHandler = [[MPTestAssociateRequestHandler alloc] init];
|
||||
NSDictionary *handlerDict = @{
|
||||
[associateHandler identifier] : associateHandler,
|
||||
[testAssociateHandler identifier] : testAssociateHandler
|
||||
};
|
||||
return handlerDict;
|
||||
}
|
||||
|
||||
+ (BOOL)validKeyProposal {
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,13 +0,0 @@
|
||||
//
|
||||
// MPServerDaemon.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MPServerDaemon : NSObject
|
||||
|
||||
@end
|
||||
@@ -1,93 +0,0 @@
|
||||
//
|
||||
// MPServerDaemon.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPServerDaemon.h"
|
||||
#import "MPSettingsHelper.h"
|
||||
#import "HTTPServer.h"
|
||||
#import "MPIconHelper.h"
|
||||
#import "MPConnection.h"
|
||||
#import "MPServerRequestHandling.h"
|
||||
|
||||
@interface MPServerDaemon () {
|
||||
@private
|
||||
HTTPServer *server;
|
||||
NSStatusItem *statusItem;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) BOOL isEnabled;
|
||||
@property (nonatomic, assign) BOOL showStatusItem;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPServerDaemon
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
|
||||
NSString *enableServerKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyEnableHttpServer];
|
||||
NSString *showItemKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyShowMenuItem];
|
||||
[self bind:NSStringFromSelector(@selector(isEnabled)) toObject:defaultsController withKeyPath:enableServerKeyPath options:nil];
|
||||
[self bind:NSStringFromSelector(@selector(showStatusItem)) toObject:defaultsController withKeyPath:showItemKeyPath options:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)setIsEnabled:(BOOL)enabled {
|
||||
if(_isEnabled == enabled) {
|
||||
return; // NO changes
|
||||
}
|
||||
_isEnabled = enabled;
|
||||
if(enabled) {
|
||||
if(!server) {
|
||||
[self _setupServer];
|
||||
}
|
||||
NSError *error= nil;
|
||||
if(![server start:&error]) {
|
||||
[NSApp presentError:error];
|
||||
}
|
||||
// setup menu item
|
||||
}
|
||||
else {
|
||||
/* Do not let the resource linger around */
|
||||
server = nil;
|
||||
}
|
||||
[self _updateStatusItem];
|
||||
}
|
||||
|
||||
|
||||
- (void)setShowStatusItem:(BOOL)showStatusItem {
|
||||
if(_showStatusItem != showStatusItem) {
|
||||
_showStatusItem = showStatusItem;
|
||||
[self _updateStatusItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_updateStatusItem {
|
||||
if(_isEnabled && _showStatusItem) {
|
||||
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
|
||||
[statusItem setImage:[MPIconHelper icon:MPIconServer ]];
|
||||
}
|
||||
else if(statusItem) {
|
||||
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
|
||||
statusItem = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setupServer {
|
||||
NSAssert(server == nil, @"Server should be nil");
|
||||
server = [[HTTPServer alloc] init];
|
||||
[server setConnectionClass:[MPConnection class]];
|
||||
[server setInterface:@"localhost"];
|
||||
NSInteger port = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyHttpPort];
|
||||
[server setPort:port];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,14 +0,0 @@
|
||||
//
|
||||
// MPTestAssociateRequestHanlder.h
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 17.06.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MPServerRequestHandling.h"
|
||||
|
||||
@interface MPTestAssociateRequestHandler : NSObject <MPServerRequestHandling>
|
||||
|
||||
@end
|
||||
@@ -1,29 +0,0 @@
|
||||
//
|
||||
// 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 sharedService];
|
||||
if(![service configurationEntry]) {
|
||||
return; //Nothing to do
|
||||
}
|
||||
/*
|
||||
Test request data
|
||||
store entry db as main db?
|
||||
*/
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user