More generic postPath

master
Bob Mottram 2019-07-05 23:13:20 +01:00
parent ac42694ac4
commit edaf2cb8e6
3 changed files with 49 additions and 27 deletions

View File

@ -154,7 +154,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain, \ self.server.domain, \
messageJson, messageJson,
self.headers['host'], self.headers['host'],
self.headers['signature']) self.headers['signature'],
'/'+self.path.split('/')[-1])
if cacheFilename: if cacheFilename:
if cacheFilename not in self.server.inboxQueue: if cacheFilename not in self.server.inboxQueue:
self.server.inboxQueue.append(cacheFilename) self.server.inboxQueue.append(cacheFilename)

View File

@ -89,7 +89,7 @@ def validPublishedDate(published) -> bool:
return False return False
return True 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 """Saves the give json to the inbox queue for the person
keyId specifies the actor sending the post keyId specifies the actor sending the post
""" """
@ -120,6 +120,7 @@ def savePostToInboxQueue(baseDir: str,httpPrefix: str,nickname: str, domain: str
'published': published, 'published': published,
'host': host, 'host': host,
'headers': headers, 'headers': headers,
'path': postPath,
'post': postJson, 'post': postJson,
'filename': filename, 'filename': filename,
'destination': destination 'destination': destination
@ -197,10 +198,10 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
verifyHeaders={ verifyHeaders={
'host': queueJson['host'], 'host': queueJson['host'],
'signature': queueJson['headers'] 'signature': queueJson['headers']
} }
if not verifyPostHeaders(httpPrefix, \ if not verifyPostHeaders(httpPrefix, \
pubKey, verifyHeaders, \ pubKey, verifyHeaders, \
'/inbox', False, \ queueJson['path'], False, \
json.dumps(queueJson['post'])): json.dumps(queueJson['post'])):
if debug: if debug:
print('DEBUG: Header signature check failed') print('DEBUG: Header signature check failed')

View File

@ -488,21 +488,32 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \
if not wfRequest: if not wfRequest:
return 1 return 1
if not clientToServer:
postToBox='inbox'
else:
postToBox='outbox'
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition = \ 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 # If there are more than one followers on the target domain
# then send to teh shared inbox indead of the individual inbox # then send to teh shared inbox indead of the individual inbox
if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox: if nickname=='capabilities':
inboxUrl=sharedInbox inboxUrl=capabilityAcquisition
if not capabilityAcquisition:
return 2
else:
if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox:
inboxUrl=sharedInbox
if not inboxUrl: if not inboxUrl:
return 2
if not pubKey:
return 3 return 3
if not toPersonId: if not pubKey:
return 4 return 4
if not toPersonId:
return 5
# sharedInbox and capabilities are optional
postJsonObject = \ postJsonObject = \
createPostBase(baseDir,nickname,domain,port, \ 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 # get the senders private key
privateKeyPem=getPersonKey(nickname,domain,baseDir,'private') privateKeyPem=getPersonKey(nickname,domain,baseDir,'private')
if len(privateKeyPem)==0: if len(privateKeyPem)==0:
return 5 return 6
if not clientToServer: if toDomain not in inboxUrl:
postPath='/inbox' return 7
else: postPath='/'+inboxUrl.split('/')[-1]
postPath='/outbox'
# construct the http header # construct the http header
signatureHeaderJson = \ signatureHeaderJson = \
@ -558,31 +568,41 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str,nickname: str, domain
if not wfRequest: if not wfRequest:
return 1 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 = \ 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 # If there are more than one followers on the target domain
# then send to teh shared inbox indead of the individual inbox # then send to teh shared inbox indead of the individual inbox
if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox: if nickname=='capabilities':
inboxUrl=sharedInbox inboxUrl=capabilityAcquisition
if not capabilityAcquisition:
return 2
else:
if noOfFollowersOnDomain(baseDir,handle,toDomain)>1 and sharedInbox:
inboxUrl=sharedInbox
if not inboxUrl: if not inboxUrl:
return 2
if not pubKey:
return 3 return 3
if not toPersonId: if not pubKey:
return 4 return 4
if not toPersonId:
return 5
# sharedInbox and capabilities are optional
# get the senders private key # get the senders private key
privateKeyPem=getPersonKey(nickname,domain,baseDir,'private') privateKeyPem=getPersonKey(nickname,domain,baseDir,'private')
if len(privateKeyPem)==0: if len(privateKeyPem)==0:
return 5 return 6
if not clientToServer: if toDomain not in inboxUrl:
postPath='/inbox' return 7
else: postPath='/'+inboxUrl.split('/')[-1]
postPath='/outbox'
# construct the http header # construct the http header
signatureHeaderJson = \ signatureHeaderJson = \