Add pfs flag, installation id and nobackup data directory

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-09-20 11:49:34 +02:00
parent 83cd95ff3c
commit df51731fca
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
21 changed files with 142 additions and 22 deletions

1
.env
View File

@ -16,3 +16,4 @@ GROUP_CHATS_ENABLED=0
CACHED_WEBVIEWS_ENABLED=1
EXTENSIONS=1
HARDWALLET_ENABLED=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -11,3 +11,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1
GROUP_CHATS_ENABLED=1
EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -14,3 +14,4 @@ GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1
CACHED_WEBVIEWS_ENABLED=1
EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -13,3 +13,4 @@ DEBUG_WEBVIEW=1
GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1
EXTENSIONS=1
PFS_ENCRYPTION_ENABLED=0

View File

@ -14,3 +14,4 @@ INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1
EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -15,3 +15,4 @@ DEBUG_WEBVIEW=0
GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1
EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -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");

View File

@ -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

View File

@ -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

View File

@ -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$" ""))

View File

@ -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}])

View File

@ -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))))))

View File

@ -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))

View File

@ -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)))

View File

@ -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)
@ -89,7 +91,11 @@
:LightClient true
:MinimumPoW 0.001
:EnableNTPSync true}
:RequireTopics (get-topics network))
: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)))

View File

@ -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)))

View File

@ -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)))

View File

@ -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 _]

View File

@ -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)))))))))

View File

@ -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

View File

@ -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))))))