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, \
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)

View File

@ -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')

View File

@ -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 = \