From 46aaf8fa9a30cbe1c1410e59e70caa9e202c4cf0 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Mon, 20 Jan 2020 04:51:44 +0900 Subject: [PATCH] =?UTF-8?q?AP=20Actor=E3=81=AE=E9=8D=B5=E3=81=A8keyId?= =?UTF-8?q?=E3=81=AE=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4=20(#5733)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Node PKCS#8 * keyIdを#main-key形式に --- src/remote/activitypub/renderer/key.ts | 10 +++++++--- src/remote/activitypub/renderer/person.ts | 2 +- src/remote/activitypub/request.ts | 2 +- src/server/api/private/signup.ts | 10 +++++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/remote/activitypub/renderer/key.ts b/src/remote/activitypub/renderer/key.ts index 334e5e00cd..e792f487fd 100644 --- a/src/remote/activitypub/renderer/key.ts +++ b/src/remote/activitypub/renderer/key.ts @@ -1,10 +1,14 @@ import config from '../../../config'; import { ILocalUser } from '../../../models/entities/user'; import { UserKeypair } from '../../../models/entities/user-keypair'; +import { createPublicKey } from 'crypto'; -export default (user: ILocalUser, key: UserKeypair) => ({ - id: `${config.url}/users/${user.id}/publickey`, +export default (user: ILocalUser, key: UserKeypair, postfix?: string) => ({ + id: `${config.url}/users/${user.id}${postfix || '/publickey'}`, type: 'Key', owner: `${config.url}/users/${user.id}`, - publicKeyPem: key.publicKey + publicKeyPem: createPublicKey(key.publicKey).export({ + type: 'spki', + format: 'pem' + }) }); diff --git a/src/remote/activitypub/renderer/person.ts b/src/remote/activitypub/renderer/person.ts index d4c018fb78..07a0eeed42 100644 --- a/src/remote/activitypub/renderer/person.ts +++ b/src/remote/activitypub/renderer/person.ts @@ -108,7 +108,7 @@ export async function renderPerson(user: ILocalUser) { image: banner ? renderImage(banner) : null, tag, manuallyApprovesFollowers: user.isLocked, - publicKey: renderKey(user, keypair), + publicKey: renderKey(user, keypair, `#main-key`), isCat: user.isCat, attachment: attachment.length ? attachment : undefined }; diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index bcbb0fbe70..869fabd032 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -56,7 +56,7 @@ export default async (user: ILocalUser, url: string, object: any) => { sign(req, { authorizationHeaderName: 'Signature', key: keypair.privateKey, - keyId: `${config.url}/users/${user.id}/publickey`, + keyId: `${config.url}/users/${user.id}#main-key`, headers: ['date', 'host', 'digest'] }); diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts index 63216019e9..af1aefda84 100644 --- a/src/server/api/private/signup.ts +++ b/src/server/api/private/signup.ts @@ -91,21 +91,21 @@ export default async (ctx: Koa.Context) => { return; } - const keyPair = await new Promise((s, j) => + const keyPair = await new Promise((res, rej) => generateKeyPair('rsa', { modulusLength: 4096, publicKeyEncoding: { - type: 'pkcs1', + type: 'spki', format: 'pem' }, privateKeyEncoding: { - type: 'pkcs1', + type: 'pkcs8', format: 'pem', cipher: undefined, passphrase: undefined } - } as any, (e, publicKey, privateKey) => - e ? j(e) : s([publicKey, privateKey]) + } as any, (err, publicKey, privateKey) => + err ? rej(err) : res([publicKey, privateKey]) )); let account!: User;