From ad99ed2a28f17dc5e3ec95d42fb389aa2f8595c6 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Fri, 21 Dec 2018 09:32:56 +0100 Subject: [PATCH] Allow toggling pfs in dev-mode This commits allow users to toggle pfs in dev-mode (it is already used for pairing and group chats). Once enabled direct and public messages sent will only be received by users running >= 0.9.32. Also this does not guarantee PFS (both devices need to have it enabled it), and there still some UX work to do to ensure that, but it is useful for testing. A warning is displayed explaining the limitations when enabling. --- .env | 2 +- .env.e2e | 2 +- .env.jenkins | 2 +- .env.nightly | 2 +- .env.nightly.staging.fleet | 2 +- .env.prod | 2 +- STATUS_GO_VERSION | 2 +- src/status_im/accounts/core.cljs | 10 ++++++++++ src/status_im/events.cljs | 5 +++++ src/status_im/transport/message/protocol.cljs | 20 ++++++++++--------- .../desktop/main/tabs/profile/views.cljs | 17 ++++++++++++---- .../ui/screens/profile/user/views.cljs | 7 +++++++ translations/en.json | 3 +++ 13 files changed, 56 insertions(+), 20 deletions(-) diff --git a/.env b/.env index ee80e168ec..bf57c6f301 100644 --- a/.env +++ b/.env @@ -13,7 +13,7 @@ PAIRING_ENABLED=1 CACHED_WEBVIEWS_ENABLED=1 EXTENSIONS=1 HARDWALLET_ENABLED=0 -PFS_ENCRYPTION_ENABLED=0 +PFS_ENCRYPTION_ENABLED=1 DEV_BUILD=1 ERC20_CONTRACT_WARNINGS=1 MAILSERVER_CONFIRMATIONS_ENABLED=0 diff --git a/.env.e2e b/.env.e2e index b6d34b9214..84c095388a 100644 --- a/.env.e2e +++ b/.env.e2e @@ -10,6 +10,6 @@ DEBUG_WEBVIEW=1 GROUP_CHATS_ENABLED=1 PAIRING_ENABLED=1 EXTENSIONS=1 -PFS_ENCRYPTION_ENABLED=0 +PFS_ENCRYPTION_ENABLED=1 ERC20_CONTRACT_WARNINGS=1 MAILSERVER_CONFIRMATIONS_ENABLED=0 diff --git a/.env.jenkins b/.env.jenkins index 84b8b91214..39efc88bd8 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -12,7 +12,7 @@ GROUP_CHATS_ENABLED=1 MAINNET_WARNING_ENABLED=1 CACHED_WEBVIEWS_ENABLED=1 EXTENSIONS=1 -PFS_ENCRYPTION_ENABLED=0 +PFS_ENCRYPTION_ENABLED=1 PAIRING_ENABLED=1 ERC20_CONTRACT_WARNINGS=1 MAILSERVER_CONFIRMATIONS_ENABLED=0 diff --git a/.env.nightly b/.env.nightly index cc93037984..8afa36234c 100644 --- a/.env.nightly +++ b/.env.nightly @@ -12,6 +12,6 @@ GROUP_CHATS_ENABLED=1 PAIRING_ENABLED=1 MAINNET_WARNING_ENABLED=1 EXTENSIONS=1 -PFS_ENCRYPTION_ENABLED=0 +PFS_ENCRYPTION_ENABLED=1 ERC20_CONTRACT_WARNINGS=1 MAILSERVER_CONFIRMATIONS_ENABLED=0 diff --git a/.env.nightly.staging.fleet b/.env.nightly.staging.fleet index 0826073f24..e7c76eaba1 100644 --- a/.env.nightly.staging.fleet +++ b/.env.nightly.staging.fleet @@ -11,6 +11,6 @@ PAIRING_ENABLED=1 GROUP_CHATS_ENABLED=1 MAINNET_WARNING_ENABLED=1 EXTENSIONS=1 -PFS_ENCRYPTION_ENABLED=0 +PFS_ENCRYPTION_ENABLED=1 ERC20_CONTRACT_WARNINGS=1 MAILSERVER_CONFIRMATIONS_ENABLED=0 diff --git a/.env.prod b/.env.prod index 5755396c32..d3b1de8bcf 100644 --- a/.env.prod +++ b/.env.prod @@ -13,5 +13,5 @@ GROUP_CHATS_ENABLED=1 PAIRING_ENABLED=1 MAINNET_WARNING_ENABLED=1 EXTENSIONS=1 -PFS_ENCRYPTION_ENABLED=0 +PFS_ENCRYPTION_ENABLED=1 ERC20_CONTRACT_WARNINGS=0 diff --git a/STATUS_GO_VERSION b/STATUS_GO_VERSION index 3ecb42649f..f1639633a9 100644 --- a/STATUS_GO_VERSION +++ b/STATUS_GO_VERSION @@ -1 +1 @@ -0.17.10-beta.1 +181221-204011-e80de6 diff --git a/src/status_im/accounts/core.cljs b/src/status_im/accounts/core.cljs index 4e9a909780..4578a15d49 100644 --- a/src/status_im/accounts/core.cljs +++ b/src/status_im/accounts/core.cljs @@ -67,6 +67,16 @@ {:desktop-notifications? desktop-notifications?} {})) +(fx/defn toggle-pfs [{:keys [db] :as cofx} enabled?] + (let [settings (get-in db [:account/account :settings]) + warning {:utils/show-popup {:title (i18n/label :t/pfs-warning-title) + :content (i18n/label :t/pfs-warning-content)}}] + + (fx/merge cofx + (when enabled? warning) + (accounts.update/update-settings (assoc settings :pfs? enabled?) + {})))) + (fx/defn switch-web3-opt-in-mode [{:keys [db] :as cofx} opt-in] (let [settings (get-in db [:account/account :settings])] (accounts.update/update-settings cofx diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 82c298ed63..1a83b1c23f 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -153,6 +153,11 @@ (fn [cofx [_ desktop-notifications?]] (accounts/enable-notifications cofx desktop-notifications?))) +(handlers/register-handler-fx + :accounts.ui/toggle-pfs + (fn [cofx [_ enabled?]] + (accounts/toggle-pfs cofx enabled?))) + (handlers/register-handler-fx :accounts.ui/web3-opt-in-mode-switched (fn [cofx [_ opt-in]] diff --git a/src/status_im/transport/message/protocol.cljs b/src/status_im/transport/message/protocol.cljs index 21317bf22c..1266be424b 100644 --- a/src/status_im/transport/message/protocol.cljs +++ b/src/status_im/transport/message/protocol.cljs @@ -85,6 +85,7 @@ StatusMessage (send [this chat-id {:keys [message-id] :as cofx}] (let [dev-mode? (get-in cofx [:db :account/account :dev-mode?]) + pfs? (get-in cofx [:db :account/account :settings :pfs?]) current-public-key (accounts.db/current-public-key cofx) params {:chat-id chat-id :payload this @@ -94,7 +95,7 @@ message-type]}] (case message-type :public-group-user-message - (if config/pfs-encryption-enabled? + (if pfs? (send-public-message cofx chat-id @@ -103,7 +104,7 @@ (send-with-sym-key cofx params)) :user-message - (if config/pfs-encryption-enabled? + (if pfs? (send-direct-message cofx chat-id @@ -133,13 +134,14 @@ (defrecord MessagesSeen [message-ids] StatusMessage (send [this chat-id cofx] - (if config/pfs-encryption-enabled? - (send-direct-message cofx - chat-id - nil - this) - (send-with-pubkey cofx {:chat-id chat-id - :payload this}))) + (let [pfs? (get-in cofx [:db :account/account :settings :pfs?])] + (if pfs? + (send-direct-message cofx + chat-id + nil + this) + (send-with-pubkey cofx {:chat-id chat-id + :payload this})))) (receive [this chat-id signature _ cofx] (chat/receive-seen cofx chat-id signature this)) (validate [this] diff --git a/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs b/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs index 69bad0bec1..0ff0eb33a5 100644 --- a/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs +++ b/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs @@ -150,8 +150,8 @@ (i18n/label :t/send-logs)]]]])) (views/defview advanced-settings [] - (views/letsubs [installations [:pairing/installations] - current-mailserver-id [:mailserver/current-id] + (views/letsubs [current-mailserver-id [:mailserver/current-id] + {:keys [settings]} [:account/account] mailservers [:mailserver/fleet-mailservers] mailserver-state [:mailserver/state] node-status [:node-status] @@ -159,7 +159,8 @@ connection-stats [:connection-stats] disconnected [:disconnected?]] (let [render-fn (offline-messaging.views/render-row current-mailserver-id) - connection-message (connection-status peers-count node-status mailserver-state disconnected)] + pfs? (:pfs? settings) + connection-message (connection-status peers-count node-status mailserver-state disconnected)] [react/scroll-view [react/text {:style styles/advanced-settings-title :font :medium} @@ -182,7 +183,15 @@ [render-fn mailserver]])] [react/view {:style styles/title-separator}] [react/text {:style styles/adv-settings-subtitle} (i18n/label :t/logging)] - [logging-display]]))) + [logging-display] + + [react/view {:style styles/title-separator}] + [react/text {:style styles/adv-settings-subtitle} (i18n/label :t/pfs)] + [react/view {:style (styles/profile-row false)} + [react/text {:style (styles/profile-row-text colors/black)} (i18n/label :notifications)] + [react/switch {:on-tint-color colors/blue + :value pfs? + :on-value-change #(re-frame/dispatch [:accounts.ui/toggle-pfs (not pfs?)])}]]]))) (views/defview installations [] (views/letsubs [installations [:pairing/installations] diff --git a/src/status_im/ui/screens/profile/user/views.cljs b/src/status_im/ui/screens/profile/user/views.cljs index a52735ef5d..760fc3fc72 100644 --- a/src/status_im/ui/screens/profile/user/views.cljs +++ b/src/status_im/ui/screens/profile/user/views.cljs @@ -196,6 +196,13 @@ {:label-kw :t/devices :action-fn #(re-frame/dispatch [:navigate-to :installations]) :accessibility-label :pairing-settings-button}]) + (when dev-mode? + [profile.components/settings-item-separator]) + (when dev-mode? + [profile.components/settings-switch-item + {:label-kw :t/pfs + :value (:pfs? settings) + :action-fn #(re-frame/dispatch [:accounts.ui/toggle-pfs %])}]) [profile.components/settings-item-separator] [profile.components/settings-switch-item {:label-kw :t/dev-mode diff --git a/translations/en.json b/translations/en.json index ffe1933696..a11574344b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -23,6 +23,9 @@ "currency-display-name-tzs": "Tanzanian Shilling", "currency-display-name-brl": "Brazil Real", "mainnet-network": "Main network", + "pfs": "PFS Enabled", + "pfs-warning-title": "Warning, experimental feature", + "pfs-warning-content": "PFS support is still experimental, so use at your own risk.\nIf enabled, only users who are running 0.9.32 and higher will be able to read your direct and public messages. This does not guarantee PFS for all your messages yet, and it will only encrypt your messages, not the one you receive.", "phone-national": "National", "open-dapp": "Open ÐApp", "new-transaction": "New Transaction",