From eefca034fc622db86c2527bed034bb9b64d7ba77 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 4 Mar 2024 02:20:09 +0000 Subject: [PATCH] =?UTF-8?q?digest=E3=83=97=E3=83=AA=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=83=80=E3=82=92=E5=BE=A9=E6=B4=BB=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RFC実装時にどうするか考える --- packages/backend/src/core/QueueService.ts | 3 ++- .../backend/src/core/activitypub/ApRequestService.ts | 9 +++++---- .../src/queue/processors/DeliverProcessorService.ts | 2 +- packages/backend/src/queue/types.ts | 2 ++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/QueueService.ts b/packages/backend/src/core/QueueService.ts index 7ba1853f84..1e96adedfd 100644 --- a/packages/backend/src/core/QueueService.ts +++ b/packages/backend/src/core/QueueService.ts @@ -15,7 +15,7 @@ import type { Antenna } from '@/server/api/endpoints/i/import-antennas.js'; import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, RelationshipQueue, SystemQueue, WebhookDeliverQueue } from './QueueModule.js'; import type { DbJobData, DeliverJobData, RelationshipJobData, ThinUser } from '../queue/types.js'; import type * as Bull from 'bullmq'; -import type { ParsedSignature } from '@misskey-dev/node-http-message-signatures'; +import { genRFC3230DigestHeader, type ParsedSignature } from '@misskey-dev/node-http-message-signatures'; @Injectable() export class QueueService { @@ -81,6 +81,7 @@ export class QueueService { id: user.id, }, content: contentBody, + digest: await genRFC3230DigestHeader(contentBody, 'SHA-256'), to, isSharedInbox, }; diff --git a/packages/backend/src/core/activitypub/ApRequestService.ts b/packages/backend/src/core/activitypub/ApRequestService.ts index 0e96a80165..8469dfbce4 100644 --- a/packages/backend/src/core/activitypub/ApRequestService.ts +++ b/packages/backend/src/core/activitypub/ApRequestService.ts @@ -28,7 +28,7 @@ type PrivateKey = { keyId: string; }; -export async function createSignedPost(args: { level: string; key: PrivateKey; url: string; body: string; additionalHeaders: Record }) { +export async function createSignedPost(args: { level: string; key: PrivateKey; url: string; body: string; digest?: string, additionalHeaders: Record }) { const u = new URL(args.url); const request: RequestLike = { url: u.href, @@ -40,9 +40,9 @@ export async function createSignedPost(args: { level: string; key: PrivateKey; u ...args.additionalHeaders, }, }; - +c // TODO: httpMessageSignaturesImplementationLevelによって新規格で通信をするようにする - const digestHeader = await genRFC3230DigestHeader(args.body, 'SHA-256'); + const digestHeader = args.digest ?? await genRFC3230DigestHeader(args.body, 'SHA-256'); request.headers['Digest'] = digestHeader; const result = await signAsDraftToRequest(request, args.key, ['(request-target)', 'date', 'host', 'digest']); @@ -105,7 +105,7 @@ export class ApRequestService { } @bindThis - public async signedPost(user: { id: MiUser['id'] }, url: string, object: unknown, level: string): Promise { + public async signedPost(user: { id: MiUser['id'] }, url: string, object: unknown, level: string, digest?: string): Promise { const body = typeof object === 'string' ? object : JSON.stringify(object); const key = await this.getPrivateKey(user.id, level); const req = await createSignedPost({ @@ -116,6 +116,7 @@ export class ApRequestService { additionalHeaders: { 'User-Agent': this.config.userAgent, }, + digest, }); this.logger.debug('create signed post', { diff --git a/packages/backend/src/queue/processors/DeliverProcessorService.ts b/packages/backend/src/queue/processors/DeliverProcessorService.ts index 6bbe7a4973..8f3782a048 100644 --- a/packages/backend/src/queue/processors/DeliverProcessorService.ts +++ b/packages/backend/src/queue/processors/DeliverProcessorService.ts @@ -76,7 +76,7 @@ export class DeliverProcessorService { await this.fetchInstanceMetadataService.fetchInstanceMetadata(_server).then(() => {}); const server = await this.federatedInstanceService.fetch(host); - await this.apRequestService.signedPost(job.data.user, job.data.to, job.data.content, server.httpMessageSignaturesImplementationLevel); + await this.apRequestService.signedPost(job.data.user, job.data.to, job.data.content, server.httpMessageSignaturesImplementationLevel, job.data.digest); // Update stats if (server.isNotResponding) { diff --git a/packages/backend/src/queue/types.ts b/packages/backend/src/queue/types.ts index fcae4c2596..135bccb60c 100644 --- a/packages/backend/src/queue/types.ts +++ b/packages/backend/src/queue/types.ts @@ -32,6 +32,8 @@ export type DeliverJobData = { user: ThinUser; /** Activity */ content: string; + /** Digest header */ + digest: string; /** inbox URL to deliver */ to: string; /** whether it is sharedInbox */