mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 14:07:38 -07:00
parent
e1b070757b
commit
0d21645e73
4 changed files with 14 additions and 10 deletions
|
@ -1,10 +1,14 @@
|
||||||
import config from '../../../config';
|
import config from '../../../config';
|
||||||
import { ILocalUser } from '../../../models/entities/user';
|
import { ILocalUser } from '../../../models/entities/user';
|
||||||
import { UserKeypair } from '../../../models/entities/user-keypair';
|
import { UserKeypair } from '../../../models/entities/user-keypair';
|
||||||
|
import { createPublicKey } from 'crypto';
|
||||||
|
|
||||||
export default (user: ILocalUser, key: UserKeypair) => ({
|
export default (user: ILocalUser, key: UserKeypair, postfix?: string) => ({
|
||||||
id: `${config.url}/users/${user.id}/publickey`,
|
id: `${config.url}/users/${user.id}${postfix || '/publickey'}`,
|
||||||
type: 'Key',
|
type: 'Key',
|
||||||
owner: `${config.url}/users/${user.id}`,
|
owner: `${config.url}/users/${user.id}`,
|
||||||
publicKeyPem: key.publicKey
|
publicKeyPem: createPublicKey(key.publicKey).export({
|
||||||
|
type: 'spki',
|
||||||
|
format: 'pem'
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
|
@ -108,7 +108,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||||
image: banner ? renderImage(banner) : null,
|
image: banner ? renderImage(banner) : null,
|
||||||
tag,
|
tag,
|
||||||
manuallyApprovesFollowers: user.isLocked,
|
manuallyApprovesFollowers: user.isLocked,
|
||||||
publicKey: renderKey(user, keypair),
|
publicKey: renderKey(user, keypair, `#main-key`),
|
||||||
isCat: user.isCat,
|
isCat: user.isCat,
|
||||||
attachment: attachment.length ? attachment : undefined
|
attachment: attachment.length ? attachment : undefined
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,7 +56,7 @@ export default async (user: ILocalUser, url: string, object: any) => {
|
||||||
sign(req, {
|
sign(req, {
|
||||||
authorizationHeaderName: 'Signature',
|
authorizationHeaderName: 'Signature',
|
||||||
key: keypair.privateKey,
|
key: keypair.privateKey,
|
||||||
keyId: `${config.url}/users/${user.id}/publickey`,
|
keyId: `${config.url}/users/${user.id}#main-key`,
|
||||||
headers: ['date', 'host', 'digest']
|
headers: ['date', 'host', 'digest']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -91,21 +91,21 @@ export default async (ctx: Koa.Context) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyPair = await new Promise<string[]>((s, j) =>
|
const keyPair = await new Promise<string[]>((res, rej) =>
|
||||||
generateKeyPair('rsa', {
|
generateKeyPair('rsa', {
|
||||||
modulusLength: 4096,
|
modulusLength: 4096,
|
||||||
publicKeyEncoding: {
|
publicKeyEncoding: {
|
||||||
type: 'pkcs1',
|
type: 'spki',
|
||||||
format: 'pem'
|
format: 'pem'
|
||||||
},
|
},
|
||||||
privateKeyEncoding: {
|
privateKeyEncoding: {
|
||||||
type: 'pkcs1',
|
type: 'pkcs8',
|
||||||
format: 'pem',
|
format: 'pem',
|
||||||
cipher: undefined,
|
cipher: undefined,
|
||||||
passphrase: undefined
|
passphrase: undefined
|
||||||
}
|
}
|
||||||
} as any, (e, publicKey, privateKey) =>
|
} as any, (err, publicKey, privateKey) =>
|
||||||
e ? j(e) : s([publicKey, privateKey])
|
err ? rej(err) : res([publicKey, privateKey])
|
||||||
));
|
));
|
||||||
|
|
||||||
let account!: User;
|
let account!: User;
|
||||||
|
|
Loading…
Reference in a new issue