/api/key 경로에 있는 Endpoint들을 /api/client 경로로 이동

This commit is contained in:
static
2024-12-29 19:12:50 +09:00
parent bbba449819
commit 3664ad66ac
4 changed files with 9 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ const generateChallenge = async (userId: number, ip: string, clientId: number, p
return challenge.toString("base64");
};
export const registerPubKey = async (userId: number, ip: string, pubKey: string) => {
export const registerUserClient = async (userId: number, ip: string, pubKey: string) => {
const client = await getClientByPubKey(pubKey);
let clientId;
@@ -54,7 +54,7 @@ export const registerPubKey = async (userId: number, ip: string, pubKey: string)
return await generateChallenge(userId, ip, clientId, pubKey);
};
export const verifyPubKey = async (userId: number, ip: string, answer: string) => {
export const verifyUserClient = async (userId: number, ip: string, answer: string) => {
const challenge = await getUserClientChallenge(answer, ip);
if (!challenge) {
error(401, "Invalid challenge answer");

View File

@@ -15,7 +15,7 @@ export const createBlobFromKeyPairBase64 = (pubKeyBase64: string, privKeyBase64:
};
export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey: CryptoKey) => {
let res = await callAPI("/api/key/register", {
let res = await callAPI("/api/client/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
@@ -28,7 +28,7 @@ export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey
const challenge = data.challenge as string;
const answer = await decryptRSACiphertext(challenge, privateKey);
res = await callAPI("/api/key/verify", {
res = await callAPI("/api/client/verify", {
method: "POST",
headers: {
"Content-Type": "application/json",

View File

@@ -1,7 +1,7 @@
import { error, json } from "@sveltejs/kit";
import { z } from "zod";
import { authenticate } from "$lib/server/modules/auth";
import { registerPubKey } from "$lib/server/services/key";
import { registerUserClient } from "$lib/server/services/client";
import type { RequestHandler } from "./$types";
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
@@ -18,6 +18,6 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
}
const { pubKey } = zodRes.data;
const challenge = await registerPubKey(userId, getClientAddress(), pubKey.trim());
const challenge = await registerUserClient(userId, getClientAddress(), pubKey.trim());
return json({ challenge });
};

View File

@@ -1,7 +1,7 @@
import { error, text } from "@sveltejs/kit";
import { z } from "zod";
import { authenticate } from "$lib/server/modules/auth";
import { verifyPubKey } from "$lib/server/services/key";
import { verifyUserClient } from "$lib/server/services/client";
import type { RequestHandler } from "./$types";
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
@@ -18,6 +18,6 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
}
const { answer } = zodRes.data;
await verifyPubKey(userId, getClientAddress(), answer.trim());
return text("Key verified", { headers: { "Content-Type": "text/plain" } });
await verifyUserClient(userId, getClientAddress(), answer.trim());
return text("Client verified", { headers: { "Content-Type": "text/plain" } });
};