mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-11-04 08:10:28 +09:00
리다이렉트 경로 처리, 파일 정보 변환, 상태 표시 UI 등 중복된 코드를 통합하고 모듈 간 순환 의존성 및 계층 위반 해소
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9119c21881
commit
5b8621e524
96 files changed
+452
-548
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import { AES_GCM_IV_SIZE } from "#lib/shared/format/index.ts";
|
||||
import {
|
||||
encodeString,
|
||||
decodeString,
|
||||
@@ -7,6 +6,9 @@ import {
|
||||
concatenateBuffers,
|
||||
} from "./encoding.ts";
|
||||
|
||||
export const AES_GCM_IV_SIZE = 12;
|
||||
export const AES_GCM_TAG_SIZE = 16;
|
||||
|
||||
export const generateMasterKey = async () => {
|
||||
return {
|
||||
masterKey: await crypto.subtle.generateKey(
|
||||
@@ -44,10 +46,12 @@ export const makeAESKeyNonextractable = async (key: CryptoKey) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const wrapDataKey = async (dataKey: CryptoKey, masterKey: CryptoKey) => {
|
||||
return encodeToBase64(await crypto.subtle.wrapKey("raw", dataKey, masterKey, "AES-KW"));
|
||||
const wrapKey = async (key: CryptoKey, masterKey: CryptoKey) => {
|
||||
return encodeToBase64(await crypto.subtle.wrapKey("raw", key, masterKey, "AES-KW"));
|
||||
};
|
||||
|
||||
export const wrapDataKey = wrapKey;
|
||||
|
||||
export const unwrapDataKey = async (dataKeyWrapped: string, masterKey: CryptoKey) => {
|
||||
return {
|
||||
dataKey: await crypto.subtle.unwrapKey(
|
||||
@@ -62,9 +66,7 @@ export const unwrapDataKey = async (dataKeyWrapped: string, masterKey: CryptoKey
|
||||
};
|
||||
};
|
||||
|
||||
export const wrapHmacSecret = async (hmacSecret: CryptoKey, masterKey: CryptoKey) => {
|
||||
return encodeToBase64(await crypto.subtle.wrapKey("raw", hmacSecret, masterKey, "AES-KW"));
|
||||
};
|
||||
export const wrapHmacSecret = wrapKey;
|
||||
|
||||
export const unwrapHmacSecret = async (hmacSecretWrapped: string, masterKey: CryptoKey) => {
|
||||
return {
|
||||
@@ -84,7 +86,7 @@ export const unwrapHmacSecret = async (hmacSecretWrapped: string, masterKey: Cry
|
||||
};
|
||||
|
||||
export const encryptData = async (data: BufferSource, dataKey: CryptoKey) => {
|
||||
const iv = crypto.getRandomValues(new Uint8Array(12));
|
||||
const iv = crypto.getRandomValues(new Uint8Array(AES_GCM_IV_SIZE));
|
||||
const ciphertext = await crypto.subtle.encrypt(
|
||||
{
|
||||
name: "AES-GCM",
|
||||
|
||||
@@ -166,15 +166,21 @@ export const verifySignatureRSA = async (
|
||||
);
|
||||
};
|
||||
|
||||
// The message signed by clients to prove the integrity of the wrapped master key. Also verified
|
||||
// by the server, so it must not be changed.
|
||||
export const serializeMasterKeyWrapped = (masterKeyWrapped: string, masterKeyVersion: number) => {
|
||||
return JSON.stringify({
|
||||
version: masterKeyVersion,
|
||||
key: masterKeyWrapped,
|
||||
});
|
||||
};
|
||||
|
||||
export const signMasterKeyWrapped = async (
|
||||
masterKeyWrapped: string,
|
||||
masterKeyVersion: number,
|
||||
signKey: CryptoKey,
|
||||
) => {
|
||||
const serialized = JSON.stringify({
|
||||
version: masterKeyVersion,
|
||||
key: masterKeyWrapped,
|
||||
});
|
||||
const serialized = serializeMasterKeyWrapped(masterKeyWrapped, masterKeyVersion);
|
||||
return encodeToBase64(await signMessageRSA(encodeString(serialized), signKey));
|
||||
};
|
||||
|
||||
@@ -184,10 +190,7 @@ export const verifyMasterKeyWrapped = async (
|
||||
masterKeyWrappedSig: string,
|
||||
verifyKey: CryptoKey,
|
||||
) => {
|
||||
const serialized = JSON.stringify({
|
||||
version: masterKeyVersion,
|
||||
key: masterKeyWrapped,
|
||||
});
|
||||
const serialized = serializeMasterKeyWrapped(masterKeyWrapped, masterKeyVersion);
|
||||
return await verifySignatureRSA(
|
||||
encodeString(serialized),
|
||||
decodeFromBase64(masterKeyWrappedSig),
|
||||
|
||||
Reference in new issue
Block a user