From 78c0c042bd214ff845d6b0737dd11d45634f5fa0 Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:59:35 +0100 Subject: [PATCH] fix js --- .../docker/dashboard/app/static/trigger.js | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/services/ansible_openvpn/docker/dashboard/app/static/trigger.js b/services/ansible_openvpn/docker/dashboard/app/static/trigger.js index 8809cca..d6967f5 100644 --- a/services/ansible_openvpn/docker/dashboard/app/static/trigger.js +++ b/services/ansible_openvpn/docker/dashboard/app/static/trigger.js @@ -92,36 +92,36 @@ async function do_decrypt(jsonContent) { let el = document.getElementById("error_panel"); try { const pem = await $('input[name="privkey"]')[0].files[0].text(); + var encrypted = atob(jsonContent.encrypted_audio); + // convert a Forge certificate from PEM + const pki = forge.pki; + var privateKey = pki.decryptRsaPrivateKey(pem, $('input[name="pwd"]')[0].value); + if(privateKey == null) { + el.style.visibility = "visible"; + el.innerHTML = "Invalid decryption key or password"; + return; + } else { + el.style.visibility = "hidden"; + var decrypted = privateKey.decrypt(encrypted.substring(0, 512), 'RSA-OAEP'); + var aes_key = decrypted.substring(0, 16); + var iv = decrypted.substring(16, 32); + console.log("aeskey " + btoa(aes_key)); + console.log("iv " + btoa(iv)); + var decipher = forge.cipher.createDecipher('AES-CBC', aes_key); + decipher.start({iv: iv}); + decipher.update(forge.util.createBuffer(encrypted.substring(512))); + var result = decipher.finish(); // check 'result' for true/false + // outputs decrypted hex + // Create regex patterns for replacing unwanted characters in file name + const formattedDate = jsonContent.date.replace(new RegExp(`[-:]`, 'g'), "_"); + const fname = jsonContent.hwa+"_"+formattedDate+".flac"; + download(decipher.output.data, fname, "audio/flac"); + } } catch (e) { el.style.visibility = "visible"; el.innerHTML = "No private key file submitted "+e; return; } - var encrypted = atob(jsonContent.encrypted_audio); - // convert a Forge certificate from PEM - const pki = forge.pki; - var privateKey = pki.decryptRsaPrivateKey(pem, $('input[name="pwd"]')[0].value); - if(privateKey == null) { - el.style.visibility = "visible"; - el.innerHTML = "Invalid decryption key or password"; - return; - } else { - el.style.visibility = "hidden"; - var decrypted = privateKey.decrypt(encrypted.substring(0, 512), 'RSA-OAEP'); - var aes_key = decrypted.substring(0, 16); - var iv = decrypted.substring(16, 32); - console.log("aeskey " + btoa(aes_key)); - console.log("iv " + btoa(iv)); - var decipher = forge.cipher.createDecipher('AES-CBC', aes_key); - decipher.start({iv: iv}); - decipher.update(forge.util.createBuffer(encrypted.substring(512))); - var result = decipher.finish(); // check 'result' for true/false - // outputs decrypted hex - // Create regex patterns for replacing unwanted characters in file name - const formattedDate = jsonContent.date.replace(new RegExp(`[-:]`, 'g'), "_"); - const fname = jsonContent.hwa+"_"+formattedDate+".flac"; - download(decipher.output.data, fname, "audio/flac"); - } } function decrypt_and_download(sample_id) {