mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
로그인 및 암호 키 등록 이후 클라이언트 승인 대기 페이지로의 자동 리다이렉션 구현
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { callAPI } from "$lib/hooks";
|
||||
import { storeMasterKeys } from "$lib/indexedDB";
|
||||
import {
|
||||
encodeToBase64,
|
||||
decodeFromBase64,
|
||||
decryptRSACiphertext,
|
||||
signRSAMessage,
|
||||
makeAESKeyNonextractable,
|
||||
unwrapAESKeyUsingRSA,
|
||||
} from "$lib/modules/crypto";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
|
||||
export const requestClientRegistration = async (
|
||||
encryptKeyBase64: string,
|
||||
@@ -40,3 +44,35 @@ export const requestClientRegistration = async (
|
||||
});
|
||||
return res.ok;
|
||||
};
|
||||
|
||||
export const requestMasterKeyDownload = async (decryptKey: CryptoKey) => {
|
||||
const res = await callAPI("/api/mek/list", { method: "GET" });
|
||||
if (!res.ok) return false;
|
||||
|
||||
const data = await res.json();
|
||||
const { meks: masterKeysWrapped } = data as {
|
||||
meks: {
|
||||
version: number;
|
||||
state: "active" | "retired";
|
||||
mek: string;
|
||||
}[];
|
||||
};
|
||||
const masterKeys = await Promise.all(
|
||||
masterKeysWrapped.map(async ({ version, state, mek: masterKeyWrapped }) => ({
|
||||
version,
|
||||
state,
|
||||
masterKey: await makeAESKeyNonextractable(
|
||||
await unwrapAESKeyUsingRSA(decodeFromBase64(masterKeyWrapped), decryptKey),
|
||||
),
|
||||
})),
|
||||
);
|
||||
|
||||
await storeMasterKeys(
|
||||
masterKeys.map(({ version, state, masterKey }) => ({ version, state, key: masterKey })),
|
||||
);
|
||||
masterKeyStore.set(
|
||||
new Map(masterKeys.map(({ version, state, masterKey }) => [version, { state, masterKey }])),
|
||||
);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user