From 1d9f3048303f7ebf4ec73bb9040e309b69875bb1 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Mon, 2 Jan 2023 15:01:19 -0500 Subject: [PATCH] aes.js: improved error handling --- scripts/aes.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/aes.js b/scripts/aes.js index e5e14d6..b57727b 100644 --- a/scripts/aes.js +++ b/scripts/aes.js @@ -77,9 +77,18 @@ async function encrypt() { async function decrypt() { let msgEncoded = decMsg.value; - let ciphertext = new b64ToBuf(msgEncoded.ciphertext); - let iv = new Uint8Array(b64ToBuf(msgEncoded.iv)); - let salt = new Uint8Array(b64ToBuf(msgEncoded.salt)); + let ciphertext, iv, salt; + try { + ciphertext = new b64ToBuf(msgEncoded.ciphertext); + iv = new Uint8Array(b64ToBuf(msgEncoded.iv)); + salt = new Uint8Array(b64ToBuf(msgEncoded.salt)); + } catch (e) { + decMsg.alertBox("alert-error", "Invalid base64 value."); + } + + if (ciphertext === undefined || iv === undefined || salt === undefined) { + return; + } let keyMaterial = await getKeyMaterial(decPass.value); let key = await getKey(keyMaterial, salt);