Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wss Error #47

Open
pawansingh00 opened this issue Apr 4, 2022 · 0 comments
Open

wss Error #47

pawansingh00 opened this issue Apr 4, 2022 · 0 comments

Comments

@pawansingh00
Copy link

pawansingh00 commented Apr 4, 2022

Hi,

I have the following code --

I run this on the remote machine which I want to access using - VNC

#!/usr/bin/env node

const GuacamoleLite = require('guacamole-lite');

const websocketOptions = {
    port: 8080 // we will accept connections to this port
};

const guacdOptions = {
    port: 4822 // port of guacd
};

const clientOptions = {
    log: {
        level: 'VERBOSE'
    },
    crypt: {
        cypher: 'AES-256-CBC',
        key: 'MySuperSecretKeyForParamsToken12'
    }
};

const guacServer = new GuacamoleLite(websocketOptions, guacdOptions, clientOptions);

And then

I try to connect to it using below code

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Page Title</title>
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <link rel="stylesheet" href="">
        <style></style>

        <!-- Guacamole -->
        <script type="text/javascript"
            src="https://unpkg.com/browse/[email protected]/dist/guacamole-common.js"></script>
    </head>
    
    
    <body>
    
        <!-- Display -->
        <div id="display"></div>
    
        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */
    
            // Get display div from document
            var display = document.getElementById("display");
    
            // Instantiate client, using an HTTP tunnel for communications.
            var guac = new Guacamole.Client(
                new Guacamole.WebSocketTunnel("ws://<PUBLIC_IP_OF_MACHINE>:8080")
            );
    
            // Add client to display div
            display.appendChild(guac.getDisplay().getElement());
            
            // Error handler
            guac.onerror = function(error) {
                console.log("Error :: ", error);
                alert(error);
            };
    
            // Connect
           guac.connect('token=<generated_token>');
                                
    
            // Disconnect on close
            window.onunload = function() {
                guac.disconnect();
            }
    
        /* ]]> */ </script>


        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            // Mouse
            var mouse = new Guacamole.Mouse(guac.getDisplay().getElement());

            mouse.onmousedown = 
            mouse.onmouseup   =
            mouse.onmousemove = function(mouseState) {
                guac.sendMouseState(mouseState);
            };

            // Keyboard
            var keyboard = new Guacamole.Keyboard(document);

            keyboard.onkeydown = function (keysym) {
                guac.sendKeyEvent(1, keysym);
            };

            keyboard.onkeyup = function (keysym) {
                guac.sendKeyEvent(0, keysym);
            };

        /* ]]> */ </script>
    
    </body>

</html>

In above code - <PUBLIC_IP_OF_MACHINE> - this is public IP of the machine which I want to access using VNC
and - <generated_token> - this is a token generated using the below script ---

const crypto = require('crypto');

const clientOptions = {
    cypher: 'AES-256-CBC',
    key: 'MySuperSecretKeyForParamsToken12'
}

const encrypt = (value) => {
    const iv = crypto.randomBytes(16);
    const cipher = crypto.createCipheriv(clientOptions.cypher, clientOptions.key, iv);

    let crypted = cipher.update(JSON.stringify(value), 'utf8', 'base64');
    crypted += cipher.final('base64');

    const data = {
        iv: iv.toString('base64'),
        value: crypted
    };

    return new Buffer(JSON.stringify(data)).toString('base64');
};

console.log("Token : " + encrypt({
    "connection": {
        "type": "vnc",
        "settings": {
            "hostname": "<PUBLIC_IP_OF_MACHINE>",
            "port": "5900",
            "username": "pawan",
            "password": "pawan"           
        }
    }
}));

It works when -- above index.html file is served over http.

When I serve the above - index.html file over https and modify
this

            var guac = new Guacamole.Client(
                new Guacamole.WebSocketTunnel("ws://<PUBLIC_IP_OF_MACHINE>:8080")
            );

as

            var guac = new Guacamole.Client(
                new Guacamole.WebSocketTunnel("ws://<PUBLIC_IP_OF_MACHINE>:8080")
            );

I get the below error in Browser console -

wss -- guacamole-common.js:13108 WebSocket connection to 'wss://<PUBLIC_IP_OF_MACHINE>:8080/?token=<token>' failed: [email protected]:[email protected]:3336(anonymous)@?userId=9had87:50

Any help is much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant