Request Body의 필드마다 서명하지 않고, 데이터 전체에 대해 서명하도록 개선

This commit is contained in:
static
2024-12-31 09:32:37 +09:00
parent 5c535d1191
commit 0d00e2476a
10 changed files with 73 additions and 55 deletions

View File

@@ -1,6 +1,6 @@
import { callAPI } from "$lib/hooks";
import { storeRSAKey } from "$lib/indexedDB";
import { encodeToBase64, encryptRSAPlaintext, signRSAMessage } from "$lib/modules/crypto";
import { encodeToBase64, encryptRSAPlaintext, signRequest } from "$lib/modules/crypto";
import type { ClientKeys } from "$lib/stores";
export { requestTokenUpgrade } from "$lib/services/auth";
@@ -47,16 +47,17 @@ export const requestInitialMekRegistration = async (
signKey: CryptoKey,
) => {
const mekDraftEncrypted = await encryptRSAPlaintext(mekDraft, encryptKey);
const mekDraftEncryptedSigned = await signRSAMessage(mekDraftEncrypted, signKey);
const res = await callAPI("/api/mek/register/initial", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
mek: encodeToBase64(mekDraftEncrypted),
sigMek: encodeToBase64(mekDraftEncryptedSigned),
}),
body: await signRequest(
{
mek: encodeToBase64(mekDraftEncrypted),
},
signKey,
),
});
return res.ok || res.status === 409;
};