diff --git a/app/api/server/default/info.js b/app/api/server/default/info.js index 12f3ac7fd97..861d9dfb36a 100644 --- a/app/api/server/default/info.js +++ b/app/api/server/default/info.js @@ -21,7 +21,7 @@ API.default.addRoute('info', { authRequired: false }, { API.default.addRoute('ecdh_proxy/initEncryptedSession', { authRequired: false }, { post() { return { - statusCode: 406, + statusCode: 200, body: { success: false, error: 'Not Acceptable', diff --git a/client/types/meteor.d.ts b/client/types/meteor.d.ts index a50c051a76f..90878ecd81c 100644 --- a/client/types/meteor.d.ts +++ b/client/types/meteor.d.ts @@ -30,6 +30,7 @@ declare module 'meteor/meteor' { send: (data: string) => void; }; _launchConnectionAsync: () => void; + allowConnection: (allow: boolean) => void; }; onMessage(message: string): void; diff --git a/ee/client/ecdh.ts b/ee/client/ecdh.ts index c6812440492..46654b941ee 100644 --- a/ee/client/ecdh.ts +++ b/ee/client/ecdh.ts @@ -9,7 +9,7 @@ const sessionPromise = new Promise((resolve) => { }); function init(session: ClientSession): void { - Meteor.connection._stream._launchConnectionAsync(); + Meteor.connection._stream.allowConnection(true); const _didMessage = Meteor.connection._stream.socket._didMessage.bind( Meteor.connection._stream.socket, @@ -41,16 +41,23 @@ async function initEncryptedSession(): Promise { if (response.status !== 200) { resolveSession(); - return Meteor.connection._stream._launchConnectionAsync(); + return Meteor.connection._stream.allowConnection(true); } - await session.setServerKey(await response.text()); + const data = await response.json(); + + if (data.success === false) { + resolveSession(); + return Meteor.connection._stream.allowConnection(true); + } + + await session.setServerKey(data.publicKeyString); resolveSession(session); init(session); } catch (e) { console.log(e); resolveSession(); - Meteor.connection._stream._launchConnectionAsync(); + Meteor.connection._stream.allowConnection(true); } } diff --git a/ee/server/services/ecdh-proxy/lib/server.ts b/ee/server/services/ecdh-proxy/lib/server.ts index a6b68d2f8db..07ca0eb040f 100644 --- a/ee/server/services/ecdh-proxy/lib/server.ts +++ b/ee/server/services/ecdh-proxy/lib/server.ts @@ -93,7 +93,10 @@ app.post('/api/ecdh_proxy/initEncryptedSession', async (req, res) => { const session = await getSessionCached(req.body.clientPublicKey); res.cookie('ecdhSession', req.body.clientPublicKey); - res.send(session.publicKeyString); + res.send({ + success: true, + publicKeyString: session.publicKeyString, + }); } catch (e) { res.status(400).send(e.message); } diff --git a/packages/rocketchat-ddp/client/index.js b/packages/rocketchat-ddp/client/index.js index f391245ddc0..9cd1907d52d 100644 --- a/packages/rocketchat-ddp/client/index.js +++ b/packages/rocketchat-ddp/client/index.js @@ -1,4 +1,15 @@ import { ClientStream } from 'meteor/socket-stream-client'; +ClientStream.prototype.connectionAllowed = false; +ClientStream.prototype.allowConnection = function(allow = true) { + this.connectionAllowed = allow; + this._launchConnection(); +}; + ClientStream.prototype._launchConnectionAsync = ClientStream.prototype._launchConnection; -ClientStream.prototype._launchConnection = function() {}; +ClientStream.prototype._launchConnection = function() { + if (!this.connectionAllowed) { + return; + } + this._launchConnectionAsync(); +};