From 378d080cef6f3d85d20dff87bf16de14ee666b2f Mon Sep 17 00:00:00 2001 From: shinigami-eyes <43276258+shinigami-eyes@users.noreply.github.com> Date: Sat, 10 Jul 2021 10:17:30 +0000 Subject: [PATCH] Also store hash --- extension/background.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extension/background.ts b/extension/background.ts index 7ca4c70..f559bbd 100644 --- a/extension/background.ts +++ b/extension/background.ts @@ -564,6 +564,7 @@ function objectToBytes(obj: any) { interface AsymmetricallyEncryptedData { symmetricKey: JsonWebKey; + sha256: string; } async function encryptSubmission(plainObj: any): Promise { @@ -583,10 +584,14 @@ async function encryptSubmission(plainObj: any): Promise { const iv = window.crypto.getRandomValues(new Uint8Array(16)); + const plainData = objectToBytes(plainObj); + const symmetricallyEncryptedData = await crypto.subtle.encrypt({ name: "AES-CBC", iv - }, symmetricKey, objectToBytes(plainObj)); + }, symmetricKey, plainData); + + const plainHash = await crypto.subtle.digest('SHA-256', plainData); const asymmetricallyEncryptedSymmetricKey = await crypto.subtle.encrypt( { @@ -594,7 +599,8 @@ async function encryptSubmission(plainObj: any): Promise { }, publicEncryptionKey, objectToBytes({ - symmetricKey: await crypto.subtle.exportKey('jwk', symmetricKey) + symmetricKey: await crypto.subtle.exportKey('jwk', symmetricKey), + sha256: bufferToBase64(plainHash) }) ); return {