From 75191ae7572e998a9080d3d01654fddbe594e527 Mon Sep 17 00:00:00 2001 From: warrickct Date: Thu, 3 Mar 2022 17:14:59 +1100 Subject: [PATCH] Add blocking joining open group based on blocklist. --- .github/workflows/build-binaries.yml | 3 --- package.json | 8 ++++++- preload.js | 21 +++++++++++++++- .../opengroupV2/JoinOpenGroupV2.ts | 21 ++++++++++++++++ ts/session/crypto/index.ts | 2 +- ts/window.d.ts | 1 + yarn.lock | 24 +++++++++++++++++++ 7 files changed, 74 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 06b3d3500..79c319bdf 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -57,9 +57,6 @@ jobs: repository: oxen-io/blocklist path: blocklist - - name: Find blocklist - run: find / -name "blocklist" 2>/dev/null - - name: Generate and concat files run: yarn generate diff --git a/package.json b/package.json index c0b353927..de180c126 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "jquery": "3.3.1", "jsbn": "1.1.0", "libsodium-wrappers": "^0.7.8", + "libsodium-wrappers-sumo": "^0.7.9", "linkify-it": "3.0.2", "lodash": "4.17.11", "long": "^4.0.0", @@ -139,6 +140,7 @@ "@types/fs-extra": "5.0.5", "@types/jquery": "3.3.29", "@types/libsodium-wrappers": "^0.7.8", + "@types/libsodium-wrappers-sumo": "^0.7.5", "@types/linkify-it": "2.0.3", "@types/lodash": "4.14.106", "@types/mocha": "5.0.0", @@ -250,7 +252,11 @@ "StartupWMClass": "Session" }, "asarUnpack": "node_modules/spellchecker/vendor/hunspell_dictionaries", - "target": ["deb", "rpm", "freebsd"], + "target": [ + "deb", + "rpm", + "freebsd" + ], "icon": "build/icon-linux.icns" }, "asarUnpack": [ diff --git a/preload.js b/preload.js index 49411a915..0f990ad8e 100644 --- a/preload.js +++ b/preload.js @@ -5,8 +5,10 @@ const path = require('path'); const { webFrame, remote, clipboard, ipcRenderer } = require('electron'); const { app } = remote; +const url = require('url'); +const fs = require('fs'); -const config = require('url').parse(window.location.toString(), true).query; +const config = url.parse(window.location.toString(), true).query; let title = config.name; if (config.environment !== 'production') { @@ -212,6 +214,23 @@ window.clipboard = clipboard; window.getSeedNodeList = () => JSON.parse(config.seedNodeList); +window.getOpenGroupBlockList = () => { + // const blocklist = url.parse(window.location.toString(), true).query; + if (!window.groupBlockList) { + try { + const blockList = fs + .readFileSync(path.resolve(__dirname, 'blocklist', 'blocklist.txt'), 'utf8') + .toString() + .split('\n'); + // TODO: trim whitespace + window.groupBlockList = blockList; + } catch (e) { + return []; + } + } + return window.groupBlockList; +}; + const { locale: localFromEnv } = config; window.i18n = i18n.setup(localFromEnv, localeMessages); diff --git a/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts b/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts index c3d2b7928..42179e6df 100644 --- a/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts +++ b/ts/session/apis/open_group_api/opengroupV2/JoinOpenGroupV2.ts @@ -1,5 +1,6 @@ import { getV2OpenGroupRoomByRoomId, OpenGroupV2Room } from '../../../../data/opengroups'; import { getConversationController } from '../../../conversations'; +import { getSodium } from '../../../crypto'; import { PromiseUtils, ToastUtils } from '../../../utils'; import { forceSyncConfigurationNowIfNeeded } from '../../../utils/syncUtils'; import { @@ -44,6 +45,22 @@ export function parseOpenGroupV2(urlWithPubkey: string): OpenGroupV2Room | undef return undefined; } +/** + * Checks if the group pubkey (hashed as blake2b) is in the list of blocked groups (also hashed) + * @param serverPubKey PubKey of the open group being evaluated + * @returns true - group is in the blocklist, false - the group is not in the blocklist + */ +export const isGroupInBlockList = async (serverPubKey: string): Promise => { + const blockList = window?.getOpenGroupBlockList(); + if (!blockList || !blockList.length) { + return false; + } + const sodium = await getSodium(); + // generic hash is blake2b + const serverPubKeyBlake2bHash = sodium.crypto_generichash(32, serverPubKey, null, 'hex'); + return blockList.includes(serverPubKeyBlake2bHash); +}; + /** * Join an open group using the v2 logic. * @@ -58,6 +75,10 @@ async function joinOpenGroupV2(room: OpenGroupV2Room, fromConfigMessage: boolean return; } + if (await isGroupInBlockList(room.serverPublicKey)) { + return; + } + const serverUrl = room.serverUrl.toLowerCase(); const roomId = room.roomId.toLowerCase(); const publicKey = room.serverPublicKey.toLowerCase(); diff --git a/ts/session/crypto/index.ts b/ts/session/crypto/index.ts index 995f8d726..56d821b06 100644 --- a/ts/session/crypto/index.ts +++ b/ts/session/crypto/index.ts @@ -6,7 +6,7 @@ import crypto from 'crypto'; // libsodium-wrappers requires the `require` call to work // tslint:disable-next-line: no-require-imports -import libsodiumwrappers from 'libsodium-wrappers'; +import libsodiumwrappers from 'libsodium-wrappers-sumo'; import { toHex } from '../utils/String'; import { ECKeyPair } from '../../receiver/keypairs'; diff --git a/ts/window.d.ts b/ts/window.d.ts index a075e8a5b..9d6bc4192 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -74,5 +74,6 @@ declare global { setStartInTray: (val: boolean) => Promise; getStartInTray: () => Promise; libsession: any; + getOpenGroupBlockList: () => Array; } } diff --git a/yarn.lock b/yarn.lock index e991939bd..5630dc7cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1056,6 +1056,18 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.8.tgz#edf1bf1dbf4e04413ca8e5b17b3b7d7d54b59818" integrity sha512-YSBPTLTVm2e2OoQIDYx8HaeWJ5tTToLH67kXR7zYNGupXMEHa2++G8k+DczX2cFVgalypqtyZIcU19AFcmOpmg== +"@types/libsodium-wrappers-sumo@^0.7.5": + version "0.7.5" + resolved "https://registry.yarnpkg.com/@types/libsodium-wrappers-sumo/-/libsodium-wrappers-sumo-0.7.5.tgz#c5191fc28d44edd39583552bd1855f6b7b77ca88" + integrity sha512-CL7rmLxw28H/FpFUnMu5BzzRsE+ICxHBpRoaY8ks+3HMsCJdA/Vp809sj+qNhw64Ht0OEnfoN3BC1sHwagoVaw== + dependencies: + "@types/libsodium-wrappers" "*" + +"@types/libsodium-wrappers@*": + version "0.7.9" + resolved "https://registry.yarnpkg.com/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.9.tgz#89c3ad2156d5143e64bce86cfeb0045a983aeccc" + integrity sha512-LisgKLlYQk19baQwjkBZZXdJL0KbeTpdEnrAfz5hQACbklCY0gVFnsKUyjfNWF1UQsCSjw93Sj5jSbiO8RPfdw== + "@types/libsodium-wrappers@^0.7.8": version "0.7.8" resolved "https://registry.yarnpkg.com/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.8.tgz#34575d7692fdbb7a7fdb63afcde381db86ec0de2" @@ -5867,6 +5879,18 @@ levn@^0.3.0, levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" +libsodium-sumo@^0.7.0: + version "0.7.9" + resolved "https://registry.yarnpkg.com/libsodium-sumo/-/libsodium-sumo-0.7.9.tgz#dff3d6144849e30d9b9a7bf628d28243f1c49102" + integrity sha512-DcfJ57zlSlcmQU4s8KOX78pT0zKx5S9RLi0oyDuoIgm4K95+VNSaOidK/y9lUK4lxft14PtTPjoBy8tmLk1TDQ== + +libsodium-wrappers-sumo@^0.7.9: + version "0.7.9" + resolved "https://registry.yarnpkg.com/libsodium-wrappers-sumo/-/libsodium-wrappers-sumo-0.7.9.tgz#d15a346870c8e339baf1518f06b0ddccfa1e1046" + integrity sha512-XLgLkqY973PngrRElbjOH0y7bJKYEfMWVpWPmW5iuhBjO6zXvHYQWtN52MVEeie/h98ZXN1Aw9BE+GzxQVAfLg== + dependencies: + libsodium-sumo "^0.7.0" + libsodium-wrappers@^0.7.8: version "0.7.8" resolved "https://registry.yarnpkg.com/libsodium-wrappers/-/libsodium-wrappers-0.7.8.tgz#d95cdf3e7236c2aef76844bf8e1929ba9eef3e9e"