mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
Request 서명 시스템 삭제
보안에 큰 도움이 되지 않는다고 판단하여 삭제하였습니다. 판단 근거는 다음과 같습니다. 1. Web Crypto API는 HTTPS 환경에서만 사용할 수 있음 2. 프론트엔드와 백엔드가 하나의 서버에서 제공되므로, 리버스 프록시에 의한 중간자 공격을 받지 않는가에 대한 직관적인 검증이 불가능함 3. 신뢰할 수 없는 리버스 프록시는 애초에 사용하지 않는 것이 맞음 다만 MEK에 대한 서명 등은 그대로 유지됩니다.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { callSignedPostApi } from "$lib/hooks";
|
||||
import { callPostApi } from "$lib/hooks";
|
||||
import { storeClientKey } from "$lib/indexedDB";
|
||||
import { signMasterKeyWrapped } from "$lib/modules/crypto";
|
||||
import type { InitialMasterKeyRegisterRequest } from "$lib/server/schemas";
|
||||
@@ -46,13 +46,9 @@ export const requestInitialMasterKeyRegistration = async (
|
||||
masterKeyWrapped: string,
|
||||
signKey: CryptoKey,
|
||||
) => {
|
||||
const res = await callSignedPostApi<InitialMasterKeyRegisterRequest>(
|
||||
"/api/mek/register/initial",
|
||||
{
|
||||
mek: masterKeyWrapped,
|
||||
mekSig: await signMasterKeyWrapped(1, masterKeyWrapped, signKey),
|
||||
},
|
||||
signKey,
|
||||
);
|
||||
const res = await callPostApi<InitialMasterKeyRegisterRequest>("/api/mek/register/initial", {
|
||||
mek: masterKeyWrapped,
|
||||
mekSig: await signMasterKeyWrapped(1, masterKeyWrapped, signKey),
|
||||
});
|
||||
return res.ok || res.status === 409;
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import { goto } from "$app/navigation";
|
||||
import { TopBar } from "$lib/components";
|
||||
import { FloatingButton } from "$lib/components/buttons";
|
||||
import { clientKeyStore, masterKeyStore } from "$lib/stores";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import CreateBottomSheet from "./CreateBottomSheet.svelte";
|
||||
import CreateDirectoryModal from "./CreateDirectoryModal.svelte";
|
||||
import DeleteDirectoryEntryModal from "./DeleteDirectoryEntryModal.svelte";
|
||||
@@ -81,12 +81,7 @@
|
||||
});
|
||||
|
||||
const createDirectory = async (name: string) => {
|
||||
await requestDirectroyCreation(
|
||||
name,
|
||||
data.id,
|
||||
$masterKeyStore?.get(1)!,
|
||||
$clientKeyStore?.signKey!,
|
||||
);
|
||||
await requestDirectroyCreation(name, data.id, $masterKeyStore?.get(1)!);
|
||||
isCreateDirectoryModalOpen = false;
|
||||
};
|
||||
|
||||
@@ -94,7 +89,7 @@
|
||||
const file = fileInput?.files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
requestFileUpload(file, data.id, $masterKeyStore?.get(1)!, $clientKeyStore?.signKey!);
|
||||
requestFileUpload(file, data.id, $masterKeyStore?.get(1)!);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { callSignedPostApi } from "$lib/hooks";
|
||||
import { callPostApi } from "$lib/hooks";
|
||||
import {
|
||||
encodeToBase64,
|
||||
generateDataKey,
|
||||
@@ -7,8 +7,6 @@ import {
|
||||
encryptData,
|
||||
encryptString,
|
||||
decryptString,
|
||||
digestMessage,
|
||||
signRequestBody,
|
||||
} from "$lib/modules/crypto";
|
||||
import type {
|
||||
DirectroyInfoResponse,
|
||||
@@ -33,49 +31,38 @@ export const requestDirectroyCreation = async (
|
||||
name: string,
|
||||
parentId: "root" | number,
|
||||
masterKey: MasterKey,
|
||||
signKey: CryptoKey,
|
||||
) => {
|
||||
const { dataKey } = await generateDataKey();
|
||||
const nameEncrypted = await encryptData(new TextEncoder().encode(name), dataKey);
|
||||
return await callSignedPostApi<DirectoryCreateRequest>(
|
||||
"/api/directory/create",
|
||||
{
|
||||
parentId,
|
||||
mekVersion: masterKey.version,
|
||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||
name: encodeToBase64(nameEncrypted.ciphertext),
|
||||
nameIv: nameEncrypted.iv,
|
||||
},
|
||||
signKey,
|
||||
);
|
||||
return await callPostApi<DirectoryCreateRequest>("/api/directory/create", {
|
||||
parentId,
|
||||
mekVersion: masterKey.version,
|
||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||
name: encodeToBase64(nameEncrypted.ciphertext),
|
||||
nameIv: nameEncrypted.iv,
|
||||
});
|
||||
};
|
||||
|
||||
export const requestFileUpload = async (
|
||||
file: File,
|
||||
parentId: "root" | number,
|
||||
masterKey: MasterKey,
|
||||
signKey: CryptoKey,
|
||||
) => {
|
||||
const { dataKey } = await generateDataKey();
|
||||
const fileEncrypted = await encryptData(await file.arrayBuffer(), dataKey);
|
||||
const fileEncryptedHash = await digestMessage(fileEncrypted.ciphertext);
|
||||
const nameEncrypted = await encryptString(file.name, dataKey);
|
||||
|
||||
const form = new FormData();
|
||||
form.set(
|
||||
"metadata",
|
||||
await signRequestBody<FileUploadRequest>(
|
||||
{
|
||||
parentId,
|
||||
mekVersion: masterKey.version,
|
||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||
contentHash: encodeToBase64(fileEncryptedHash),
|
||||
contentIv: fileEncrypted.iv,
|
||||
name: nameEncrypted.ciphertext,
|
||||
nameIv: nameEncrypted.iv,
|
||||
},
|
||||
signKey,
|
||||
),
|
||||
JSON.stringify({
|
||||
parentId,
|
||||
mekVersion: masterKey.version,
|
||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||
contentIv: fileEncrypted.iv,
|
||||
name: nameEncrypted.ciphertext,
|
||||
nameIv: nameEncrypted.iv,
|
||||
} satisfies FileUploadRequest),
|
||||
);
|
||||
form.set("content", new Blob([fileEncrypted.ciphertext]));
|
||||
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { parseSignedRequest } from "$lib/server/modules/crypto";
|
||||
import { directoryRenameRequest } from "$lib/server/schemas";
|
||||
import { renameDirectory } from "$lib/server/services/directory";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies, params }) => {
|
||||
const { userId, clientId } = await authorize(cookies, "activeClient");
|
||||
const { userId } = await authorize(cookies, "activeClient");
|
||||
|
||||
const zodRes = z
|
||||
const paramsZodRes = z
|
||||
.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
})
|
||||
.safeParse(params);
|
||||
if (!zodRes.success) error(400, "Invalid path parameters");
|
||||
const { id } = zodRes.data;
|
||||
const { name, nameIv } = await parseSignedRequest(
|
||||
clientId,
|
||||
await request.json(),
|
||||
directoryRenameRequest,
|
||||
);
|
||||
if (!paramsZodRes.success) error(400, "Invalid path parameters");
|
||||
const { id } = paramsZodRes.data;
|
||||
|
||||
const bodyZodRes = directoryRenameRequest.safeParse(await request.json());
|
||||
if (!bodyZodRes.success) error(400, "Invalid request body");
|
||||
const { name, nameIv } = bodyZodRes.data;
|
||||
|
||||
await renameDirectory(userId, id, name, nameIv);
|
||||
return text("Directory renamed", { headers: { "Content-Type": "text/plain" } });
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
import { text } from "@sveltejs/kit";
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { parseSignedRequest } from "$lib/server/modules/crypto";
|
||||
import { directoryCreateRequest } from "$lib/server/schemas";
|
||||
import { createDirectory } from "$lib/server/services/directory";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
const { userId, clientId } = await authorize(cookies, "activeClient");
|
||||
const { parentId, mekVersion, dek, name, nameIv } = await parseSignedRequest(
|
||||
clientId,
|
||||
await request.json(),
|
||||
directoryCreateRequest,
|
||||
);
|
||||
const { userId } = await authorize(cookies, "activeClient");
|
||||
|
||||
const zodRes = directoryCreateRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { parentId, mekVersion, dek, name, nameIv } = zodRes.data;
|
||||
|
||||
await createDirectory({
|
||||
userId,
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { z } from "zod";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { parseSignedRequest } from "$lib/server/modules/crypto";
|
||||
import { fileRenameRequest } from "$lib/server/schemas";
|
||||
import { renameFile } from "$lib/server/services/file";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies, params }) => {
|
||||
const { userId, clientId } = await authorize(cookies, "activeClient");
|
||||
const { userId } = await authorize(cookies, "activeClient");
|
||||
|
||||
const zodRes = z
|
||||
const paramsZodRes = z
|
||||
.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
})
|
||||
.safeParse(params);
|
||||
if (!zodRes.success) error(400, "Invalid path parameters");
|
||||
const { id } = zodRes.data;
|
||||
const { name, nameIv } = await parseSignedRequest(
|
||||
clientId,
|
||||
await request.json(),
|
||||
fileRenameRequest,
|
||||
);
|
||||
if (!paramsZodRes.success) error(400, "Invalid path parameters");
|
||||
const { id } = paramsZodRes.data;
|
||||
|
||||
const bodyZodRes = fileRenameRequest.safeParse(await request.json());
|
||||
if (!bodyZodRes.success) error(400, "Invalid request body");
|
||||
const { name, nameIv } = bodyZodRes.data;
|
||||
|
||||
await renameFile(userId, id, name, nameIv);
|
||||
return text("File renamed", { headers: { "Content-Type": "text/plain" } });
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { authorize } from "$lib/server/modules/auth";
|
||||
import { parseSignedRequest } from "$lib/server/modules/crypto";
|
||||
import { fileUploadRequest } from "$lib/server/schemas";
|
||||
import { uploadFile } from "$lib/server/services/file";
|
||||
import type { RequestHandler } from "./$types";
|
||||
|
||||
export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
const { userId, clientId } = await authorize(cookies, "activeClient");
|
||||
const { userId } = await authorize(cookies, "activeClient");
|
||||
|
||||
const form = await request.formData();
|
||||
|
||||
const metadata = form.get("metadata");
|
||||
if (!metadata || typeof metadata !== "string") {
|
||||
error(400, "Invalid request body");
|
||||
}
|
||||
const { parentId, mekVersion, dek, contentHash, contentIv, name, nameIv } =
|
||||
await parseSignedRequest(clientId, JSON.parse(metadata), fileUploadRequest);
|
||||
|
||||
const content = form.get("content");
|
||||
if (!content || !(content instanceof File)) {
|
||||
if (typeof metadata !== "string" || !(content instanceof File)) {
|
||||
error(400, "Invalid request body");
|
||||
}
|
||||
|
||||
const zodRes = fileUploadRequest.safeParse(JSON.parse(metadata));
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { parentId, mekVersion, dek, contentIv, name, nameIv } = zodRes.data;
|
||||
|
||||
await uploadFile(
|
||||
{
|
||||
userId,
|
||||
@@ -33,7 +29,6 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
encNameIv: nameIv,
|
||||
},
|
||||
content.stream(),
|
||||
contentHash,
|
||||
);
|
||||
return text("File uploaded", { headers: { "Content-Type": "text/plain" } });
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import { authenticate } from "$lib/server/modules/auth";
|
||||
import { parseSignedRequest } from "$lib/server/modules/crypto";
|
||||
import { initialMasterKeyRegisterRequest } from "$lib/server/schemas";
|
||||
import { registerInitialActiveMek } from "$lib/server/services/mek";
|
||||
import type { RequestHandler } from "./$types";
|
||||
@@ -11,11 +10,9 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
error(403, "Forbidden");
|
||||
}
|
||||
|
||||
const { mek, mekSig } = await parseSignedRequest(
|
||||
clientId,
|
||||
await request.json(),
|
||||
initialMasterKeyRegisterRequest,
|
||||
);
|
||||
const zodRes = initialMasterKeyRegisterRequest.safeParse(await request.json());
|
||||
if (!zodRes.success) error(400, "Invalid request body");
|
||||
const { mek, mekSig } = zodRes.data;
|
||||
|
||||
await registerInitialActiveMek(userId, clientId, mek, mekSig);
|
||||
return text("MEK registered", { headers: { "Content-Type": "text/plain" } });
|
||||
|
||||
Reference in New Issue
Block a user