From 3c1302c150d641cce886a8891b09b5fbe4fca269 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Fri, 14 Oct 2022 13:02:49 +0200 Subject: [PATCH] Fix minor bug, allow not setting up --- src/fetcher/activitypub.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/fetcher/activitypub.js b/src/fetcher/activitypub.js index a9c1719..89eff8d 100644 --- a/src/fetcher/activitypub.js +++ b/src/fetcher/activitypub.js @@ -54,16 +54,16 @@ module.exports.fn = async (data, opts) => { const fetchPromise = new Promise((resolve, reject) => { (async () => { + let isConfigured = false try { validator.isURL(opts.claims.activitypub.url) + isConfigured = true } catch (err) { - throw new Error(`ActivityPub fetcher was not set up properly (${err.message})`) + console.log(`ActivityPub fetcher was not set up (${err.message})`) } - // Prepare the signature const now = new Date() const { host, pathname, search } = new URL(data.url) - const signedString = `(request-target): get ${pathname}${search}\nhost: ${host}\ndate: ${now.toUTCString()}` const headers = { host, @@ -71,12 +71,13 @@ module.exports.fn = async (data, opts) => { accept: 'application/activity+json' } - if (jsEnv.isNode) { + if (isConfigured && jsEnv.isNode) { // Generate the signature + const signedString = `(request-target): get ${pathname}${search}\nhost: ${host}\ndate: ${now.toUTCString()}` const sign = crypto.createSign('SHA256') sign.write(signedString) sign.end() - const signatureSig = sign.sign(opts.claims.activitypub.privateKey, 'base64') + const signatureSig = sign.sign(opts.claims.activitypub.privateKey.replace(/\\n/g, '\n'), 'base64') headers.signature = `keyId="${opts.claims.activitypub.url}#main-key",headers="(request-target) host date",signature="${signatureSig}",algorithm="rsa-sha256"` }