mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-15 22:38:47 +00:00
암호 키 생성 및 등록시 최초 MEK도 함께 생성 및 등록하도록 구현
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { callAPI } from "$lib/hooks";
|
||||
import { storeKeyPairIntoIndexedDB } from "$lib/indexedDB";
|
||||
import { decryptRSACiphertext } from "$lib/modules/crypto";
|
||||
import {
|
||||
encodeToBase64,
|
||||
decodeFromBase64,
|
||||
encryptRSAPlaintext,
|
||||
decryptRSACiphertext,
|
||||
} from "$lib/modules/crypto";
|
||||
|
||||
export const createBlobFromKeyPairBase64 = (pubKeyBase64: string, privKeyBase64: string) => {
|
||||
const pubKeyFormatted = pubKeyBase64.match(/.{1,64}/g)?.join("\n");
|
||||
@@ -26,18 +31,22 @@ export const requestPubKeyRegistration = async (pubKeyBase64: string, privateKey
|
||||
|
||||
const data = await res.json();
|
||||
const challenge = data.challenge as string;
|
||||
const answer = await decryptRSACiphertext(challenge, privateKey);
|
||||
const answer = await decryptRSACiphertext(decodeFromBase64(challenge), privateKey);
|
||||
|
||||
res = await callAPI("/api/client/verify", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ answer }),
|
||||
body: JSON.stringify({ answer: encodeToBase64(answer) }),
|
||||
});
|
||||
return res.ok;
|
||||
};
|
||||
|
||||
export const storeKeyPairPersistently = async (keyPair: CryptoKeyPair) => {
|
||||
await storeKeyPairIntoIndexedDB(keyPair.publicKey, keyPair.privateKey);
|
||||
};
|
||||
|
||||
export const requestTokenUpgrade = async (pubKeyBase64: string) => {
|
||||
const res = await fetch("/api/auth/upgradeToken", {
|
||||
method: "POST",
|
||||
@@ -49,6 +58,17 @@ export const requestTokenUpgrade = async (pubKeyBase64: string) => {
|
||||
return res.ok;
|
||||
};
|
||||
|
||||
export const storeKeyPairPersistently = async (keyPair: CryptoKeyPair) => {
|
||||
await storeKeyPairIntoIndexedDB(keyPair.publicKey, keyPair.privateKey);
|
||||
export const requestInitialMekRegistration = async (
|
||||
mekDraft: ArrayBuffer,
|
||||
publicKey: CryptoKey,
|
||||
) => {
|
||||
const mekDraftEncrypted = await encryptRSAPlaintext(mekDraft, publicKey);
|
||||
const res = await callAPI("/api/mek/register/initial", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ mek: encodeToBase64(mekDraftEncrypted) }),
|
||||
});
|
||||
return res.ok || res.status === 403;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user