AP Actorの鍵とkeyIdのフォーマットの変更 (#5733)

* Node PKCS#8

* keyIdを#main-key形式に
This commit is contained in:
MeiMei 2020-01-20 04:51:44 +09:00 committed by syuilo
parent 5a950cf991
commit 46aaf8fa9a
4 changed files with 14 additions and 10 deletions

View file

@ -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'
})
});

View file

@ -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
};

View file

@ -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']
});

View file

@ -91,21 +91,21 @@ export default async (ctx: Koa.Context) => {
return;
}
const keyPair = await new Promise<string[]>((s, j) =>
const keyPair = await new Promise<string[]>((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;