use gen-key-pair fn. from '@misskey-dev/node-http-message-signatures'
This commit is contained in:
parent
fd71ad7a5f
commit
67758d2d1e
|
@ -11,7 +11,7 @@ import { RedisKVCache } from '@/misc/cache.js';
|
||||||
import type { MiUserKeypair } from '@/models/UserKeypair.js';
|
import type { MiUserKeypair } from '@/models/UserKeypair.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { genEd25519KeyPair } from '@/misc/gen-key-pair.js';
|
import { genEd25519KeyPair } from '@misskey-dev/node-http-message-signatures';
|
||||||
import { GlobalEventService, GlobalEvents } from '@/core/GlobalEventService.js';
|
import { GlobalEventService, GlobalEvents } from '@/core/GlobalEventService.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
|
@ -3,41 +3,7 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as crypto from 'node:crypto';
|
import { genEd25519KeyPair, genRsaKeyPair } from '@misskey-dev/node-http-message-signatures';
|
||||||
import * as util from 'node:util';
|
|
||||||
|
|
||||||
const generateKeyPair = util.promisify(crypto.generateKeyPair);
|
|
||||||
|
|
||||||
export async function genRsaKeyPair(modulusLength = 4096) {
|
|
||||||
return await generateKeyPair('rsa', {
|
|
||||||
modulusLength,
|
|
||||||
publicKeyEncoding: {
|
|
||||||
type: 'spki',
|
|
||||||
format: 'pem',
|
|
||||||
},
|
|
||||||
privateKeyEncoding: {
|
|
||||||
type: 'pkcs8',
|
|
||||||
format: 'pem',
|
|
||||||
cipher: undefined,
|
|
||||||
passphrase: undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function genEd25519KeyPair() {
|
|
||||||
return await generateKeyPair('ed25519', {
|
|
||||||
publicKeyEncoding: {
|
|
||||||
type: 'spki',
|
|
||||||
format: 'pem',
|
|
||||||
},
|
|
||||||
privateKeyEncoding: {
|
|
||||||
type: 'pkcs8',
|
|
||||||
format: 'pem',
|
|
||||||
cipher: undefined,
|
|
||||||
passphrase: undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function genRSAAndEd25519KeyPair(rsaModulusLength = 4096) {
|
export async function genRSAAndEd25519KeyPair(rsaModulusLength = 4096) {
|
||||||
const rsa = await genRsaKeyPair(rsaModulusLength);
|
const rsa = await genRsaKeyPair(rsaModulusLength);
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import { verifyDraftSignature, parseRequestSignature } from '@misskey-dev/node-http-message-signatures';
|
import { verifyDraftSignature, parseRequestSignature, genEd25519KeyPair, genRsaKeyPair } from '@misskey-dev/node-http-message-signatures';
|
||||||
import { genEd25519KeyPair, genRsaKeyPair } from '@/misc/gen-key-pair.js';
|
|
||||||
import { createSignedGet, createSignedPost } from '@/core/activitypub/ApRequestService.js';
|
import { createSignedGet, createSignedPost } from '@/core/activitypub/ApRequestService.js';
|
||||||
|
|
||||||
export const buildParsedSignature = (signingString: string, signature: string, algorithm: string) => {
|
export const buildParsedSignature = (signingString: string, signature: string, algorithm: string) => {
|
||||||
|
@ -49,7 +48,7 @@ describe('ap-request', () => {
|
||||||
const parsed = parseRequestSignature(req.request);
|
const parsed = parseRequestSignature(req.request);
|
||||||
expect(parsed?.version).toBe('draft');
|
expect(parsed?.version).toBe('draft');
|
||||||
if (!parsed) return;
|
if (!parsed) return;
|
||||||
const verify = verifyDraftSignature(parsed?.value, keypair.publicKey);
|
const verify = verifyDraftSignature(parsed.value, keypair.publicKey);
|
||||||
assert.deepStrictEqual(verify, true);
|
assert.deepStrictEqual(verify, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -68,7 +67,7 @@ describe('ap-request', () => {
|
||||||
const parsed = parseRequestSignature(req.request);
|
const parsed = parseRequestSignature(req.request);
|
||||||
expect(parsed?.version).toBe('draft');
|
expect(parsed?.version).toBe('draft');
|
||||||
if (!parsed) return;
|
if (!parsed) return;
|
||||||
const verify = verifyDraftSignature(parsed?.value, keypair.publicKey);
|
const verify = verifyDraftSignature(parsed.value, keypair.publicKey);
|
||||||
assert.deepStrictEqual(verify, true);
|
assert.deepStrictEqual(verify, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue