aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/utils
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers/utils')
-rw-r--r--server/lib/job-queue/handlers/utils/activitypub-http-utils.ts19
1 files changed, 16 insertions, 3 deletions
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 @@
1import { buildSignedActivity } from '../../../../helpers/activitypub' 1import { buildSignedActivity } from '../../../../helpers/activitypub'
2import { getServerActor } from '../../../../helpers/utils' 2import { getServerActor } from '../../../../helpers/utils'
3import { ActorModel } from '../../../../models/activitypub/actor' 3import { ActorModel } from '../../../../models/activitypub/actor'
4import { sha256 } from '../../../../helpers/core-utils'
4 5
5async function computeBody (payload: { body: any, signatureActorId?: number }) { 6type Payload = { body: any, signatureActorId?: number }
7
8async function computeBody (payload: Payload) {
6 let body = payload.body 9 let body = payload.body
7 10
8 if (payload.signatureActorId) { 11 if (payload.signatureActorId) {
@@ -14,7 +17,7 @@ async function computeBody (payload: { body: any, signatureActorId?: number }) {
14 return body 17 return body
15} 18}
16 19
17async function buildSignedRequestOptions (payload: { signatureActorId?: number }) { 20async function buildSignedRequestOptions (payload: Payload) {
18 let actor: ActorModel | null 21 let actor: ActorModel | null
19 if (payload.signatureActorId) { 22 if (payload.signatureActorId) {
20 actor = await ActorModel.load(payload.signatureActorId) 23 actor = await ActorModel.load(payload.signatureActorId)
@@ -29,11 +32,21 @@ async function buildSignedRequestOptions (payload: { signatureActorId?: number }
29 algorithm: 'rsa-sha256', 32 algorithm: 'rsa-sha256',
30 authorizationHeaderName: 'Signature', 33 authorizationHeaderName: 'Signature',
31 keyId, 34 keyId,
32 key: actor.privateKey 35 key: actor.privateKey,
36 headers: [ 'date', 'host', 'digest', '(request-target)' ]
37 }
38}
39
40function buildGlobalHeaders (body: object) {
41 const digest = 'SHA-256=' + sha256(JSON.stringify(body), 'base64')
42
43 return {
44 'Digest': digest
33 } 45 }
34} 46}
35 47
36export { 48export {
49 buildGlobalHeaders,
37 computeBody, 50 computeBody,
38 buildSignedRequestOptions 51 buildSignedRequestOptions
39} 52}