MEK 관련 DB 스키마 생성

This commit is contained in:
static
2024-12-29 18:01:02 +09:00
parent 46938ef700
commit bbba449819
5 changed files with 76 additions and 11 deletions

View File

@@ -17,13 +17,13 @@ const expiresIn = ms(env.challenge.pubKeyExp);
const expiresAt = () => new Date(Date.now() + expiresIn);
const generateChallenge = async (userId: number, ip: string, clientId: number, pubKey: string) => {
const challenge = await promisify(randomBytes)(32);
const challengeBase64 = challenge.toString("base64");
await createUserClientChallenge(userId, clientId, challengeBase64, ip, expiresAt());
const answer = await promisify(randomBytes)(32);
const answerBase64 = answer.toString("base64");
await createUserClientChallenge(userId, clientId, answerBase64, ip, expiresAt());
const pubKeyPem = `-----BEGIN PUBLIC KEY-----\n${pubKey}\n-----END PUBLIC KEY-----`;
const challengeEncrypted = publicEncrypt({ key: pubKeyPem, oaepHash: "sha256" }, challenge);
return challengeEncrypted.toString("base64");
const challenge = publicEncrypt({ key: pubKeyPem, oaepHash: "sha256" }, answer);
return challenge.toString("base64");
};
export const registerPubKey = async (userId: number, ip: string, pubKey: string) => {