From a6cfb5a7db6a86b33b5f49e5d9b533ff7da643f9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 13 Aug 2021 21:43:48 +0900 Subject: [PATCH] =?UTF-8?q?fix(activity-pub):=20=E3=82=A2=E3=82=AB?= =?UTF-8?q?=E3=82=A6=E3=83=B3=E3=83=88=E5=89=8A=E9=99=A4=E3=82=A2=E3=82=AF?= =?UTF-8?q?=E3=83=86=E3=82=A3=E3=83=93=E3=83=86=E3=82=A3=E3=81=8C=E9=85=8D?= =?UTF-8?q?=E9=80=81=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E3=81=93=E3=81=A8?= =?UTF-8?q?=E3=81=8C=E3=81=82=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #7506 --- CHANGELOG.md | 1 + src/queue/index.ts | 10 ++++++++-- src/queue/types.ts | 4 +++- src/remote/activitypub/request.ts | 6 ++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da90a5c07..ce2449e38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Misskey更新時にダイアログを表示するように ### Bugfixes +- ActivityPub: アカウント削除アクティビティが配送されないことがある問題を修正 ## 12.87.0 (2021/08/12) diff --git a/src/queue/index.ts b/src/queue/index.ts index c7b7f0392..dda0c2852 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -13,6 +13,7 @@ import { getJobInfo } from './get-job-info'; import { dbQueue, deliverQueue, inboxQueue, objectStorageQueue } from './queues'; import { ThinUser } from './types'; import { IActivity } from '@/remote/activitypub/type'; +import { getUserKeypair } from '@/misc/keypair-store'; function renderError(e: Error): any { return { @@ -59,12 +60,17 @@ objectStorageQueue .on('error', (job: any, err: Error) => objectStorageLogger.error(`error ${err}`, { job, e: renderError(err) })) .on('stalled', (job) => objectStorageLogger.warn(`stalled id=${job.id}`)); -export function deliver(user: ThinUser, content: unknown, to: string | null) { +export async function deliver(user: ThinUser, content: unknown, to: string | null) { if (content == null) return null; if (to == null) return null; + const keypair = await getUserKeypair(user.id); + const data = { - user, + user: { + ...user, + privateKey: keypair.privateKey, + }, content, to }; diff --git a/src/queue/types.ts b/src/queue/types.ts index a782fc6b9..6ebfb765f 100644 --- a/src/queue/types.ts +++ b/src/queue/types.ts @@ -5,7 +5,9 @@ import * as httpSignature from 'http-signature'; export type DeliverJobData = { /** Actor */ - user: ThinUser; + user: ThinUser & { + privateKey: string; + }; /** Activity */ content: unknown; /** inbox URL to deliver */ diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index e4dca3232..459d5f6ac 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -11,7 +11,7 @@ import got from 'got'; import * as Got from 'got'; import { getUserKeypair } from '@/misc/keypair-store'; -export default async (user: { id: User['id'] }, url: string, object: any) => { +export default async (user: { id: User['id']; privateKey: string; }, url: string, object: any) => { const timeout = 10 * 1000; const { protocol, hostname, port, pathname, search } = new URL(url); @@ -22,8 +22,6 @@ export default async (user: { id: User['id'] }, url: string, object: any) => { sha256.update(data); const hash = sha256.digest('base64'); - const keypair = await getUserKeypair(user.id); - await new Promise((resolve, reject) => { const req = https.request({ agent: getAgentByUrl(new URL(`https://example.net`)), @@ -48,7 +46,7 @@ export default async (user: { id: User['id'] }, url: string, object: any) => { sign(req, { authorizationHeaderName: 'Signature', - key: keypair.privateKey, + key: user.privateKey, keyId: `${config.url}/users/${user.id}#main-key`, headers: ['(request-target)', 'date', 'host', 'digest'] });