컴파일 오류 등 수정

This commit is contained in:
static
2025-01-20 19:40:38 +09:00
parent 803110606b
commit eed60bb4a1
12 changed files with 30 additions and 32 deletions

View File

@@ -5,7 +5,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
"dev:db": "docker compose -f docker-compose.dev.yaml up -d", "dev:db": "docker compose -f docker-compose.dev.yaml -p arkvault-dev up -d",
"build": "vite build", "build": "vite build",
"preview": "vite preview", "preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",

View File

@@ -82,8 +82,8 @@ export const getAllValidClientMeks = async (userId: number, clientId: number) =>
.onRef("client_master_encryption_key.version", "=", "master_encryption_key.version"), .onRef("client_master_encryption_key.version", "=", "master_encryption_key.version"),
) )
.selectAll() .selectAll()
.where("user_id", "=", userId) .where("client_master_encryption_key.user_id", "=", userId)
.where("client_id", "=", clientId) .where("client_master_encryption_key.client_id", "=", clientId)
.where((eb) => eb.or([eb("state", "=", "active"), eb("state", "=", "retired")])) .where((eb) => eb.or([eb("state", "=", "active"), eb("state", "=", "retired")]))
.execute(); .execute();
return clientMeks.map( return clientMeks.map(

View File

@@ -1,5 +1,6 @@
import { Kysely } from "kysely"; import { Kysely } from "kysely";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const up = async (db: Kysely<any>) => { export const up = async (db: Kysely<any>) => {
// user.ts // user.ts
await db.schema await db.schema
@@ -203,6 +204,7 @@ export const up = async (db: Kysely<any>) => {
.execute(); .execute();
}; };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const down = async (db: Kysely<any>) => { export const down = async (db: Kysely<any>) => {
await db.schema.dropTable("file_log").execute(); await db.schema.dropTable("file_log").execute();
await db.schema.dropTable("file").execute(); await db.schema.dropTable("file").execute();

View File

@@ -21,5 +21,5 @@ export const verifyClientEncMekSig = async (
} }
const data = JSON.stringify({ version, key: encMek }); const data = JSON.stringify({ version, key: encMek });
return verifySignature(Buffer.from(data), encMekSig, userClient.client.sigPubKey); return verifySignature(Buffer.from(data), encMekSig, userClient.sigPubKey);
}; };

View File

@@ -63,7 +63,7 @@ export const registerUserClient = async (
} }
try { try {
const clientId = await createClient(encPubKey, sigPubKey, userId); const { clientId } = await createClient(encPubKey, sigPubKey, userId);
return { challenge: await createUserClientChallenge(ip, userId, clientId, encPubKey) }; return { challenge: await createUserClientChallenge(ip, userId, clientId, encPubKey) };
} catch (e) { } catch (e) {
if (e instanceof IntegrityError && e.message === "Public key(s) already registered") { if (e instanceof IntegrityError && e.message === "Public key(s) already registered") {

View File

@@ -8,8 +8,9 @@ import {
setDirectoryEncName, setDirectoryEncName,
unregisterDirectory, unregisterDirectory,
getAllFilesByParent, getAllFilesByParent,
type NewDirectoryParams, type NewDirectory,
} from "$lib/server/db/file"; } from "$lib/server/db/file";
import type { Ciphertext } from "$lib/server/db/schema";
export const getDirectoryInformation = async (userId: number, directoryId: "root" | number) => { export const getDirectoryInformation = async (userId: number, directoryId: "root" | number) => {
const directory = directoryId !== "root" ? await getDirectory(userId, directoryId) : undefined; const directory = directoryId !== "root" ? await getDirectory(userId, directoryId) : undefined;
@@ -53,11 +54,10 @@ export const renameDirectory = async (
userId: number, userId: number,
directoryId: number, directoryId: number,
dekVersion: Date, dekVersion: Date,
newEncName: string, newEncName: Ciphertext,
newEncNameIv: string,
) => { ) => {
try { try {
await setDirectoryEncName(userId, directoryId, dekVersion, newEncName, newEncNameIv); await setDirectoryEncName(userId, directoryId, dekVersion, newEncName);
} catch (e) { } catch (e) {
if (e instanceof IntegrityError) { if (e instanceof IntegrityError) {
if (e.message === "Directory not found") { if (e.message === "Directory not found") {
@@ -70,7 +70,7 @@ export const renameDirectory = async (
} }
}; };
export const createDirectory = async (params: NewDirectoryParams) => { export const createDirectory = async (params: NewDirectory) => {
const oneMinuteAgo = new Date(Date.now() - 60 * 1000); const oneMinuteAgo = new Date(Date.now() - 60 * 1000);
const oneMinuteLater = new Date(Date.now() + 60 * 1000); const oneMinuteLater = new Date(Date.now() + 60 * 1000);
if (params.dekVersion <= oneMinuteAgo || params.dekVersion >= oneMinuteLater) { if (params.dekVersion <= oneMinuteAgo || params.dekVersion >= oneMinuteLater) {

View File

@@ -13,8 +13,9 @@ import {
getFile, getFile,
setFileEncName, setFileEncName,
unregisterFile, unregisterFile,
type NewFileParams, type NewFile,
} from "$lib/server/db/file"; } from "$lib/server/db/file";
import type { Ciphertext } from "$lib/server/db/schema";
import env from "$lib/server/loadenv"; import env from "$lib/server/loadenv";
export const getFileInformation = async (userId: number, fileId: number) => { export const getFileInformation = async (userId: number, fileId: number) => {
@@ -38,8 +39,8 @@ export const getFileInformation = async (userId: number, fileId: number) => {
export const deleteFile = async (userId: number, fileId: number) => { export const deleteFile = async (userId: number, fileId: number) => {
try { try {
const filePath = await unregisterFile(userId, fileId); const { path } = await unregisterFile(userId, fileId);
unlink(filePath); // Intended unlink(path); // Intended
} catch (e) { } catch (e) {
if (e instanceof IntegrityError && e.message === "File not found") { if (e instanceof IntegrityError && e.message === "File not found") {
error(404, "Invalid file id"); error(404, "Invalid file id");
@@ -65,11 +66,10 @@ export const renameFile = async (
userId: number, userId: number,
fileId: number, fileId: number,
dekVersion: Date, dekVersion: Date,
newEncName: string, newEncName: Ciphertext,
newEncNameIv: string,
) => { ) => {
try { try {
await setFileEncName(userId, fileId, dekVersion, newEncName, newEncNameIv); await setFileEncName(userId, fileId, dekVersion, newEncName);
} catch (e) { } catch (e) {
if (e instanceof IntegrityError) { if (e instanceof IntegrityError) {
if (e.message === "File not found") { if (e.message === "File not found") {
@@ -96,7 +96,7 @@ const safeUnlink = async (path: string) => {
}; };
export const uploadFile = async ( export const uploadFile = async (
params: Omit<NewFileParams, "path" | "encContentHash">, params: Omit<NewFile, "path" | "encContentHash">,
encContentStream: Readable, encContentStream: Readable,
encContentHash: Promise<string>, encContentHash: Promise<string>,
) => { ) => {

View File

@@ -7,11 +7,11 @@ import { verifyClientEncMekSig } from "$lib/server/modules/mek";
export const getClientMekList = async (userId: number, clientId: number) => { export const getClientMekList = async (userId: number, clientId: number) => {
const clientMeks = await getAllValidClientMeks(userId, clientId); const clientMeks = await getAllValidClientMeks(userId, clientId);
return { return {
encMeks: clientMeks.map((clientMek) => ({ encMeks: clientMeks.map(({ version, state, encMek, encMekSig }) => ({
version: clientMek.master_encryption_key.version, version,
state: clientMek.master_encryption_key.state as "active" | "retired", state,
encMek: clientMek.client_master_encryption_key.encMek, encMek,
encMekSig: clientMek.client_master_encryption_key.encMekSig, encMekSig,
})), })),
}; };
}; };

View File

@@ -20,6 +20,6 @@ export const POST: RequestHandler = async ({ locals, params, request }) => {
if (!bodyZodRes.success) error(400, "Invalid request body"); if (!bodyZodRes.success) error(400, "Invalid request body");
const { dekVersion, name, nameIv } = bodyZodRes.data; const { dekVersion, name, nameIv } = bodyZodRes.data;
await renameDirectory(userId, id, new Date(dekVersion), name, nameIv); await renameDirectory(userId, id, new Date(dekVersion), { ciphertext: name, iv: nameIv });
return text("Directory renamed", { headers: { "Content-Type": "text/plain" } }); return text("Directory renamed", { headers: { "Content-Type": "text/plain" } });
}; };

View File

@@ -17,8 +17,7 @@ export const POST: RequestHandler = async ({ locals, request }) => {
mekVersion, mekVersion,
encDek: dek, encDek: dek,
dekVersion: new Date(dekVersion), dekVersion: new Date(dekVersion),
encName: name, encName: { ciphertext: name, iv: nameIv },
encNameIv: nameIv,
}); });
return text("Directory created", { headers: { "Content-Type": "text/plain" } }); return text("Directory created", { headers: { "Content-Type": "text/plain" } });
}; };

View File

@@ -20,6 +20,6 @@ export const POST: RequestHandler = async ({ locals, params, request }) => {
if (!bodyZodRes.success) error(400, "Invalid request body"); if (!bodyZodRes.success) error(400, "Invalid request body");
const { dekVersion, name, nameIv } = bodyZodRes.data; const { dekVersion, name, nameIv } = bodyZodRes.data;
await renameFile(userId, id, new Date(dekVersion), name, nameIv); await renameFile(userId, id, new Date(dekVersion), { ciphertext: name, iv: nameIv });
return text("File renamed", { headers: { "Content-Type": "text/plain" } }); return text("File renamed", { headers: { "Content-Type": "text/plain" } });
}; };

View File

@@ -40,12 +40,9 @@ const parseFileMetadata = (userId: number, json: string) => {
contentHmac, contentHmac,
contentType, contentType,
encContentIv: contentIv, encContentIv: contentIv,
encName: name, encName: { ciphertext: name, iv: nameIv },
encNameIv: nameIv, encCreatedAt: createdAt && createdAtIv ? { ciphertext: createdAt, iv: createdAtIv } : null,
encCreatedAt: createdAt ?? null, encLastModifiedAt: { ciphertext: lastModifiedAt, iv: lastModifiedAtIv },
encCreatedAtIv: createdAtIv ?? null,
encLastModifiedAt: lastModifiedAt,
encLastModifiedAtIv: lastModifiedAtIv,
} satisfies FileMetadata; } satisfies FileMetadata;
}; };