cscg24-guacamole

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

ClientExample.jsx (1798B)


      1import Guacamole from 'guacamole-common-js';
      2import React from 'react';
      3import crypto from "crypto";
      4
      5// DO NOT keep this in your frontend application!
      6// This is just an example.
      7// See "Security Considerations" in the docs/advanced-configuration.md
      8const CIPHER = 'aes-256-cbc';
      9const SECRET_KEY = 'MySuperSecretKeyForParamsToken12';
     10const tokenObject = {
     11  connection: {
     12    type: "rdp",
     13    settings: {
     14      "hostname": "10.0.0.12",
     15      "username": "Administrator",
     16      "password": "pAsSwOrD",
     17      "enable-drive": true,
     18      "create-drive-path": true,
     19      "security": "any",
     20      "ignore-cert": true,
     21      "enable-wallpaper": false
     22    }
     23  }
     24};
     25
     26// DO NOT do this in your frontend application!
     27// This is just an example.
     28// See "Security Considerations" in the docs/advanced-configuration.md
     29// This is just an example
     30function encryptToken(value) {
     31  const iv = crypto.randomBytes(16);
     32  const cipher = crypto.createCipheriv(CIPHER, Buffer.from(SECRET_KEY), iv);
     33
     34  let encrypted = cipher.update(JSON.stringify(value), 'utf8', 'base64');
     35  encrypted += cipher.final('base64');
     36
     37  const data = {
     38    iv: iv.toString('base64'),
     39    value: encrypted
     40  };
     41
     42  const json = JSON.stringify(data);
     43  return Buffer.from(json).toString('base64');
     44}
     45
     46
     47class GuacamoleStage extends React.Component {
     48  constructor(props) {
     49    super(props);
     50    this.myRef = React.createRef();
     51
     52    this.token = encryptToken(tokenObject);
     53
     54    this.tunnel = new Guacamole.WebSocketTunnel('ws://localhost:8080/');
     55    this.client = new Guacamole.Client(this.tunnel);
     56  }
     57
     58  componentDidMount() {
     59    this.myRef.current.appendChild(this.client.getDisplay().getElement());
     60    this.client.connect('token='+this.token);
     61  }
     62
     63  render() {
     64    return <div ref={this.myRef} />;
     65  }
     66}
     67
     68export default GuacamoleStage
     69