mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-12 21:08:46 +00:00
/api/key 경로에 있는 Endpoint들을 /api/client 경로로 이동
This commit is contained in:
@@ -26,7 +26,7 @@ const generateChallenge = async (userId: number, ip: string, clientId: number, p
|
|||||||
return challenge.toString("base64");
|
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);
|
const client = await getClientByPubKey(pubKey);
|
||||||
let clientId;
|
let clientId;
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ export const registerPubKey = async (userId: number, ip: string, pubKey: string)
|
|||||||
return await generateChallenge(userId, ip, clientId, pubKey);
|
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);
|
const challenge = await getUserClientChallenge(answer, ip);
|
||||||
if (!challenge) {
|
if (!challenge) {
|
||||||
error(401, "Invalid challenge answer");
|
error(401, "Invalid challenge answer");
|
||||||
@@ -15,7 +15,7 @@ export const createBlobFromKeyPairBase64 = (pubKeyBase64: string, privKeyBase64:
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey: CryptoKey) => {
|
export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey: CryptoKey) => {
|
||||||
let res = await callAPI("/api/key/register", {
|
let res = await callAPI("/api/client/register", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -28,7 +28,7 @@ export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey
|
|||||||
const challenge = data.challenge as string;
|
const challenge = data.challenge as string;
|
||||||
const answer = await decryptRSACiphertext(challenge, privateKey);
|
const answer = await decryptRSACiphertext(challenge, privateKey);
|
||||||
|
|
||||||
res = await callAPI("/api/key/verify", {
|
res = await callAPI("/api/client/verify", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { error, json } from "@sveltejs/kit";
|
import { error, json } from "@sveltejs/kit";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { authenticate } from "$lib/server/modules/auth";
|
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";
|
import type { RequestHandler } from "./$types";
|
||||||
|
|
||||||
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
|
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 { pubKey } = zodRes.data;
|
||||||
const challenge = await registerPubKey(userId, getClientAddress(), pubKey.trim());
|
const challenge = await registerUserClient(userId, getClientAddress(), pubKey.trim());
|
||||||
return json({ challenge });
|
return json({ challenge });
|
||||||
};
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { error, text } from "@sveltejs/kit";
|
import { error, text } from "@sveltejs/kit";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { authenticate } from "$lib/server/modules/auth";
|
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";
|
import type { RequestHandler } from "./$types";
|
||||||
|
|
||||||
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
|
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
|
||||||
@@ -18,6 +18,6 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { answer } = zodRes.data;
|
const { answer } = zodRes.data;
|
||||||
await verifyPubKey(userId, getClientAddress(), answer.trim());
|
await verifyUserClient(userId, getClientAddress(), answer.trim());
|
||||||
return text("Key verified", { headers: { "Content-Type": "text/plain" } });
|
return text("Client verified", { headers: { "Content-Type": "text/plain" } });
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user