vadimpronin / guacamole-lite

Node.js library for creating Guacamole-compatible servers. Guacamole is a RDP/VNC/SSH/Telnet client for HTML5 browsers.
Apache License 2.0
246 stars 78 forks source link

Decrypt method in Crypt.js fails #11

Open wperrigo opened 6 years ago

wperrigo commented 6 years ago

I was always getting a failure in the Decrypt method due to character issues. I had to replace one line to get it to work.

This: let encoded = JSON.parse(this.constructor.base64decode(encodedString));

Became this: let tempJSON = this.constructor.base64decode(encodedString) let encoded = JSON.parse(tempJSON.substr(0, tempJSON.indexOf('}')+1));

vadimpronin commented 6 years ago

Never seen such problem. Can you show me the code that you use to encode the token?

wperrigo commented 6 years ago
// SET ENCRYPTION OPTIONS FOR THE JSON TOKENS
const clientOptions = {
    crypt: {
        cypher: 'AES-256-CBC',
        key: 'hidden_super_secret_key'
    },
    connectionDefaultSettings: {
        rdp: {
            'create-drive-path': true,
            'security': 'any',
            'ignore-cert': true,
            'enable-wallpaper': false,
            'create-recording-path': true
        }
    }
}
const encrypt = (value) => {
    const iv = crypto.randomBytes(16)
    const cipher = crypto.createCipheriv(clientOptions.crypt.cypher, clientOptions.crypt.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')
}
wpcwzy commented 6 months ago

I was always getting a failure in the Decrypt method due to character issues. I had to replace one line to get it to work.

This: let encoded = JSON.parse(this.constructor.base64decode(encodedString));

Became this: let tempJSON = this.constructor.base64decode(encodedString) let encoded = JSON.parse(tempJSON.substr(0, tempJSON.indexOf('}')+1));

Thank you very much. This replacement fixes my problem XD