mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
공개 키 등록시 인증 절차 추가
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
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 type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
pubKey: z.string().base64().nonempty(),
|
||||
@@ -17,6 +17,6 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
error(403, "Forbidden");
|
||||
}
|
||||
|
||||
await registerPubKey(userId, zodRes.data.pubKey);
|
||||
return text("Public key registered", { headers: { "Content-Type": "text/plain" } });
|
||||
const challenge = await registerPubKey(userId, getClientAddress(), zodRes.data.pubKey);
|
||||
return json({ challenge });
|
||||
};
|
||||
|
||||
22
src/routes/api/key/verify/+server.ts
Normal file
22
src/routes/api/key/verify/+server.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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 type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
|
||||
const zodRes = z
|
||||
.object({
|
||||
answer: z.string().base64().nonempty(),
|
||||
})
|
||||
.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
|
||||
const { userId, clientId } = authenticate(cookies);
|
||||
if (clientId) {
|
||||
error(403, "Forbidden");
|
||||
}
|
||||
|
||||
await verifyPubKey(userId, getClientAddress(), zodRes.data.answer);
|
||||
return text("Key verified", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
Reference in New Issue
Block a user