From 94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Jan 2018 15:05:18 +0100 Subject: Move job queue to redis We'll use it as cache in the future. /!\ You'll loose your old jobs (pending jobs too) so upgrade only when you don't have pending job anymore. --- .../handlers/utils/activitypub-http-utils.ts | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 server/lib/job-queue/handlers/utils/activitypub-http-utils.ts (limited to 'server/lib/job-queue/handlers/utils') diff --git a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts new file mode 100644 index 000000000..c087371c6 --- /dev/null +++ b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts @@ -0,0 +1,39 @@ +import { buildSignedActivity } from '../../../../helpers/activitypub' +import { getServerActor } from '../../../../helpers/utils' +import { ActorModel } from '../../../../models/activitypub/actor' + +async function computeBody (payload: { body: any, signatureActorId?: number }) { + let body = payload.body + + if (payload.signatureActorId) { + const actorSignature = await ActorModel.load(payload.signatureActorId) + if (!actorSignature) throw new Error('Unknown signature actor id.') + body = await buildSignedActivity(actorSignature, payload.body) + } + + return body +} + +async function buildSignedRequestOptions (payload: { signatureActorId?: number }) { + let actor: ActorModel + if (payload.signatureActorId) { + actor = await ActorModel.load(payload.signatureActorId) + if (!actor) throw new Error('Unknown signature actor id.') + } else { + // We need to sign the request, so use the server + actor = await getServerActor() + } + + const keyId = actor.getWebfingerUrl() + return { + algorithm: 'rsa-sha256', + authorizationHeaderName: 'Signature', + keyId, + key: actor.privateKey + } +} + +export { + computeBody, + buildSignedRequestOptions +} -- cgit v1.2.3