[#7135] Fix wrong password handling

Leftover after #7032. The node hasn't been started if the user entered a
wrong password, that's why `Statusgo.Verify` call has failed (it works
properly only with running node atm).

Implementation:
- the node is started with "dummy" configs if it's necessary to call
  `Statusgo.Verify` method
- on `Statusgo.Verify` callback node is stopped so that it can be
  started with proper configs on the next sign in attempt.
- signing in is disabled while the node is running

disable sign in while node is running

_

_
This commit is contained in:
Roman Volosovskyi 2018-12-18 18:12:02 +02:00
parent b4e2654b74
commit e122ebdb84
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
6 changed files with 73 additions and 39 deletions

View File

@ -14,7 +14,8 @@
[status-im.protocol.core :as protocol] [status-im.protocol.core :as protocol]
[status-im.models.wallet :as models.wallet] [status-im.models.wallet :as models.wallet]
[status-im.models.transactions :as transactions] [status-im.models.transactions :as transactions]
[status-im.i18n :as i18n])) [status-im.i18n :as i18n]
[status-im.node.core :as node]))
;; login flow: ;; login flow:
;; ;;
@ -126,10 +127,14 @@
:on-accept #(re-frame/dispatch :on-accept #(re-frame/dispatch
[:init.ui/account-data-reset-accepted address])}})) [:init.ui/account-data-reset-accepted address])}}))
(fx/defn verify-callback (fx/defn verify-callback
[{:keys [db] :as cofx} verify-result realm-error] [cofx verify-result realm-error]
(let [data (types/json->clj verify-result) (let [data (types/json->clj verify-result)
error (:error data) error (:error data)
success (empty? error)] success (empty? error)]
(fx/merge
cofx
{:node/stop nil}
(fn [{:keys [db] :as cofx}]
(if success (if success
(case (:error realm-error) (case (:error realm-error)
:decryption-failed :decryption-failed
@ -140,7 +145,7 @@
{:data-store/change-account [address password true]})) {:data-store/change-account [address password true]}))
{:db (update db :accounts/login assoc {:db (update db :accounts/login assoc
:error error :error error
:processing false)}))) :processing false)})))))
(fx/defn handle-change-account-error (fx/defn handle-change-account-error
[{:keys [db] :as cofx} error] [{:keys [db] :as cofx} error]
@ -148,7 +153,7 @@
(if (map? error) (if (map? error)
error error
{:message (str error)}) {:message (str error)})
{:keys [address password]} (accounts.db/credentials cofx) {:keys [address]} (accounts.db/credentials cofx)
erase-button (i18n/label :migrations-erase-accounts-data-button)] erase-button (i18n/label :migrations-erase-accounts-data-button)]
(case error (case error
:migrations-failed :migrations-failed
@ -168,12 +173,12 @@
:on-accept #(re-frame/dispatch :on-accept #(re-frame/dispatch
[:init.ui/account-data-reset-accepted address])}}) [:init.ui/account-data-reset-accepted address])}})
:database-does-not-exist (:database-does-not-exist :decryption-failed)
{:accounts.login/verify [address password realm-error]} (fx/merge cofx
{:db (-> db
:decryption-failed (assoc :node/on-ready :verify-account)
;; check if decryption failed because of wrong password (assoc :realm-error realm-error))}
{:accounts.login/verify [address password realm-error]} (node/initialize nil))
{:ui/show-confirmation {:ui/show-confirmation
{:title (i18n/label :unknown-realm-error) {:title (i18n/label :unknown-realm-error)

View File

@ -150,7 +150,7 @@
:keys [accounts/accounts accounts/create networks/networks network :keys [accounts/accounts accounts/create networks/networks network
network-status peers-count peers-summary view-id navigation-stack network-status peers-count peers-summary view-id navigation-stack
status-module-initialized? device-UUID semaphores accounts/login] status-module-initialized? device-UUID semaphores accounts/login]
:node/keys [status] :node/keys [status on-ready]
:or {network (get app-db :network)}} db :or {network (get app-db :network)}} db
current-account (get accounts address) current-account (get accounts address)
account-network-id (get current-account :network network) account-network-id (get current-account :network network)
@ -160,6 +160,7 @@
:navigation-stack navigation-stack :navigation-stack navigation-stack
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
:node/status status :node/status status
:node/on-ready on-ready
:accounts/create create :accounts/create create
:networks/networks networks :networks/networks networks
:account/account current-account :account/account current-account

View File

@ -125,6 +125,16 @@
:always :always
(add-log-level log-level)))) (add-log-level log-level))))
(defn get-verify-account-config
"Is used when the node has to be started before
`VerifyAccountPassword` call."
[db network]
(-> (get-in (:networks/networks db) [network :config])
(get-base-node-config)
(assoc :PFSEnabled false
:NoDiscovery true)
(add-log-level config/log-level-status-go)))
(fx/defn update-sync-state (fx/defn update-sync-state
[{:keys [db]} error sync-state] [{:keys [db]} error sync-state]
{:db (assoc db :node/chain-sync-state {:db (assoc db :node/chain-sync-state
@ -142,7 +152,9 @@
(let [network (if address (let [network (if address
(get-account-network db address) (get-account-network db address)
(:network db)) (:network db))
node-config (get-account-node-config db address) node-config (if (= (:node/on-ready db) :verify-account)
(get-verify-account-config db network)
(get-account-node-config db address))
node-config-json (types/clj->json node-config)] node-config-json (types/clj->json node-config)]
(log/info "Node config: " node-config-json) (log/info "Node config: " node-config-json)
{:db (assoc db {:db (assoc db

View File

@ -14,9 +14,7 @@
(fx/defn status-node-started (fx/defn status-node-started
[{db :db :as cofx}] [{db :db :as cofx}]
(let [{:node/keys [restart? address on-ready] (let [{:node/keys [restart? address on-ready]
:accounts/keys [create]} db :accounts/keys [create]} db]
can-login? (and (not restart?)
(:password (accounts.db/credentials cofx)))]
(fx/merge cofx (fx/merge cofx
{:db (-> db {:db (-> db
(assoc :node/status :started) (assoc :node/status :started)
@ -25,12 +23,18 @@
(when restart? (when restart?
(node/initialize address)) (node/initialize address))
(when can-login? (case on-ready
(accounts.login/login)) :login
(when (= :create-account on-ready) (accounts.login/login)
:verify-account
(let [{:keys [address password]} (accounts.db/credentials cofx)]
(fn [_] (fn [_]
{:accounts.create/create-account (:password create)})) {:accounts.login/verify
(when (= :recover-account on-ready) [address password (:realm-error db)]}))
:create-account
(fn [_]
{:accounts.create/create-account (:password create)})
:recover-account
(fn [{:keys [db]}] (fn [{:keys [db]}]
(let [{:keys [password passphrase]} (:accounts/recover db)] (let [{:keys [password passphrase]} (:accounts/recover db)]
{:accounts.recover/recover-account {:accounts.recover/recover-account

View File

@ -55,9 +55,10 @@
name]]]) name]]])
(defview login [] (defview login []
(letsubs [{:keys [address photo-path name password error processing save-password? can-save-password?]} [:get :accounts/login] (letsubs [{:keys [photo-path name error processing save-password? can-save-password?]} [:get :accounts/login]
can-navigate-back? [:can-navigate-back?] can-navigate-back? [:can-navigate-back?]
password-text-input (atom nil)] password-text-input (atom nil)
sign-in-enabled? [:sign-in-enabled?]]
[react/keyboard-avoiding-view {:style ast/accounts-view} [react/keyboard-avoiding-view {:style ast/accounts-view}
[status-bar/status-bar] [status-bar/status-bar]
[login-toolbar can-navigate-back?] [login-toolbar can-navigate-back?]
@ -72,7 +73,8 @@
:placeholder (i18n/label :t/password) :placeholder (i18n/label :t/password)
:ref #(reset! password-text-input %) :ref #(reset! password-text-input %)
:auto-focus true :auto-focus true
:on-submit-editing #(login-account @password-text-input) :on-submit-editing (when sign-in-enabled?
#(login-account @password-text-input))
:on-change-text #(do :on-change-text #(do
(re-frame/dispatch [:set-in [:accounts/login :password] (re-frame/dispatch [:set-in [:accounts/login :password]
(security/mask-data %)]) (security/mask-data %)])
@ -102,5 +104,5 @@
[components.common/bottom-button [components.common/bottom-button
{:forward? true {:forward? true
:label (i18n/label :t/sign-in) :label (i18n/label :t/sign-in)
:disabled? (not (spec/valid? ::db/password (security/safe-unmask-data password))) :disabled? (not sign-in-enabled?)
:on-press #(login-account @password-text-input)}]])])) :on-press #(login-account @password-text-input)}]])]))

View File

@ -2,7 +2,8 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.accounts.db :as db] [status-im.accounts.db :as db]
[status-im.utils.ethereum.core :as ethereum] [status-im.utils.ethereum.core :as ethereum]
[cljs.spec.alpha :as spec])) [cljs.spec.alpha :as spec]
[status-im.utils.security :as security]))
(re-frame/reg-sub (re-frame/reg-sub
:accounts/accounts :accounts/accounts
@ -40,3 +41,12 @@
:get-recover-account :get-recover-account
(fn [db] (fn [db]
(:accounts/recover db))) (:accounts/recover db)))
(re-frame/reg-sub
:sign-in-enabled?
:<- [:get :accounts/login]
:<- [:get :node/status]
(fn [[{:keys [password]} status]]
(and (or (nil? status) (= status :stopped))
(spec/valid? ::db/password
(security/safe-unmask-data password)))))