From b11c8e473593953c482b142519fa9d1cedcd58e3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 5 Jul 2019 21:32:21 +0100 Subject: [PATCH] Return capabilities endpoint --- README.md | 3 +++ follow.py | 12 +++++++++--- person.py | 3 ++- posts.py | 21 +++++++++++++++++---- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3da02605..7fb5f259 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Based on the specification: https://www.w3.org/TR/activitypub Also: https://raw.githubusercontent.com/w3c/activitypub/gh-pages/activitypub-tutorial.txt +https://blog.dereferenced.org/what-is-ocap-and-why-should-i-care + This project is currently *pre alpha* and not recommended for any real world uses. ## Goals @@ -21,6 +23,7 @@ This project is currently *pre alpha* and not recommended for any real world use * http signatures and basic auth. * Compatible with http (onion addresses), https and dat. * Minimal dependencies. + * Capabilities based security * Data minimization principle. Configurable post expiry time. * Commandline interface. If there's a GUI it should be a separate project. * Designed for intermittent connectivity. Assume network disruptions. diff --git a/follow.py b/follow.py index c0404a02..3ccf48e3 100644 --- a/follow.py +++ b/follow.py @@ -280,7 +280,7 @@ def sendFollowRequest(baseDir: str,nickname: str,domain: str,port: int,httpPrefi if followPort!=80 and followPort!=443: followDomain=followDomain+':'+str(followPort) - newFollow = { + newFollowJson = { 'type': 'Follow', 'actor': httpPrefix+'://'+domain+'/users/'+nickname, 'object': followHttpPrefix+'://'+followDomain+'/users/'+followNickname, @@ -290,5 +290,11 @@ def sendFollowRequest(baseDir: str,nickname: str,domain: str,port: int,httpPrefi if ccUrl: if len(ccUrl)>0: - newFollow['cc']=ccUrl - return newFollow + newFollowJson['cc']=ccUrl + + sendSignedJson(newFollowJson,session,baseDir,nickname,domain,port, \ + nicknameToFollow,domainToFollow,toPort, '', \ + httpPrefix,saveToFile,clientToServer,federationList, \ + sendThreads,postLog,cachedWebfingers,personCache) + + return newFollowJson diff --git a/person.py b/person.py index 9c1dd697..fcc5d954 100644 --- a/person.py +++ b/person.py @@ -54,7 +54,8 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ 'endpoints': { 'id': httpPrefix+'://'+domain+'/users/'+nickname+'/endpoints', 'sharedInbox': httpPrefix+'://'+domain+'/inbox', - 'uploadMedia': httpPrefix+'://'+domain+'/users/'+nickname+'/endpoints/uploadMedia' + 'uploadMedia': httpPrefix+'://'+domain+'/users/'+nickname+'/endpoints/uploadMedia', + "capabilityAcquisition": httpPrefix+'://'+domain+'/caps/new' }, 'featured': httpPrefix+'://'+domain+'/users/'+nickname+'/collections/featured', 'followers': httpPrefix+'://'+domain+'/users/'+nickname+'/followers', diff --git a/posts.py b/posts.py index bcc5e09a..0f8a860a 100644 --- a/posts.py +++ b/posts.py @@ -134,10 +134,23 @@ def getPersonBox(session,wfRequest: {},personCache: {},boxName='inbox') -> (str, if personJson.get('endpoints'): if personJson['endpoints'].get('sharedInbox'): sharedInbox=personJson['endpoints']['sharedInbox'] + capabilityAcquisition=None + if personJson.get('capabilityAcquisition'): + capabilityAcquisition=personJson['capabilityAcquisition'] + else: + if personJson.get('capabilityAcquisitionEndpoint'): + capabilityAcquisition=personJson['capabilityAcquisitionEndpoint'] + else: + if personJson.get('endpoints'): + if personJson['endpoints'].get('capabilityAcquisition'): + capabilityAcquisition=personJson['endpoints']['capabilityAcquisition'] + else: + if personJson['endpoints'].get('capabilityAcquisitionEndpoint'): + capabilityAcquisition=personJson['endpoints']['capabilityAcquisitionEndpoint'] storePersonInCache(personUrl,personJson,personCache) - return boxJson,pubKeyId,pubKey,personId,sharedInbox + return boxJson,pubKeyId,pubKey,personId,sharedInbox,capabilityAcquisition def getPosts(session,outboxUrl: str,maxPosts: int,maxMentions: int, \ maxEmoji: int,maxAttachments: int,federationList: [], \ @@ -470,7 +483,7 @@ def sendPost(session,baseDir: str,nickname: str, domain: str, port: int, \ return 1 # get the actor inbox for the To handle - inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox = \ + inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition = \ getPersonBox(session,wfRequest,personCache,'inbox') # If there are more than one followers on the target domain @@ -540,7 +553,7 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str,nickname: str, domain return 1 # get the actor inbox for the To handle - inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox = \ + inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition = \ getPersonBox(session,wfRequest,personCache,'inbox') # If there are more than one followers on the target domain @@ -730,7 +743,7 @@ def getPublicPostsOfPerson(nickname: str,domain: str,raw: bool,simple: bool) -> if not wfRequest: sys.exit() - personUrl,pubKeyId,pubKey,personId,shaedInbox= \ + personUrl,pubKeyId,pubKey,personId,shaedInbox,capabilityAcquisition= \ getPersonBox(session,wfRequest,personCache,'outbox') wfResult = json.dumps(wfRequest, indent=4, sort_keys=True)