[#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:
parent
b4e2654b74
commit
e122ebdb84
|
@ -14,7 +14,8 @@
|
|||
[status-im.protocol.core :as protocol]
|
||||
[status-im.models.wallet :as models.wallet]
|
||||
[status-im.models.transactions :as transactions]
|
||||
[status-im.i18n :as i18n]))
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.node.core :as node]))
|
||||
|
||||
;; login flow:
|
||||
;;
|
||||
|
@ -126,10 +127,14 @@
|
|||
:on-accept #(re-frame/dispatch
|
||||
[:init.ui/account-data-reset-accepted address])}}))
|
||||
(fx/defn verify-callback
|
||||
[{:keys [db] :as cofx} verify-result realm-error]
|
||||
[cofx verify-result realm-error]
|
||||
(let [data (types/json->clj verify-result)
|
||||
error (:error data)
|
||||
success (empty? error)]
|
||||
(fx/merge
|
||||
cofx
|
||||
{:node/stop nil}
|
||||
(fn [{:keys [db] :as cofx}]
|
||||
(if success
|
||||
(case (:error realm-error)
|
||||
:decryption-failed
|
||||
|
@ -140,7 +145,7 @@
|
|||
{:data-store/change-account [address password true]}))
|
||||
{:db (update db :accounts/login assoc
|
||||
:error error
|
||||
:processing false)})))
|
||||
:processing false)})))))
|
||||
|
||||
(fx/defn handle-change-account-error
|
||||
[{:keys [db] :as cofx} error]
|
||||
|
@ -148,7 +153,7 @@
|
|||
(if (map? error)
|
||||
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)]
|
||||
(case error
|
||||
:migrations-failed
|
||||
|
@ -168,12 +173,12 @@
|
|||
:on-accept #(re-frame/dispatch
|
||||
[:init.ui/account-data-reset-accepted address])}})
|
||||
|
||||
:database-does-not-exist
|
||||
{:accounts.login/verify [address password realm-error]}
|
||||
|
||||
:decryption-failed
|
||||
;; check if decryption failed because of wrong password
|
||||
{:accounts.login/verify [address password realm-error]}
|
||||
(:database-does-not-exist :decryption-failed)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc :node/on-ready :verify-account)
|
||||
(assoc :realm-error realm-error))}
|
||||
(node/initialize nil))
|
||||
|
||||
{:ui/show-confirmation
|
||||
{:title (i18n/label :unknown-realm-error)
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
:keys [accounts/accounts accounts/create networks/networks network
|
||||
network-status peers-count peers-summary view-id navigation-stack
|
||||
status-module-initialized? device-UUID semaphores accounts/login]
|
||||
:node/keys [status]
|
||||
:node/keys [status on-ready]
|
||||
:or {network (get app-db :network)}} db
|
||||
current-account (get accounts address)
|
||||
account-network-id (get current-account :network network)
|
||||
|
@ -160,6 +160,7 @@
|
|||
:navigation-stack navigation-stack
|
||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||
:node/status status
|
||||
:node/on-ready on-ready
|
||||
:accounts/create create
|
||||
:networks/networks networks
|
||||
:account/account current-account
|
||||
|
|
|
@ -125,6 +125,16 @@
|
|||
:always
|
||||
(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
|
||||
[{:keys [db]} error sync-state]
|
||||
{:db (assoc db :node/chain-sync-state
|
||||
|
@ -142,7 +152,9 @@
|
|||
(let [network (if address
|
||||
(get-account-network db address)
|
||||
(: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)]
|
||||
(log/info "Node config: " node-config-json)
|
||||
{:db (assoc db
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
(fx/defn status-node-started
|
||||
[{db :db :as cofx}]
|
||||
(let [{:node/keys [restart? address on-ready]
|
||||
:accounts/keys [create]} db
|
||||
can-login? (and (not restart?)
|
||||
(:password (accounts.db/credentials cofx)))]
|
||||
:accounts/keys [create]} db]
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(assoc :node/status :started)
|
||||
|
@ -25,12 +23,18 @@
|
|||
|
||||
(when restart?
|
||||
(node/initialize address))
|
||||
(when can-login?
|
||||
(accounts.login/login))
|
||||
(when (= :create-account on-ready)
|
||||
(case on-ready
|
||||
:login
|
||||
(accounts.login/login)
|
||||
:verify-account
|
||||
(let [{:keys [address password]} (accounts.db/credentials cofx)]
|
||||
(fn [_]
|
||||
{:accounts.create/create-account (:password create)}))
|
||||
(when (= :recover-account on-ready)
|
||||
{:accounts.login/verify
|
||||
[address password (:realm-error db)]}))
|
||||
:create-account
|
||||
(fn [_]
|
||||
{:accounts.create/create-account (:password create)})
|
||||
:recover-account
|
||||
(fn [{:keys [db]}]
|
||||
(let [{:keys [password passphrase]} (:accounts/recover db)]
|
||||
{:accounts.recover/recover-account
|
||||
|
|
|
@ -55,9 +55,10 @@
|
|||
name]]])
|
||||
|
||||
(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?]
|
||||
password-text-input (atom nil)]
|
||||
password-text-input (atom nil)
|
||||
sign-in-enabled? [:sign-in-enabled?]]
|
||||
[react/keyboard-avoiding-view {:style ast/accounts-view}
|
||||
[status-bar/status-bar]
|
||||
[login-toolbar can-navigate-back?]
|
||||
|
@ -72,7 +73,8 @@
|
|||
:placeholder (i18n/label :t/password)
|
||||
:ref #(reset! password-text-input %)
|
||||
: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
|
||||
(re-frame/dispatch [:set-in [:accounts/login :password]
|
||||
(security/mask-data %)])
|
||||
|
@ -102,5 +104,5 @@
|
|||
[components.common/bottom-button
|
||||
{:forward? true
|
||||
: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)}]])]))
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.accounts.db :as db]
|
||||
[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
|
||||
:accounts/accounts
|
||||
|
@ -40,3 +41,12 @@
|
|||
:get-recover-account
|
||||
(fn [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)))))
|
||||
|
|
Loading…
Reference in New Issue