diff options
Diffstat (limited to 'server/lib/job-queue/handlers/utils')
-rw-r--r-- | server/lib/job-queue/handlers/utils/activitypub-http-utils.ts | 29 |
1 files changed, 24 insertions, 5 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..4961d4502 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,12 @@ | |||
1 | import { buildSignedActivity } from '../../../../helpers/activitypub' | 1 | import { buildSignedActivity } from '../../../../helpers/activitypub' |
2 | import { getServerActor } from '../../../../helpers/utils' | 2 | import { getServerActor } from '../../../../helpers/utils' |
3 | import { ActorModel } from '../../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../../models/activitypub/actor' |
4 | import { sha256 } from '../../../../helpers/core-utils' | ||
5 | import { HTTP_SIGNATURE } from '../../../../initializers' | ||
4 | 6 | ||
5 | async function computeBody (payload: { body: any, signatureActorId?: number }) { | 7 | type Payload = { body: any, signatureActorId?: number } |
8 | |||
9 | async function computeBody (payload: Payload) { | ||
6 | let body = payload.body | 10 | let body = payload.body |
7 | 11 | ||
8 | if (payload.signatureActorId) { | 12 | if (payload.signatureActorId) { |
@@ -14,7 +18,7 @@ async function computeBody (payload: { body: any, signatureActorId?: number }) { | |||
14 | return body | 18 | return body |
15 | } | 19 | } |
16 | 20 | ||
17 | async function buildSignedRequestOptions (payload: { signatureActorId?: number }) { | 21 | async function buildSignedRequestOptions (payload: Payload) { |
18 | let actor: ActorModel | null | 22 | let actor: ActorModel | null |
19 | if (payload.signatureActorId) { | 23 | if (payload.signatureActorId) { |
20 | actor = await ActorModel.load(payload.signatureActorId) | 24 | actor = await ActorModel.load(payload.signatureActorId) |
@@ -26,14 +30,29 @@ async function buildSignedRequestOptions (payload: { signatureActorId?: number } | |||
26 | 30 | ||
27 | const keyId = actor.getWebfingerUrl() | 31 | const keyId = actor.getWebfingerUrl() |
28 | return { | 32 | return { |
29 | algorithm: 'rsa-sha256', | 33 | algorithm: HTTP_SIGNATURE.ALGORITHM, |
30 | authorizationHeaderName: 'Signature', | 34 | authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, |
31 | keyId, | 35 | keyId, |
32 | key: actor.privateKey | 36 | key: actor.privateKey, |
37 | headers: HTTP_SIGNATURE.HEADERS_TO_SIGN | ||
38 | } | ||
39 | } | ||
40 | |||
41 | function buildGlobalHeaders (body: any) { | ||
42 | return { | ||
43 | 'Digest': buildDigest(body) | ||
33 | } | 44 | } |
34 | } | 45 | } |
35 | 46 | ||
47 | function buildDigest (body: any) { | ||
48 | const rawBody = typeof body === 'string' ? body : JSON.stringify(body) | ||
49 | |||
50 | return 'SHA-256=' + sha256(rawBody, 'base64') | ||
51 | } | ||
52 | |||
36 | export { | 53 | export { |
54 | buildDigest, | ||
55 | buildGlobalHeaders, | ||
37 | computeBody, | 56 | computeBody, |
38 | buildSignedRequestOptions | 57 | buildSignedRequestOptions |
39 | } | 58 | } |