From 6c85b39adc5fe2abeace2824866cd044960f5ed8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 30 Jun 2019 19:23:18 +0100 Subject: [PATCH] Include port with domain --- epicyon.py | 2 +- httpsig.py | 3 ++- person.py | 11 +++++++---- session.py | 5 +++++ webfinger.py | 5 ++++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/epicyon.py b/epicyon.py index 47449a160..223e53399 100644 --- a/epicyon.py +++ b/epicyon.py @@ -66,7 +66,7 @@ followerOfPerson(username,domain,'giraffe','trees.com',federationList) #sys.exit() -privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True) +privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,port,https,True) #deleteAllPosts(username,domain) setPreferredUsername(username,domain,'badger') setBio(username,domain,'Some personal info') diff --git a/httpsig.py b/httpsig.py index 4244c6f82..4ae9ad083 100644 --- a/httpsig.py +++ b/httpsig.py @@ -114,7 +114,8 @@ def testHttpsigBase(withDigest): username='socrates' domain='argumentative.social' https=True - privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,False) + port=80 + privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,port,https,False) messageBodyJson = '{"a key": "a value", "another key": "A string"}' if not withDigest: headers = {'host': domain} diff --git a/person.py b/person.py index 02300b07e..9c4e3a605 100644 --- a/person.py +++ b/person.py @@ -21,7 +21,7 @@ def generateRSAKey() -> (str,str): publicKeyPem = key.publickey().exportKey("PEM").decode("utf-8") return privateKeyPem,publicKeyPem -def createPerson(username: str,domain: str,https: bool, saveToFile: bool) -> (str,str,{},{}): +def createPerson(username: str,domain: str,port: int,https: bool, saveToFile: bool) -> (str,str,{},{}): """Returns the private key, public key, actor and webfinger endpoint """ prefix='https' @@ -29,10 +29,14 @@ def createPerson(username: str,domain: str,https: bool, saveToFile: bool) -> (st prefix='http' privateKeyPem,publicKeyPem=generateRSAKey() - webfingerEndpoint=createWebfingerEndpoint(username,domain,https,publicKeyPem) + webfingerEndpoint=createWebfingerEndpoint(username,domain,port,https,publicKeyPem) if saveToFile: storeWebfingerEndpoint(username,domain,webfingerEndpoint) - + + handle=username.lower()+'@'+domain.lower() + if port!=80 and port!=443: + domain=domain+':'+str(port) + newPerson = {'@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', {'Emoji': 'toot:Emoji', @@ -75,7 +79,6 @@ def createPerson(username: str,domain: str,https: bool, saveToFile: bool) -> (st if saveToFile: # save person to file - handle=username.lower()+'@'+domain.lower() baseDir=os.getcwd() peopleSubdir='/accounts' if not os.path.isdir(baseDir+peopleSubdir): diff --git a/session.py b/session.py index e6485993b..12d7f5b83 100644 --- a/session.py +++ b/session.py @@ -9,6 +9,8 @@ __status__ = "Production" import requests import json +baseDirectory=None + def createSession(onionRoute: bool): session = requests.session() if onionRoute: @@ -42,3 +44,6 @@ def postJson(session,postJsonObject,federationList,inboxUrl: str,headers) -> str postResult = session.post(url = inboxUrl, data = json.dumps(postJsonObject), headers=headers) return postResult.text + +def getBaseDirectory(): + baseDirectory = os.getcwd() diff --git a/webfinger.py b/webfinger.py index 1675607e8..58cde6b6e 100644 --- a/webfinger.py +++ b/webfinger.py @@ -77,13 +77,16 @@ def storeWebfingerEndpoint(username: str,domain: str,wfJson) -> bool: commentjson.dump(wfJson, fp, indent=4, sort_keys=False) return True -def createWebfingerEndpoint(username,domain,https,publicKeyPem) -> {}: +def createWebfingerEndpoint(username,domain,port,https,publicKeyPem) -> {}: """Creates a webfinger endpoint for a user """ prefix='https' if not https: prefix='http' + if port!=80 and port!=443: + domain=domain+':'+str(port) + account = { "aliases": [ prefix+"://"+domain+"/@"+username,