Skip to content

Commit

Permalink
fix js
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Feb 5, 2024
1 parent 2de7ea1 commit d75fd79
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions services/ansible_openvpn/docker/dashboard/app/static/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,27 @@ function decryptDataWithPrivateKey(data, key) {


async function do_decrypt(jsonContent) {
let el = document.getElementById("error_panel");
const el = document.getElementById("error_panel");
try {
const pem = await $('input[name="privkey"]')[0].files[0].text();
var encrypted = atob(jsonContent.encrypted_audio);
const 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);
const 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, privateKey.n.bitLength() / 8 ), '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);
const keyLength = privateKey.n.bitLength() / 8
const decrypted = privateKey.decrypt(encrypted.substring(0, privateKey.n.bitLength() / 8 ), 'RSA-OAEP');
const aes_key = decrypted.substring(0, 16);
const iv = decrypted.substring(16, 32);
const 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
decipher.update(forge.util.createBuffer(encrypted.substring(privateKey.n.bitLength() / 8)));
const 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'), "_");
Expand Down

0 comments on commit d75fd79

Please sign in to comment.