From ddbef24281a58ab70e1a51b3cb8c9c924f429a1f Mon Sep 17 00:00:00 2001 From: emad-salah Date: Fri, 23 Apr 2021 17:33:43 +0000 Subject: [PATCH] Encryption toggle added --- .env.example | 4 ++-- src/server.js | 15 +++++++++------ utils/ECC/socket.js | 4 +++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 7fc89c40..f5199e6b 100644 --- a/.env.example +++ b/.env.example @@ -4,8 +4,8 @@ DATA_FILE_NAME=radata2 PEERS=["http://gun.shock.network:8765/gun"] # API Device Token MS_TO_TOKEN_EXPIRATION=4500000 -# E2EE -DISABLE_SHOCK_ENCRYPTION=false +# E2EE +SHOCK_ENCRYPTION_ECC=true CACHE_HEADERS_MANDATORY=true SHOCK_CACHE=true # Use only if disabling LND encrypt phrase (security risk) diff --git a/src/server.js b/src/server.js index b6abf803..921b4703 100644 --- a/src/server.js +++ b/src/server.js @@ -85,7 +85,7 @@ const server = program => { forked.send(params) }) - if (process.env.DISABLE_SHOCK_ENCRYPTION === 'true') { + if (process.env.SHOCK_ENCRYPTION_ECC === 'false') { logger.error('Encryption Mode: false') } else { logger.info('Encryption Mode: true') @@ -155,7 +155,10 @@ const server = program => { const deviceId = req.headers['encryption-device-id'] const oldSend = res.send - if (nonEncryptedRoutes.includes(req.path)) { + if ( + nonEncryptedRoutes.includes(req.path) || + process.env.SHOCK_ENCRYPTION_ECC === 'false' + ) { next() return } @@ -206,7 +209,7 @@ const server = program => { // Using classic promises syntax to avoid // modifying res.send's return type - if (authorized) { + if (authorized && process.env.SHOCK_ENCRYPTION_ECC !== 'false') { ECC.encryptMessage({ deviceId, message: args[0] @@ -216,7 +219,7 @@ const server = program => { }) } - if (!authorized) { + if (!authorized || process.env.SHOCK_ENCRYPTION_ECC === 'false') { args[0] = JSON.stringify(args[0]) oldSend.apply(res, args) } @@ -351,7 +354,7 @@ const server = program => { return randomField } - const newValue = await Encryption.generateRandomString() + const newValue = await Encryption.generateRandomString(length) await Storage.setItem(fieldName, newValue) return newValue } @@ -462,7 +465,7 @@ const server = program => { // app.use(bodyParser.json({limit: '100000mb'})); app.use(bodyParser.json({ limit: '50mb' })) app.use(bodyParser.urlencoded({ limit: '50mb', extended: true })) - if (process.env.DISABLE_SHOCK_ENCRYPTION !== 'true') { + if (process.env.SHOCK_ENCRYPTION_ECC !== 'false') { app.use(modifyResponseBody) } diff --git a/utils/ECC/socket.js b/utils/ECC/socket.js index ea50d906..8f25e9b5 100644 --- a/utils/ECC/socket.js +++ b/utils/ECC/socket.js @@ -26,7 +26,9 @@ const nonEncryptedEvents = [ /** * @param {string} eventName */ -const isNonEncrypted = eventName => nonEncryptedEvents.includes(eventName) +const isNonEncrypted = eventName => + nonEncryptedEvents.includes(eventName) || + process.env.SHOCK_ENCRYPTION_ECC === 'false' /** * @param {SimpleSocket} socket