cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

encrypt_token.js (1366B)


      1const crypto = require('crypto');
      2
      3const CIPHER = 'aes-256-cbc';
      4const SECRET_KEY = 'MySuperSecretKeyForParamsToken12';
      5
      6const tokenObject = {
      7    connection: {
      8        type: "rdp",
      9        settings: {
     10            "hostname": "10.0.0.12",
     11            "username": "Administrator",
     12            "password": "pAsSwOrD",
     13            "enable-drive": true,
     14            "create-drive-path": true,
     15            "security": "any",
     16            "ignore-cert": true,
     17            "enable-wallpaper": false
     18        }
     19    }
     20};
     21
     22function encryptToken(value) {
     23    const iv = crypto.randomBytes(16);
     24    const cipher = crypto.createCipheriv(CIPHER, Buffer.from(SECRET_KEY), iv);
     25
     26    let encrypted = cipher.update(JSON.stringify(value), 'utf8', 'base64');
     27    encrypted += cipher.final('base64');
     28
     29    const data = {
     30        iv: iv.toString('base64'),
     31        value: encrypted
     32    };
     33
     34    const json = JSON.stringify(data);
     35    return Buffer.from(json).toString('base64');
     36}
     37
     38const originalToken = JSON.stringify(tokenObject, null, 2);
     39const token = encryptToken(tokenObject);
     40const urlencodedToken = encodeURIComponent(token);
     41
     42console.log("Parameters:");
     43console.log(originalToken);
     44
     45console.log("\n");
     46
     47console.log("Encrypted token:");
     48console.log(token);
     49
     50console.log("\n");
     51
     52console.log("Use this token in the URL:");
     53console.log(`ws://localhost:8080/?token=${urlencodedToken}`);