From 04f4a65a096a7274ff50a16f9b99b07419ba2797 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 3 Oct 2022 14:45:29 +0200 Subject: [PATCH] Simulate ActivityPub actor --- routes/main.js | 42 ++++++++++++++++++++++++++++++++++++++++++ template.env | 7 +++++++ 2 files changed, 49 insertions(+) diff --git a/routes/main.js b/routes/main.js index cacf057..b3bccf8 100644 --- a/routes/main.js +++ b/routes/main.js @@ -57,4 +57,46 @@ router.get('/privacy', (req, res) => { res.render(`article`, { title: `Privacy policy`, content: content }) }) +router.get('/.well-known/webfinger', (req, res) => { + if (!(process.env.DOMAIN && process.env.ACTIVITYPUB_PUBLICKEY)) { + res.status(404).send('
Cannot GET /.well-known/webfinger
') + return + } + + const body = { + 'subject': `acct:keyoxide@${process.env.DOMAIN}`, + 'aliases': [`https://${process.env.DOMAIN}/users/keyoxide`], + 'links': [{ + 'rel': 'self', + 'type': 'application/activity+json', + 'href': `https://${process.env.DOMAIN}/users/keyoxide` + }] + } + res.json(body) +}) + +router.get('/users/keyoxide', (req, res) => { + if (!(process.env.DOMAIN && process.env.ACTIVITYPUB_PUBLICKEY)) { + res.status(404).send('
Cannot GET /keyoxide
') + return + } + + const body = { + '@context': [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1' + ], + 'id': `https://${process.env.DOMAIN}/users/keyoxide`, + 'type': 'Application', + 'inbox': `https://${process.env.DOMAIN}/users/keyoxide/inbox`, + 'preferredUsername': `${process.env.DOMAIN}`, + 'publicKey': { + 'id': `https://${process.env.DOMAIN}/users/keyoxide#main-key`, + 'owner': `https://${process.env.DOMAIN}/users/keyoxide`, + 'publicKeyPem': `${process.env.ACTIVITYPUB_PUBLICKEY}` + } + } + res.type('application/activity+json').json(body) +}) + export default router diff --git a/template.env b/template.env index a0844a2..4b07118 100644 --- a/template.env +++ b/template.env @@ -5,6 +5,13 @@ # Domain of Keyoxide instance #DOMAIN= +# Public key used for the simulated ActivityPub actor named Keyoxide on the instance +# Obtained through: +# $ openssl genrsa -out private.pem 2048 +# $ openssl rsa -in private.pem -outform PEM -pubout -out public.pem +# $ while read -r line; do echo -nE "$line\n" ; done < public.pem > public-oneline.pem +#ACTIVITYPUB_PUBLICKEY= + # Domain for DOIP Proxy server # Source code for the server can be found here https://codeberg.org/keyoxide/doip-proxy #PROXY_HOSTNAME=