From 729bb184819ddda1d7313da0c30b3397e5689721 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 10 Oct 2018 08:51:58 +0200 Subject: Add more headers to broadcast/unicast --- .../handlers/utils/activitypub-http-utils.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (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 index 36092665e..d71c91a24 100644 --- a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts +++ b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts @@ -1,8 +1,11 @@ import { buildSignedActivity } from '../../../../helpers/activitypub' import { getServerActor } from '../../../../helpers/utils' import { ActorModel } from '../../../../models/activitypub/actor' +import { sha256 } from '../../../../helpers/core-utils' -async function computeBody (payload: { body: any, signatureActorId?: number }) { +type Payload = { body: any, signatureActorId?: number } + +async function computeBody (payload: Payload) { let body = payload.body if (payload.signatureActorId) { @@ -14,7 +17,7 @@ async function computeBody (payload: { body: any, signatureActorId?: number }) { return body } -async function buildSignedRequestOptions (payload: { signatureActorId?: number }) { +async function buildSignedRequestOptions (payload: Payload) { let actor: ActorModel | null if (payload.signatureActorId) { actor = await ActorModel.load(payload.signatureActorId) @@ -29,11 +32,21 @@ async function buildSignedRequestOptions (payload: { signatureActorId?: number } algorithm: 'rsa-sha256', authorizationHeaderName: 'Signature', keyId, - key: actor.privateKey + key: actor.privateKey, + headers: [ 'date', 'host', 'digest', '(request-target)' ] + } +} + +function buildGlobalHeaders (body: object) { + const digest = 'SHA-256=' + sha256(JSON.stringify(body), 'base64') + + return { + 'Digest': digest } } export { + buildGlobalHeaders, computeBody, buildSignedRequestOptions } -- cgit v1.2.3