mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-12 21:08:46 +00:00
/api/key/register Endpoint에서, 제공된 공개 키가 RSA 4096의 공개 키가 맞는지 검증하도록 개선
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import { randomBytes, publicEncrypt } from "crypto";
|
||||
import { randomBytes, publicEncrypt, createPublicKey } from "crypto";
|
||||
import ms from "ms";
|
||||
import { promisify } from "util";
|
||||
import {
|
||||
@@ -29,6 +29,15 @@ export const registerPubKey = async (userId: number, ip: string, pubKey: string)
|
||||
error(409, "Public key already registered");
|
||||
}
|
||||
|
||||
const pubKeyPem = `-----BEGIN PUBLIC KEY-----\n${pubKey}\n-----END PUBLIC KEY-----`;
|
||||
const pubKeyObject = createPublicKey(pubKeyPem);
|
||||
if (
|
||||
pubKeyObject.asymmetricKeyType !== "rsa" ||
|
||||
pubKeyObject.asymmetricKeyDetails?.modulusLength !== 4096
|
||||
) {
|
||||
error(400, "Invalid public key");
|
||||
}
|
||||
|
||||
const clientId = await createClient(pubKey, userId);
|
||||
return await generateChallenge(userId, ip, clientId, pubKey);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user