From f120117c807fa7d8e8fedb24965b90d80b2b04d6 Mon Sep 17 00:00:00 2001 From: Ravikant Singh Date: Thu, 19 Mar 2020 10:07:20 +0530 Subject: [PATCH 1/2] secure websocket connection for GridAPIClient --- src/grid-api-client.js | 5 ++++- src/syft.js | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/grid-api-client.js b/src/grid-api-client.js index 379214d5..ef45cbb2 100644 --- a/src/grid-api-client.js +++ b/src/grid-api-client.js @@ -7,7 +7,10 @@ const HTTP_PATH_VERB = { }; export default class GridAPIClient { - constructor({ url }) { + constructor({ url, allowInsecureUrl = false }) { + if (!allowInsecureUrl) { + url = url.replace('ws://', 'wss://'); + } this.transport = url.match(/^ws/i) ? 'ws' : 'http'; if (this.transport === 'ws') { this.wsUrl = url; diff --git a/src/syft.js b/src/syft.js index 5ed4909e..42e6b70b 100644 --- a/src/syft.js +++ b/src/syft.js @@ -22,7 +22,10 @@ export default class Syft { // For creating verbose logging should the worker desire this.logger = new Logger('syft.js', verbose); - this.gridClient = new GridAPIClient({ url }); + // Forcing connection to be secure if verbose value is false. + this.verbose = verbose; + + this.gridClient = new GridAPIClient({ url, allowInsecureUrl: verbose }); // objects registry this.objects = {}; @@ -30,9 +33,6 @@ export default class Syft { // For creating event listeners this.observer = new EventObserver(); - // Forcing connection to be secure if verbose value is false. - this.verbose = verbose; - this.worker_id = null; this.peerConfig = peerConfig; this.authToken = authToken; From c9999d9f5e3d4f28ead2bdc115ac3567e4d75dd8 Mon Sep 17 00:00:00 2001 From: Ravikant Singh Date: Thu, 19 Mar 2020 11:22:09 +0530 Subject: [PATCH 2/2] secure http connection for GridAPIClient --- src/grid-api-client.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/grid-api-client.js b/src/grid-api-client.js index ef45cbb2..934aaac5 100644 --- a/src/grid-api-client.js +++ b/src/grid-api-client.js @@ -8,9 +8,6 @@ const HTTP_PATH_VERB = { export default class GridAPIClient { constructor({ url, allowInsecureUrl = false }) { - if (!allowInsecureUrl) { - url = url.replace('ws://', 'wss://'); - } this.transport = url.match(/^ws/i) ? 'ws' : 'http'; if (this.transport === 'ws') { this.wsUrl = url; @@ -19,6 +16,10 @@ export default class GridAPIClient { this.httpUrl = url; this.wsUrl = url.replace(/^http(s)?/i, 'ws$1'); } + if (!allowInsecureUrl) { + this.wsUrl = this.wsUrl.replace('ws', 'wss'); + this.httpUrl = this.httpUrl.replace('http', 'https'); + } this.ws = null; this.logger = new Logger('grid', true); this.responseTimeout = 10000;