From edaf2cb8e664cd93781cf5ff56199212b36b1481 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 5 Jul 2019 23:13:20 +0100 Subject: [PATCH] More generic postPath --- daemon.py | 3 ++- inbox.py | 7 +++--- posts.py | 66 ++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/daemon.py b/daemon.py index c448f289..bc724948 100644 --- a/daemon.py +++ b/daemon.py @@ -154,7 +154,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.domain, \ messageJson, self.headers['host'], - self.headers['signature']) + self.headers['signature'], + '/'+self.path.split('/')[-1]) if cacheFilename: if cacheFilename not in self.server.inboxQueue: self.server.inboxQueue.append(cacheFilename) diff --git a/inbox.py b/inbox.py index 2a9be6bf..8098297f 100644 --- a/inbox.py +++ b/inbox.py @@ -89,7 +89,7 @@ def validPublishedDate(published) -> bool: return False return True -def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str,postJson: {},host: str,headers: str) -> str: +def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str,postJson: {},host: str,headers: str,postPath: str) -> str: """Saves the give json to the inbox queue for the person keyId specifies the actor sending the post """ @@ -120,6 +120,7 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str 'published': published, 'host': host, 'headers': headers, + 'path': postPath, 'post': postJson, 'filename': filename, 'destination': destination @@ -197,10 +198,10 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache verifyHeaders={ 'host': queueJson['host'], 'signature': queueJson['headers'] - } + } if not verifyPostHeaders(httpPrefix, \ pubKey, verifyHeaders, \ - '/inbox', False, \ + queueJson['path'], False, \ json.dumps(queueJson['post'])): if debug: print('DEBUG: Header signature check failed') diff --git a/posts.py b/posts.py index 1a8e7d96..322cab54 100644 --- a/posts.py +++ b/posts.py @@ -488,21 +488,32 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \ if not wfRequest: return 1 + if not clientToServer: + postToBox='inbox' + else: + postToBox='outbox' + # get the actor inbox for the To handle inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition = \ - getPersonBox(session,wfRequest,personCache,'inbox') + getPersonBox(session,wfRequest,personCache,postToBox) # If there are more than one followers on the target domain # then send to teh shared inbox indead of the individual inbox - if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox: - inboxUrl=sharedInbox + if nickname=='capabilities': + inboxUrl=capabilityAcquisition + if not capabilityAcquisition: + return 2 + else: + if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox: + inboxUrl=sharedInbox if not inboxUrl: - return 2 - if not pubKey: return 3 - if not toPersonId: + if not pubKey: return 4 + if not toPersonId: + return 5 + # sharedInbox and capabilities are optional postJsonObject = \ createPostBase(baseDir,nickname,domain,port, \ @@ -514,12 +525,11 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \ # get the senders private key privateKeyPem=getPersonKey(nickname,domain,baseDir,'private') if len(privateKeyPem)==0: - return 5 + return 6 - if not clientToServer: - postPath='/inbox' - else: - postPath='/outbox' + if toDomain not in inboxUrl: + return 7 + postPath='/'+inboxUrl.split('/')[-1] # construct the http header signatureHeaderJson = \ @@ -558,31 +568,41 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str,nickname: str, domain if not wfRequest: return 1 - # get the actor inbox for the To handle + if not clientToServer: + postToBox='inbox' + else: + postToBox='outbox' + + # get the actor inbox/outbox/capabilities for the To handle inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition = \ - getPersonBox(session,wfRequest,personCache,'inbox') + getPersonBox(session,wfRequest,personCache,postToBox) # If there are more than one followers on the target domain # then send to teh shared inbox indead of the individual inbox - if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox: - inboxUrl=sharedInbox + if nickname=='capabilities': + inboxUrl=capabilityAcquisition + if not capabilityAcquisition: + return 2 + else: + if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox: + inboxUrl=sharedInbox if not inboxUrl: - return 2 - if not pubKey: return 3 - if not toPersonId: + if not pubKey: return 4 + if not toPersonId: + return 5 + # sharedInbox and capabilities are optional # get the senders private key privateKeyPem=getPersonKey(nickname,domain,baseDir,'private') if len(privateKeyPem)==0: - return 5 + return 6 - if not clientToServer: - postPath='/inbox' - else: - postPath='/outbox' + if toDomain not in inboxUrl: + return 7 + postPath='/'+inboxUrl.split('/')[-1] # construct the http header signatureHeaderJson = \