From df51731fcabd75d7c020f353a6c5c56b249e6646 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Thu, 20 Sep 2018 11:49:34 +0200 Subject: [PATCH] Add pfs flag, installation id and nobackup data directory Signed-off-by: Andrea Maria Piana --- .env | 1 + .env.e2e | 1 + .env.jenkins | 1 + .env.nightly | 1 + .env.nightly.staging.fleet | 1 + .env.prod | 1 + .../react-native-status/desktop/rctstatus.cpp | 1 + src/status_im/accounts/create/core.cljs | 7 ++- src/status_im/accounts/db.cljs | 4 +- src/status_im/data_store/realm/core.cljs | 11 ++--- .../data_store/realm/schemas/base/core.cljs | 8 +++- .../realm/schemas/base/v11/account.cljs | 22 +++++++++ .../realm/schemas/base/v11/core.cljs | 13 ++++++ src/status_im/events.cljs | 6 ++- src/status_im/node/core.cljs | 17 +++++-- src/status_im/utils/config.cljs | 1 + src/status_im/utils/platform.cljs | 6 +++ src/status_im/utils/random.cljs | 8 ++++ test/cljs/status_im/test/node/core.cljs | 46 +++++++++++++++++++ test/cljs/status_im/test/runner.cljs | 2 + .../status_im/test/transport/handlers.cljs | 6 +-- 21 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 src/status_im/data_store/realm/schemas/base/v11/account.cljs create mode 100644 src/status_im/data_store/realm/schemas/base/v11/core.cljs create mode 100644 test/cljs/status_im/test/node/core.cljs diff --git a/.env b/.env index bb614b309f..7c5e71df33 100644 --- a/.env +++ b/.env @@ -16,3 +16,4 @@ GROUP_CHATS_ENABLED=0 CACHED_WEBVIEWS_ENABLED=1 EXTENSIONS=1 HARDWALLET_ENABLED=0 +PFS_ENCRYPTION_ENABLED=0 diff --git a/.env.e2e b/.env.e2e index 3d7431a5cf..8cf76a85c4 100644 --- a/.env.e2e +++ b/.env.e2e @@ -11,3 +11,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c DEBUG_WEBVIEW=1 GROUP_CHATS_ENABLED=1 EXTENSIONS=0 +PFS_ENCRYPTION_ENABLED=0 diff --git a/.env.jenkins b/.env.jenkins index 98c174045d..191c5ac7ad 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -14,3 +14,4 @@ GROUP_CHATS_ENABLED=0 MAINNET_WARNING_ENABLED=1 CACHED_WEBVIEWS_ENABLED=1 EXTENSIONS=0 +PFS_ENCRYPTION_ENABLED=0 diff --git a/.env.nightly b/.env.nightly index cda9cae687..1177ef0b15 100644 --- a/.env.nightly +++ b/.env.nightly @@ -13,3 +13,4 @@ DEBUG_WEBVIEW=1 GROUP_CHATS_ENABLED=0 MAINNET_WARNING_ENABLED=1 EXTENSIONS=1 +PFS_ENCRYPTION_ENABLED=0 diff --git a/.env.nightly.staging.fleet b/.env.nightly.staging.fleet index d92899a647..a05928377c 100644 --- a/.env.nightly.staging.fleet +++ b/.env.nightly.staging.fleet @@ -14,3 +14,4 @@ INSTABUG_SURVEYS=1 GROUP_CHATS_ENABLED=0 MAINNET_WARNING_ENABLED=1 EXTENSIONS=0 +PFS_ENCRYPTION_ENABLED=0 diff --git a/.env.prod b/.env.prod index 6031ac5ff5..82fbd76bcc 100644 --- a/.env.prod +++ b/.env.prod @@ -15,3 +15,4 @@ DEBUG_WEBVIEW=0 GROUP_CHATS_ENABLED=0 MAINNET_WARNING_ENABLED=1 EXTENSIONS=0 +PFS_ENCRYPTION_ENABLED=0 diff --git a/modules/react-native-status/desktop/rctstatus.cpp b/modules/react-native-status/desktop/rctstatus.cpp index 8b500763ca..18c6fece2b 100644 --- a/modules/react-native-status/desktop/rctstatus.cpp +++ b/modules/react-native-status/desktop/rctstatus.cpp @@ -99,6 +99,7 @@ void RCTStatus::startNode(QString configString) { } configJSON["DataDir"] = absDataDirPath; + configJSON["BackupDisabledDataDir"] = absDataDirPath; configJSON["KeyStoreDir"] = rootDir.absoluteFilePath("keystore"); configJSON["LogFile"] = dataDir.absoluteFilePath("geth.log"); diff --git a/src/status_im/accounts/create/core.cljs b/src/status_im/accounts/create/core.cljs index 87487c2228..5a8c630f61 100644 --- a/src/status_im/accounts/create/core.cljs +++ b/src/status_im/accounts/create/core.cljs @@ -11,6 +11,7 @@ [status-im.native-module.core :as status] [status-im.ui.screens.navigation :as navigation] [status-im.utils.config :as config] + [status-im.utils.random :as random] [status-im.utils.gfycat.core :as gfycat] [status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.hex :as utils.hex] @@ -48,9 +49,13 @@ {:db (assoc-in db [:accounts/accounts address] enriched-account) :data-store/base-tx [(accounts-store/save-account-tx enriched-account)]})) -(defn on-account-created [{:keys [pubkey address mnemonic]} password seed-backed-up {:keys [signing-phrase status db] :as cofx}] +(defn on-account-created [{:keys [pubkey address mnemonic]} password seed-backed-up {:keys [random-guid-generator + signing-phrase + status + db] :as cofx}] (let [normalized-address (utils.hex/normalize-hex address) account {:public-key pubkey + :installation-id (random-guid-generator) :address normalized-address :name (gfycat/generate-gfy pubkey) :status status diff --git a/src/status_im/accounts/db.cljs b/src/status_im/accounts/db.cljs index abe7820093..b7100ae7c1 100644 --- a/src/status_im/accounts/db.cljs +++ b/src/status_im/accounts/db.cljs @@ -40,12 +40,14 @@ (spec/def :account/sharing-usage-data? (spec/nilable boolean?)) (spec/def :account/dev-mode? (spec/nilable boolean?)) (spec/def :account/seed-backed-up? (spec/nilable boolean?)) +(spec/def :account/installation-id :global/not-empty-string) (spec/def :account/wallet-set-up-passed? (spec/nilable boolean?)) (spec/def :account/mainnet-warning-shown? (spec/nilable boolean?)) (spec/def :accounts/account (allowed-keys :req-un [:account/name :account/address :account/public-key - :account/photo-path :account/signing-phrase] + :account/photo-path :account/signing-phrase + :account/installation-id] :opt-un [:account/debug? :account/status :account/last-updated :account/email :account/signed-up? :account/network :account/networks :account/settings :account/wnode diff --git a/src/status_im/data_store/realm/core.cljs b/src/status_im/data_store/realm/core.cljs index be685d0729..894a607042 100644 --- a/src/status_im/data_store/realm/core.cljs +++ b/src/status_im/data_store/realm/core.cljs @@ -55,14 +55,9 @@ (.-defaultPath rn-dependencies/realm)) (def realm-dir - (cond - utils.platform/android? (str - (.-DocumentDirectoryPath rn-dependencies/fs) - "/../no_backup/realm/") - utils.platform/ios? (str - (.-LibraryDirectoryPath rn-dependencies/fs) - "/realm/") - :else (.-defaultPath rn-dependencies/realm))) + (if-let [path (utils.platform/no-backup-directory)] + (str path "/realm/") + (.-defaultPath rn-dependencies/realm))) (def old-realm-dir (string/replace old-base-realm-path #"default\.realm$" "")) diff --git a/src/status_im/data_store/realm/schemas/base/core.cljs b/src/status_im/data_store/realm/schemas/base/core.cljs index 75c5e88d79..08e53a455e 100644 --- a/src/status_im/data_store/realm/schemas/base/core.cljs +++ b/src/status_im/data_store/realm/schemas/base/core.cljs @@ -8,7 +8,8 @@ [status-im.data-store.realm.schemas.base.v7.core :as v7] [status-im.data-store.realm.schemas.base.v8.core :as v8] [status-im.data-store.realm.schemas.base.v9.core :as v9] - [status-im.data-store.realm.schemas.base.v10.core :as v10])) + [status-im.data-store.realm.schemas.base.v10.core :as v10] + [status-im.data-store.realm.schemas.base.v11.core :as v11])) ;; put schemas ordered by version (def schemas [{:schema v1/schema @@ -40,4 +41,7 @@ :migration v9/migration} {:schema v10/schema :schemaVersion 10 - :migration v10/migration}]) + :migration v10/migration} + {:schema v11/schema + :schemaVersion 11 + :migration v11/migration}]) diff --git a/src/status_im/data_store/realm/schemas/base/v11/account.cljs b/src/status_im/data_store/realm/schemas/base/v11/account.cljs new file mode 100644 index 0000000000..c3c56221cf --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v11/account.cljs @@ -0,0 +1,22 @@ +(ns status-im.data-store.realm.schemas.base.v11.account + (:require [taoensso.timbre :as log] + [clojure.string :as string] + [cognitect.transit :as transit] + [clojure.set :as set] + [status-im.utils.random :as random] + [status-im.data-store.realm.schemas.base.v10.account :as v10])) + +(def schema + (assoc-in v10/schema + [:properties :installation-id] + {:type :string})) + +(defn migration [old-realm new-realm] + (log/debug "migrating accounts schema v11") + (let [accounts (.objects new-realm "account")] + (dotimes [i (.-length accounts)] + (let [account (aget accounts i) + old-installation-id (aget account "installation-id") + installation-id (random/guid)] + (when (string/blank? old-installation-id) + (aset account "installation-id" installation-id)))))) diff --git a/src/status_im/data_store/realm/schemas/base/v11/core.cljs b/src/status_im/data_store/realm/schemas/base/v11/core.cljs new file mode 100644 index 0000000000..dc64182438 --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v11/core.cljs @@ -0,0 +1,13 @@ +(ns status-im.data-store.realm.schemas.base.v11.core + (:require [status-im.data-store.realm.schemas.base.v1.network :as network] + [status-im.data-store.realm.schemas.base.v4.bootnode :as bootnode] + [status-im.data-store.realm.schemas.base.v11.account :as account] + [taoensso.timbre :as log])) + +(def schema [network/schema + bootnode/schema + account/schema]) + +(defn migration [old-realm new-realm] + (log/debug "migrating base database v11: " old-realm new-realm) + (account/migration old-realm new-realm)) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index cad831a3a6..7d0aeba172 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -138,7 +138,8 @@ (handlers/register-handler-fx :accounts.create.callback/create-account-success - [(re-frame/inject-cofx :accounts.create/get-signing-phrase) + [(re-frame/inject-cofx :random-guid-generator) + (re-frame/inject-cofx :accounts.create/get-signing-phrase) (re-frame/inject-cofx :accounts.create/get-status)] (fn [cofx [_ result password]] (accounts.create/on-account-created result password false cofx))) @@ -187,7 +188,8 @@ (handlers/register-handler-fx :accounts.recover.callback/recover-account-success - [(re-frame/inject-cofx :accounts.create/get-signing-phrase) + [(re-frame/inject-cofx :random-guid-generator) + (re-frame/inject-cofx :accounts.create/get-signing-phrase) (re-frame/inject-cofx :accounts.create/get-status)] (fn [cofx [_ result password]] (accounts.recover/on-account-recovered result password cofx))) diff --git a/src/status_im/node/core.cljs b/src/status_im/node/core.cljs index 37b3421ea4..235da95c5e 100644 --- a/src/status_im/node/core.cljs +++ b/src/status_im/node/core.cljs @@ -4,6 +4,7 @@ [status-im.native-module.core :as status] [status-im.utils.config :as config] [status-im.utils.types :as types] + [status-im.utils.platform :as utils.platform] [taoensso.timbre :as log])) (defn- add-custom-bootnodes [config network all-bootnodes] @@ -65,6 +66,7 @@ current-fleet-key (fleet/current-fleet db address) current-fleet (get fleet/fleets current-fleet-key) {:keys [network + installation-id settings bootnodes networks]} (get accounts address) @@ -85,11 +87,15 @@ :StaticNodes (pick-nodes 2 (vals (:whisper current-fleet)))}) :always - (assoc :WhisperConfig {:Enabled true - :LightClient true - :MinimumPoW 0.001 - :EnableNTPSync true} - :RequireTopics (get-topics network)) + (assoc :WhisperConfig {:Enabled true + :LightClient true + :MinimumPoW 0.001 + :EnableNTPSync true} + :RequireTopics (get-topics network) + :BackupDisabledDataDir (utils.platform/no-backup-directory) + :InstallationID installation-id + :PFSEnabled (or config/pfs-encryption-enabled? + config/group-chats-enabled?)) (and config/bootnodes-settings-enabled? @@ -102,6 +108,7 @@ (defn get-node-config [db network] (-> (get-in (:networks/networks db) [network :config]) (get-base-node-config) + (assoc :PFSEnabled false) (assoc :NoDiscovery true) (add-log-level config/log-level-status-go))) diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index aa23cf9370..0772cb2670 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -23,6 +23,7 @@ (def rpc-networks-only? (enabled? (get-config :RPC_NETWORKS_ONLY "1"))) (def group-chats-enabled? (enabled? (get-config :GROUP_CHATS_ENABLED))) (def mainnet-warning-enabled? (enabled? (get-config :MAINNET_WARNING_ENABLED 0))) +(def pfs-encryption-enabled? (enabled? (get-config :PFS_ENCRYPTION_ENABLED "0"))) (def in-app-notifications-enabled? (enabled? (get-config :IN_APP_NOTIFICATIONS_ENABLED 0))) (def cached-webviews-enabled? (enabled? (get-config :CACHED_WEBVIEWS_ENABLED 0))) (def rn-bridge-threshold-warnings-enabled? (enabled? (get-config :RN_BRIDGE_THRESHOLD_WARNINGS 0))) diff --git a/src/status_im/utils/platform.cljs b/src/status_im/utils/platform.cljs index cf71d5713d..93c0113e82 100644 --- a/src/status_im/utils/platform.cljs +++ b/src/status_im/utils/platform.cljs @@ -26,3 +26,9 @@ android? android/platform-specific ios? ios/platform-specific :else (desktop/platform-specific (if platform (.-isMacOs platform) true)))) + +(defn no-backup-directory [] + (cond + android? (str (.-DocumentDirectoryPath rn-dependencies/fs) + "/../no_backup") + ios? (.-LibraryDirectoryPath rn-dependencies/fs))) diff --git a/src/status_im/utils/random.cljs b/src/status_im/utils/random.cljs index 3ccc24e41d..d63dae6de8 100644 --- a/src/status_im/utils/random.cljs +++ b/src/status_im/utils/random.cljs @@ -5,6 +5,9 @@ (def chance (dependencies/Chance.)) +(defn guid [] + (.guid chance)) + (defn id [] (str (datetime/timestamp) "-" (.guid chance))) @@ -19,6 +22,11 @@ [gen coll] (nth coll (seeded-rand-int gen (count coll)))) +(re-frame/reg-cofx + :random-guid-generator + (fn [coeffects _] + (assoc coeffects :random-guid-generator guid))) + (re-frame/reg-cofx :random-id (fn [coeffects _] diff --git a/test/cljs/status_im/test/node/core.cljs b/test/cljs/status_im/test/node/core.cljs new file mode 100644 index 0000000000..1cdefe409e --- /dev/null +++ b/test/cljs/status_im/test/node/core.cljs @@ -0,0 +1,46 @@ +(ns status-im.test.node.core + (:require [cljs.test :refer-macros [deftest is testing]] + [status-im.utils.config :as config] + [status-im.node.core :as node])) + +(defn- parse-node-config [config] + (-> config + :node/start + (js/JSON.parse) + (js->clj :keywordize-keys true))) + +(deftest start-test + (let [address "a" + cofx {:db {:accounts/accounts {address {:installation-id "id"}}}}] + (testing "installation-id" + (testing "the user is not logged in" + (let [actual (parse-node-config (node/start nil cofx))] + (is (not (:InstallationID actual))))) + (testing "the user is logged in" + (let [actual (parse-node-config (node/start address cofx))] + (is (= "id" (:InstallationID actual)))))) + (testing "pfs & group chats disabled" + (with-redefs [config/pfs-encryption-enabled? false + config/group-chats-enabled? false] + (testing "the user is not logged in" + (let [actual (parse-node-config (node/start nil cofx))] + (is (not (:PFSEnabled actual))))) + (testing "the user is logged in" + (let [actual (parse-node-config (node/start address cofx))] + (is (not (:PFSEnabled actual)))))) + (testing "pfs is enabled" + (with-redefs [config/pfs-encryption-enabled? true] + (testing "the user is not logged in" + (let [actual (parse-node-config (node/start nil cofx))] + (is (not (:PFSEnabled actual))))) + (testing "the user is logged in" + (let [actual (parse-node-config (node/start address cofx))] + (is (:PFSEnabled actual)))))) + (testing "group chats is enabled" + (with-redefs [config/group-chats-enabled? true] + (testing "the user is not logged in" + (let [actual (parse-node-config (node/start nil cofx))] + (is (not (:PFSEnabled actual))))) + (testing "the user is logged in" + (let [actual (parse-node-config (node/start address cofx))] + (is (:PFSEnabled actual))))))))) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index c3e3c18a2b..c732841941 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -10,6 +10,7 @@ [status-im.test.wallet.transactions.subs] [status-im.test.wallet.transactions.views] [status-im.test.mailserver.core] + [status-im.test.node.core] [status-im.test.models.bootnode] [status-im.test.models.account] [status-im.test.models.contact] @@ -74,6 +75,7 @@ 'status-im.test.init.core 'status-im.test.data-store.realm.core 'status-im.test.mailserver.core + 'status-im.test.node.core 'status-im.test.models.bootnode 'status-im.test.models.account 'status-im.test.models.contact diff --git a/test/cljs/status_im/test/transport/handlers.cljs b/test/cljs/status_im/test/transport/handlers.cljs index 220aa2155a..147e6e4ac8 100644 --- a/test/cljs/status_im/test/transport/handlers.cljs +++ b/test/cljs/status_im/test/transport/handlers.cljs @@ -13,10 +13,10 @@ (deftest receive-whisper-messages-test (testing "an error is reported" - (is (nil? (handlers/receive-whisper-messages {} [_ "error" #js [] nil])))) + (is (nil? (handlers/receive-whisper-messages {} [nil "error" #js [] nil])))) (testing "messages is undefined" - (is (nil? (handlers/receive-whisper-messages {} [_ nil js/undefined nil])))) + (is (nil? (handlers/receive-whisper-messages {} [nil nil js/undefined nil])))) (testing "happy path" - (let [actual (handlers/receive-whisper-messages {} [_ nil messages "1"])] + (let [actual (handlers/receive-whisper-messages {} [nil nil messages "1"])] (testing "it add an fx for the message" (is (:chat-received-message/add-fx actual))))))