From 5712193f72b1258b74e2c9e1dda548c4642731ef Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 22 Oct 2021 14:47:01 +0200 Subject: [PATCH] Bug Fixed Network --- Desktop/DesktopApp.js | 8 ++++---- DesktopRoot.js | 5 ++--- Environment.js | 7 ++++++- NetworkRoot.js | 4 ++-- Projects/Network/NT/Modules/WebSocketsInterface.js | 7 ++++--- Projects/Network/NT/Modules/WebSocketsNetworkClient.js | 6 +++--- Projects/Network/SA/Modules/WebSocketsAppClient.js | 6 +++--- Projects/Social-Trading/DK/modules/WebAppInterface.js | 4 ++-- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index 3a24eb71b..02e44aa7a 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -43,7 +43,7 @@ exports.newDesktopApp = function newDesktopApp() { */ queryMessage = { queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILES, - emitterUserProfileId: SA.secrets.map.get('Social Trading Desktop').userProfileId, + emitterUserProfileId: SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId, initialIndex: 'Last', amountRequested: 10, direction: 'Past' @@ -72,7 +72,7 @@ exports.newDesktopApp = function newDesktopApp() { let eventMessage = { eventId: SA.projects.foundations.utilities.miscellaneousFunctions.genereteUniqueId(), eventType: SA.projects.socialTrading.globals.eventTypes.FOLLOW_USER_PROFILE, - emitterUserProfileId: SA.secrets.map.get('Social Trading Desktop').userProfileId, + emitterUserProfileId: SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId, targetUserProfileId: profile.userProfileId } @@ -97,8 +97,8 @@ exports.newDesktopApp = function newDesktopApp() { */ queryMessage = { queryType: SA.projects.socialTrading.globals.queryTypes.USER_PROFILE_STATS, - emitterUserProfileId: SA.secrets.map.get('Social Trading Desktop').userProfileId, - targetUserProfileId: SA.secrets.map.get('Social Trading Desktop').userProfileId + emitterUserProfileId: SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId, + targetUserProfileId: SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId } query = { diff --git a/DesktopRoot.js b/DesktopRoot.js index 9cb84924a..c7440dee4 100644 --- a/DesktopRoot.js +++ b/DesktopRoot.js @@ -51,17 +51,16 @@ exports.newDesktopRoot = function newDesktopRoot() { simpleGit: require('simple-git'), nodeFetch: require('node-fetch') } - /* Setting up Secrets. */ SA.secrets = { - array: require('./My-Secrets/Secrets.json'), + array: require('./My-Secrets/Secrets.json').secrets, map: new Map() } for (let i = 0; i < SA.secrets.array.length; i++) { let secret = SA.secrets.array[i] - SA.secrets.map.set (secret.codeName, secret) + SA.secrets.map.set (secret.signingAccountChildCodeName, secret) } run() diff --git a/Environment.js b/Environment.js index 5d7a914af..41aa97b94 100644 --- a/Environment.js +++ b/Environment.js @@ -25,7 +25,12 @@ exports.newEnvironment = function () { PATH_TO_DESKTOP: './Desktop', PATH_TO_DEFAULT_WORKSPACE: path.join(basePath, './Projects/Foundations/Plugins/Workspaces'), PATH_TO_MY_WORKSPACES: path.join(basePath, './Platform/My-Workspaces'), - PATH_TO_FONTS: path.join(basePath, './Platform/WebServer/Fonts') + PATH_TO_FONTS: path.join(basePath, './Platform/WebServer/Fonts'), + DESKTOP_APP_SIGNING_ACCOUNT: 'Social-Trading-Desktop-App-1', + MOBILE_APP_SIGNING_ACCOUNT: 'Social-Trading-Mobile-App-1', + SERVER_APP_SIGNING_ACCOUNT: 'Social-Trading-Server-App-1', + PLATFORM_APP_SIGNING_ACCOUNT: 'Algo-Traders-Platform-1', + P2P_NETWORK_NODE_SIGNING_ACCOUNT: 'P2P-Network-Node-1', } if (process.env.PORTABLE_EXECUTABLE_DIR) { diff --git a/NetworkRoot.js b/NetworkRoot.js index dc0327fba..22e4df0e8 100644 --- a/NetworkRoot.js +++ b/NetworkRoot.js @@ -52,12 +52,12 @@ exports.newNetworkRoot = function newNetworkRoot() { Setting up Secrets. */ SA.secrets = { - array: require('./My-Secrets/Secrets.json'), + array: require('./My-Secrets/Secrets.json').secrets, map: new Map() } for (let i = 0; i < SA.secrets.array.length; i++) { let secret = SA.secrets.array[i] - SA.secrets.map.set(secret.codeName, secret) + SA.secrets.map.set(secret.signingAccountChildCodeName, secret) } NT.app = require('./Network/NetwokNode.js').newNetworkNode() diff --git a/Projects/Network/NT/Modules/WebSocketsInterface.js b/Projects/Network/NT/Modules/WebSocketsInterface.js index 32d00fd18..63c192f76 100644 --- a/Projects/Network/NT/Modules/WebSocketsInterface.js +++ b/Projects/Network/NT/Modules/WebSocketsInterface.js @@ -252,11 +252,11 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock */ let signedMessage = { callerProfileHandle: messageHeader.callerProfileHandle, - calledProfileHandle: SA.secrets.map.get('P2P Network Node').githubUsername, + calledProfileHandle: SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle, callerTimestamp: messageHeader.callerTimestamp, calledTimestamp: calledTimestamp } - let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get('P2P Network Node').privateKey) + let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).privateKey) let response = { result: 'Ok', @@ -345,7 +345,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock We will check that the signature includes this Network Node handle, to avoid man in the middle attackts. */ - if (signedMessage.calledProfileHandle !== SA.secrets.map.get('P2P Network Node').githubUsername) { + if (signedMessage.calledProfileHandle !== SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle) { let response = { result: 'Error', message: 'calledProfileHandle Does Not Match This Network Node Handle.' @@ -415,6 +415,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock } function removeCaller(caller) { + if (caller === undefined) { return } thisObject.callersMap.delete(caller.socket.id) diff --git a/Projects/Network/NT/Modules/WebSocketsNetworkClient.js b/Projects/Network/NT/Modules/WebSocketsNetworkClient.js index fb491a4db..89742008c 100644 --- a/Projects/Network/NT/Modules/WebSocketsNetworkClient.js +++ b/Projects/Network/NT/Modules/WebSocketsNetworkClient.js @@ -86,7 +86,7 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb let message = { messageType: 'Handshake', callerRole: 'Network Node', - callerProfileHandle: SA.secrets.map.get('Social Trading Desktop').githubUsername, + callerProfileHandle: SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle, callerTimestamp: callerTimestamp, step: 'One' } @@ -147,7 +147,7 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb We will check that the profile handle we sent to the Network Node, is returned at the signed message, to avoid man in the middle attackts. */ - if (signedMessage.callerProfileHandle !== SA.secrets.map.get('Social Trading Desktop').githubUsername) { + if (signedMessage.callerProfileHandle !== SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle) { console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node callerProfileHandle does not match my own userProfileHandle.') reject() return @@ -177,7 +177,7 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb */ socketClient.onmessage = socketMessage => { stepTwoResponse(socketMessage) } - let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get('Social Trading Desktop').privateKey) + let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).privateKey) let message = { messageType: 'Handshake', diff --git a/Projects/Network/SA/Modules/WebSocketsAppClient.js b/Projects/Network/SA/Modules/WebSocketsAppClient.js index 18572b7c7..2fe199596 100644 --- a/Projects/Network/SA/Modules/WebSocketsAppClient.js +++ b/Projects/Network/SA/Modules/WebSocketsAppClient.js @@ -86,7 +86,7 @@ exports.newNetworkModulesWebSocketsAppClient = function newNetworkModulesWebSock let message = { messageType: 'Handshake', callerRole: 'Network Client', - callerProfileHandle: SA.secrets.map.get('Social Trading Desktop').githubUsername, + callerProfileHandle: SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileHandle, callerTimestamp: callerTimestamp, step: 'One' } @@ -147,7 +147,7 @@ exports.newNetworkModulesWebSocketsAppClient = function newNetworkModulesWebSock We will check that the profile handle we sent to the Network Node, is returned at the signed message, to avoid man in the middle attackts. */ - if (signedMessage.callerProfileHandle !== SA.secrets.map.get('Social Trading Desktop').githubUsername) { + if (signedMessage.callerProfileHandle !== SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileHandle) { console.log('[ERROR] Web Sockets Client -> stepOneResponse -> The Network Node callerProfileHandle does not match my own userProfileHandle.') reject() return @@ -177,7 +177,7 @@ exports.newNetworkModulesWebSocketsAppClient = function newNetworkModulesWebSock */ socketClient.onmessage = socketMessage => { stepTwoResponse(socketMessage) } - let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get('Social Trading Desktop').privateKey) + let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileHandle) let message = { messageType: 'Handshake', diff --git a/Projects/Social-Trading/DK/modules/WebAppInterface.js b/Projects/Social-Trading/DK/modules/WebAppInterface.js index 364e36711..2eedc20bd 100644 --- a/Projects/Social-Trading/DK/modules/WebAppInterface.js +++ b/Projects/Social-Trading/DK/modules/WebAppInterface.js @@ -47,7 +47,7 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule } return JSON.stringify(response) } - queryMessage.emitterUserProfileId = SA.secrets.map.get('Social Trading Desktop').userProfileId + queryMessage.emitterUserProfileId = SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId messageHeader.queryMessage = JSON.stringify(queryMessage) let response @@ -126,7 +126,7 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule eventMessage.postText = undefined } - eventMessage.emitterUserProfileId = SA.secrets.map.get('Social Trading Desktop').userProfileId + eventMessage.emitterUserProfileId = SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId messageHeader.eventMessage = JSON.stringify(eventMessage) let response = {