From f735693d7568d052bbc0ff6d850f44252b9a7e52 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 3 Aug 2022 12:48:35 -0700 Subject: [PATCH] Relay sessions like SSH and RDP would randomly get stuck at 'Setup...', this is now fixed. --- apprelays.js | 8 ++++---- meshrelay.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apprelays.js b/apprelays.js index 39ac108f..bc910eb3 100644 --- a/apprelays.js +++ b/apprelays.js @@ -836,7 +836,7 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) { rdpClient = require('./rdp').createClient(args).on('connect', function () { send(['rdp-connect']); if ((typeof obj.infos.options == 'object') && (obj.infos.options.savepass == true)) { saveRdpCredentials(); } // Save the credentials if needed - obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64'); + obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); obj.startTime = Date.now(); // Event session start @@ -1173,7 +1173,7 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) { obj.sshClient.on('ready', function () { // Authentication was successful. // If requested, save the credentials saveSshCredentials(obj.keep); - obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64'); + obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); obj.startTime = Date.now(); // Event start of session @@ -1512,7 +1512,7 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u obj.sshClient.on('ready', function () { // Authentication was successful. // If requested, save the credentials saveSshCredentials(obj.keep); - obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64'); + obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); obj.startTime = Date.now(); try { @@ -1866,7 +1866,7 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user obj.sshClient.on('ready', function () { // Authentication was successful. // If requested, save the credentials saveSshCredentials(obj.keep); - obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64'); + obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); obj.startTime = Date.now(); // Event start of session diff --git a/meshrelay.js b/meshrelay.js index c6119db8..3ad8f903 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -879,7 +879,7 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { const rcookieData = {}; if (user != null) { rcookieData.ruserid = user._id; } else if (obj.nouser === true) { rcookieData.nouser = 1; } const rcookie = parent.parent.encodeCookie(rcookieData, parent.parent.loginCookieEncryptionKey); - if (obj.id == null) { obj.id = parent.crypto.randomBytes(9).toString('base64'); } // If there is no connection id, generate one. + if (obj.id == null) { obj.id = parent.crypto.randomBytes(9).toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); } // If there is no connection id, generate one. const command = { nodeid: cookie.nodeid, action: 'msg', type: 'tunnel', value: '*/' + xdomain + 'meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, tcpport: cookie.tcpport, tcpaddr: cookie.tcpaddr, soptions: {} }; if (user) { command.userid = user._id; } if (typeof domain.consentmessages == 'object') { @@ -915,7 +915,7 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { obj.meshid = node.meshid; // Send connection request to agent - if (obj.id == null) { obj.id = parent.crypto.randomBytes(9).toString('base64'); } // If there is no connection id, generate one. + if (obj.id == null) { obj.id = parent.crypto.randomBytes(9).toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); } // If there is no connection id, generate one. const rcookie = parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey); if (obj.req.query.tcpport != null) { const command = { nodeid: obj.req.query.nodeid, action: 'msg', type: 'tunnel', userid: user._id, value: '*/' + xdomain + 'meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, tcpport: obj.req.query.tcpport, tcpaddr: ((obj.req.query.tcpaddr == null) ? '127.0.0.1' : obj.req.query.tcpaddr), soptions: {} }; @@ -971,7 +971,7 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { obj.meshid = node.meshid; // Send connection request to agent - if (obj.id == null) { obj.id = parent.crypto.randomBytes(9).toString('base64'); } // If there is no connection id, generate one. + if (obj.id == null) { obj.id = parent.crypto.randomBytes(9).toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); } // If there is no connection id, generate one. const rcookieData = { nodeid: node._id }; if (user != null) { rcookieData.ruserid = user._id; } else if (obj.nouser === true) { rcookieData.nouser = 1; } const rcookie = parent.parent.encodeCookie(rcookieData, parent.parent.loginCookieEncryptionKey); @@ -1117,7 +1117,7 @@ module.exports.CreateLocalRelay = function (parent, ws, req, domain, user, cooki function CreateLocalRelayEx(parent, ws, req, domain, user, cookie) { const net = require('net'); var obj = {}; - obj.id = parent.crypto.randomBytes(9).toString('base64'); + obj.id = parent.crypto.randomBytes(9).toString('base64').replace(/\+/g, '@').replace(/\//g, '$'); obj.req = req; obj.ws = ws; obj.user = user;