From 142bbd8eee1755679ece1998c1b1a3b8ad4bdd9c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 24 Mar 2021 10:42:35 +1100 Subject: [PATCH] disable getVersion to snodes calls as we don't need it anymore --- js/modules/debuglogs.js | 1 + ts/session/snode_api/lokiRpc.ts | 7 ++--- ts/session/snode_api/serviceNodeAPI.ts | 7 +++-- ts/session/snode_api/snodePool.ts | 26 ++++++++++++++----- ts/session/snode_api/swarmPollingStub.ts | 1 + .../integration/stubs/stub_message_api.ts | 2 ++ 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/js/modules/debuglogs.js b/js/modules/debuglogs.js index eb26aea5a..3fd76dd29 100644 --- a/js/modules/debuglogs.js +++ b/js/modules/debuglogs.js @@ -10,6 +10,7 @@ const USER_AGENT = `Session ${VERSION}`; // upload :: String -> Promise URL exports.upload = async content => { + window.log.warn('insecureNodeFetch => upload debugLogs'); const signedForm = await insecureNodeFetch(BASE_URL, { headers: { 'user-agent': USER_AGENT, diff --git a/ts/session/snode_api/lokiRpc.ts b/ts/session/snode_api/lokiRpc.ts index 7cde6be15..9376917c2 100644 --- a/ts/session/snode_api/lokiRpc.ts +++ b/ts/session/snode_api/lokiRpc.ts @@ -34,12 +34,9 @@ async function lokiFetch( if (url.match(/https:\/\//)) { // import that this does not get set in lokiFetch fetchOptions fetchOptions.agent = snodeHttpsAgent; - } else { - window.log.warn( - 'lokirpc:::lokiFetch - insecureNodeFetch http communication', - url - ); } + window.log.warn(`insecureNodeFetch => lokiFetch of ${url}`); + const response = await insecureNodeFetch(url, fetchOptions); if (!response.ok) { diff --git a/ts/session/snode_api/serviceNodeAPI.ts b/ts/session/snode_api/serviceNodeAPI.ts index 51d09ace4..95aa4dfe7 100644 --- a/ts/session/snode_api/serviceNodeAPI.ts +++ b/ts/session/snode_api/serviceNodeAPI.ts @@ -19,6 +19,10 @@ import { updateSnodesFor, } from './snodePool'; +/** + * Currently unused. If we need it again, be sure to update it to onion routing rather + * than using a plain nodeFetch + */ export async function getVersion( node: Snode, retries: number = 0 @@ -28,8 +32,7 @@ export async function getVersion( const { log } = window; try { - // window.log.info('insecureNodeFetch => plaintext for getVersion'); - + window.log.warn('insecureNodeFetch => plaintext for getVersion'); const result = await insecureNodeFetch( `https://${node.ip}:${node.port}/get_stats/v1`, { diff --git a/ts/session/snode_api/snodePool.ts b/ts/session/snode_api/snodePool.ts index 9288466c5..4bd6a21c3 100644 --- a/ts/session/snode_api/snodePool.ts +++ b/ts/session/snode_api/snodePool.ts @@ -136,13 +136,18 @@ function compareSnodes(lhs: any, rhs: any): boolean { return lhs.pubkey_ed25519 === rhs.pubkey_ed25519; } -// WARNING: this leaks our IP to all snodes but with no other identifying information -// except "that a client started up" or "ran out of random pool snodes" -// and the order of the list is randomized, so a snode can't tell if it just started or not +/** + * Request the version of the snode. + * THIS IS AN INSECURE NODE FETCH and leaks our IP to all snodes but with no other identifying information + * except "that a client started up" or "ran out of random pool snodes" + * and the order of the list is randomized, so a snode can't tell if it just started or not + */ async function requestVersion(node: any): Promise { const { log } = window; - const result = await getVersion(node); + // WARNING: getVersion is doing an insecure node fetch. + // be sure to update getVersion to onion routing if we need this call again. + const result = false; // await getVersion(node); if (result === false) { return; @@ -177,8 +182,13 @@ export function getNodesMinVersion(minVersion: string): Array { ); } -// now get version for all snodes -// also acts an early online test/purge of bad nodes +/** + * Currently unused as it makes call over insecure node fetch and we don't need + * to filter out nodes by versions anymore. + * + * now get version for all snodes + * also acts an early online test/purge of bad nodes + */ export async function getAllVersionsForRandomSnodePool(): Promise { const { log } = window; @@ -284,7 +294,9 @@ async function refreshRandomPoolDetail(seedNodes: Array): Promise { randomSnodePool.length, 'snodes' ); - void getAllVersionsForRandomSnodePool(); + // Warning: the call below will call getVersions to all existing nodes. + // And not with onion routing + // void getAllVersionsForRandomSnodePool(); } catch (e) { log.warn('LokiSnodeAPI::refreshRandomPool - error', e.code, e.message); /* diff --git a/ts/session/snode_api/swarmPollingStub.ts b/ts/session/snode_api/swarmPollingStub.ts index 29c908814..ae55a0c8b 100644 --- a/ts/session/snode_api/swarmPollingStub.ts +++ b/ts/session/snode_api/swarmPollingStub.ts @@ -12,6 +12,7 @@ export class SwarmPollingStub extends SwarmPolling { method: 'GET', }; + // insecureNodeFetch but this is a stub const res = await insecureNodeFetch( `${this.baseUrl}/messages?pubkey=${pubkeyStr}`, get diff --git a/ts/test/session/integration/stubs/stub_message_api.ts b/ts/test/session/integration/stubs/stub_message_api.ts index 0229f8d9e..352b9a328 100644 --- a/ts/test/session/integration/stubs/stub_message_api.ts +++ b/ts/test/session/integration/stubs/stub_message_api.ts @@ -23,6 +23,8 @@ class StubMessageAPI { }; const data64 = StringUtils.decode(data, 'base64'); + // insecureNodeFetch but this is a stub + await insecureNodeFetch( `${ this.baseUrl