diff --git a/daemon.py b/daemon.py index 3b42a4a91..3516bd8bb 100644 --- a/daemon.py +++ b/daemon.py @@ -17,7 +17,6 @@ from webfinger import webfingerLookup from webfinger import webfingerHandle from person import personLookup from person import personBoxJson -from posts import getPersonPubKey from posts import outboxMessageCreateWrap from posts import savePostToBox from inbox import inboxPermittedMessage diff --git a/epicyon.py b/epicyon.py index dfcca5014..5331b9d76 100644 --- a/epicyon.py +++ b/epicyon.py @@ -16,7 +16,6 @@ from posts import deleteAllPosts from posts import createOutbox from posts import archivePosts from posts import sendPost -from posts import getPersonBox from posts import getPublicPostsOfPerson from session import createSession from session import getJson diff --git a/inbox.py b/inbox.py index a920a44a3..9dd55fd9e 100644 --- a/inbox.py +++ b/inbox.py @@ -14,11 +14,39 @@ import json import commentjson from utils import urlPermitted from utils import createInboxQueueDir -from posts import getPersonPubKey from httpsig import verifyPostHeaders from session import createSession +from session import getJson from follow import receiveFollowRequest from pprint import pprint +from cache import getPersonFromCache + +def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str: + asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} + if not personUrl: + return None + personUrl=personUrl.replace('#main-key','') + personJson = getPersonFromCache(personUrl,personCache) + if not personJson: + if debug: + print('DEBUG: Obtaining public key for '+personUrl) + personJson = getJson(session,personUrl,asHeader,None) + if not personJson: + return None + pubKey=None + if personJson.get('publicKey'): + if personJson['publicKey'].get('publicKeyPem'): + pubKey=personJson['publicKey']['publicKeyPem'] + else: + if personJson.get('publicKeyPem'): + pubKey=personJson['publicKeyPem'] + + if not pubKey: + if debug: + print('DEBUG: Public key not found for '+personUrl) + + storePersonInCache(personUrl,personJson,personCache) + return pubKey def inboxMessageHasParams(messageJson: {}) -> bool: """Checks whether an incoming message contains expected parameters @@ -123,7 +151,7 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain: with open(queueFilename, 'r') as fp: queueJson=commentjson.load(fp) - # Try a few times to obtain teh public key + # Try a few times to obtain the public key pubKey=None for tries in range(8): keyId=None diff --git a/posts.py b/posts.py index f4707145a..c599c24d0 100644 --- a/posts.py +++ b/posts.py @@ -85,6 +85,7 @@ def getPersonBox(session,wfRequest: {},personCache: {},boxName='inbox') -> (str, personUrl = getUserUrl(wfRequest) if not personUrl: return None + print('**********personUrl: '+personUrl) personJson = getPersonFromCache(personUrl,personCache) if not personJson: personJson = getJson(session,personUrl,asHeader,None) @@ -107,33 +108,6 @@ def getPersonBox(session,wfRequest: {},personCache: {},boxName='inbox') -> (str, return personJson[boxName],pubKeyId,pubKey,personId -def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str: - asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} - if not personUrl: - return None - personUrl=personUrl.replace('#main-key','') - personJson = getPersonFromCache(personUrl,personCache) - if not personJson: - if debug: - print('DEBUG: Obtaining public key for '+personUrl) - personJson = getJson(session,personUrl,asHeader,None) - if not personJson: - return None - pubKey=None - if personJson.get('publicKey'): - if personJson['publicKey'].get('publicKeyPem'): - pubKey=personJson['publicKey']['publicKeyPem'] - else: - if personJson.get('publicKeyPem'): - pubKey=personJson['publicKeyPem'] - - if not pubKey: - if debug: - print('DEBUG: Public key not found for '+personUrl) - - storePersonInCache(personUrl,personJson,personCache) - return pubKey - def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \ maxEmoji: int,maxAttachments: int,federationList: [], \ personCache: {},raw: bool,simple: bool) -> {}: