Replace address with keyUid in accounts db

Account's address was used as a primary key in accounts db and as a
deterministic id of an account in some API calls. Also it was used as a
part of the name of the account specific database. This revealed some
extra information about the account and wasn't necessary.
At first the hash of the address was planned to be used as a
deterministic id, but we already have a keyUid which is calculated as
sha256 hash of account's public key and has similar properties:
- it is deterministic
- doesn't reveal accounts public key or address in plain
This commit is contained in:
Roman Volosovskyi 2019-12-05 08:02:31 +02:00
parent c0762e7594
commit 91b931c3b4
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
18 changed files with 148 additions and 160 deletions

View File

@ -154,13 +154,13 @@
;; multiaccounts login module ;; multiaccounts login module
(handlers/register-handler-fx (handlers/register-handler-fx
:multiaccounts.login.ui/multiaccount-selected :multiaccounts.login.ui/multiaccount-selected
(fn [{:keys [db] :as cofx} [_ address]] (fn [{:keys [db] :as cofx} [_ key-uid]]
(let [{:keys [photo-path name public-key]} (let [{:keys [photo-path name public-key]}
(get-in db [:multiaccounts/multiaccounts address])] (get-in db [:multiaccounts/multiaccounts key-uid])]
(fx/merge (fx/merge
cofx cofx
{:db (dissoc db :intro-wizard)} {:db (dissoc db :intro-wizard)}
(multiaccounts.login/open-login address photo-path name public-key))))) (multiaccounts.login/open-login key-uid photo-path name public-key)))))
;; multiaccounts logout module ;; multiaccounts logout module

View File

@ -486,15 +486,6 @@
(proceed-with-generating-key))) (proceed-with-generating-key)))
(load-pair-screen cofx))))) (load-pair-screen cofx)))))
(fx/defn show-existing-multiaccount-alert
[{:keys [db] :as cofx}]
(fx/merge cofx
{:utils/show-confirmation {:title nil
:content (i18n/label :t/keycard-existing-multiaccount)
:cancel-button-text ""
:confirm-button-text :t/okay}}
(navigation/navigate-back)))
(fx/defn check-card-state (fx/defn check-card-state
{:events [:hardwallet/check-card-state]} {:events [:hardwallet/check-card-state]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@ -523,12 +514,11 @@
(load-pin-screen))))) (load-pin-screen)))))
(when (and (= card-state :multiaccount) (when (and (= card-state :multiaccount)
(= flow :import)) (= flow :import))
(let [{:keys [address]} (find-multiaccount-by-key-uid db key-uid)] (if (find-multiaccount-by-key-uid db key-uid)
(if address (recover/show-existing-multiaccount-alert key-uid)
(recover/show-existing-multiaccount-alert address) (if pairing
(if pairing (load-recovery-pin-screen)
(load-recovery-pin-screen) (load-pair-screen))))
(load-pair-screen)))))
(when (= card-state :blank) (when (= card-state :blank)
(if (= flow :import) (if (= flow :import)
(navigation/navigate-to-cofx :keycard-recovery-no-key nil) (navigation/navigate-to-cofx :keycard-recovery-no-key nil)
@ -631,13 +621,12 @@
(fx/defn get-keys-from-keycard (fx/defn get-keys-from-keycard
[{:keys [db]}] [{:keys [db]}]
(let [multiaccount-address (get-in db [:multiaccounts/login :address]) (let [key-uid (get-in db [:multiaccounts/login :key-uid])
pairing (get-in db [:multiaccounts/multiaccounts multiaccount-address :keycard-pairing]) pairing (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing])
pin (string/join (get-in db [:hardwallet :pin :login]))] pin (string/join (get-in db [:hardwallet :pin :login]))]
(when (and pairing (when (and pairing
(seq pin)) (seq pin))
{:db (-> db {:db (assoc-in db [:hardwallet :pin :status] :verifying)
(assoc-in [:hardwallet :pin :status] :verifying))
:hardwallet/get-keys {:pairing pairing :hardwallet/get-keys {:pairing pairing
:pin pin}}))) :pin pin}})))
@ -646,7 +635,7 @@
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [application-info (get-in db [:hardwallet :application-info]) (let [application-info (get-in db [:hardwallet :application-info])
key-uid (get-in db [:hardwallet :application-info :key-uid]) key-uid (get-in db [:hardwallet :application-info :key-uid])
multiaccount (get-in db [:multiaccounts/multiaccounts (get-in db [:multiaccounts/login :address])]) multiaccount (get-in db [:multiaccounts/multiaccounts (get-in db [:multiaccounts/login :key-uid])])
multiaccount-key-uid (get multiaccount :key-uid) multiaccount-key-uid (get multiaccount :key-uid)
multiaccount-mismatch? (or (nil? multiaccount) multiaccount-mismatch? (or (nil? multiaccount)
(not= multiaccount-key-uid key-uid)) (not= multiaccount-key-uid key-uid))
@ -947,12 +936,12 @@
(fx/defn on-remove-key-success (fx/defn on-remove-key-success
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [multiaccount-address (get-in db [:multiaccount :address]) (let [key-uid (get-in db [:multiaccount :key-uid])
instance-uid (get-in db [:hardwallet :application-info :instance-uid]) instance-uid (get-in db [:hardwallet :application-info :instance-uid])
pairings (get-in db [:hardwallet :pairings])] pairings (get-in db [:hardwallet :pairings])]
(fx/merge cofx (fx/merge cofx
{:db (-> db {:db (-> db
(update :multiaccounts/multiaccounts dissoc multiaccount-address) (update :multiaccounts/multiaccounts dissoc key-uid)
(assoc-in [:hardwallet :secrets] nil) (assoc-in [:hardwallet :secrets] nil)
(update-in [:hardwallet :pairings] dissoc (keyword instance-uid)) (update-in [:hardwallet :pairings] dissoc (keyword instance-uid))
(assoc-in [:hardwallet :whisper-public-key] nil) (assoc-in [:hardwallet :whisper-public-key] nil)
@ -984,10 +973,10 @@
(fx/defn on-delete-success (fx/defn on-delete-success
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [multiaccount-address (get-in db [:multiaccount :address])] (let [key-uid (get-in db [:multiaccount :key-uid])]
(fx/merge cofx (fx/merge cofx
{:db (-> db {:db (-> db
(update :multiaccounts/multiaccounts dissoc multiaccount-address) (update :multiaccounts/multiaccounts dissoc key-uid)
(assoc-in [:hardwallet :secrets] nil) (assoc-in [:hardwallet :secrets] nil)
(assoc-in [:hardwallet :application-info] nil) (assoc-in [:hardwallet :application-info] nil)
(assoc-in [:hardwallet :pin] {:status nil (assoc-in [:hardwallet :pin] {:status nil
@ -1817,11 +1806,12 @@
(fx/defn on-get-keys-success (fx/defn on-get-keys-success
[{:keys [db] :as cofx} data] [{:keys [db] :as cofx} data]
(let [{:keys [address encryption-public-key whisper-private-key] :as account-data} (js->clj data :keywordize-keys true) (let [{:keys [key-uid encryption-public-key whisper-private-key] :as account-data} (js->clj data :keywordize-keys true)
address (ethereum/normalized-hex address) {:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts key-uid])
{:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts address])
key-uid (get-in db [:hardwallet :application-info :key-uid]) key-uid (get-in db [:hardwallet :application-info :key-uid])
multiaccount-data (types/clj->json {:name name :address address :photo-path photo-path}) multiaccount-data (types/clj->json {:name name
:key-uid key-uid
:photo-path photo-path})
save-keys? (get-in db [:multiaccounts/login :save-password?])] save-keys? (get-in db [:multiaccounts/login :save-password?])]
(fx/merge (fx/merge
cofx cofx
@ -1834,7 +1824,7 @@
(assoc-in [:hardwallet :flow] nil) (assoc-in [:hardwallet :flow] nil)
(update :multiaccounts/login assoc (update :multiaccounts/login assoc
:password encryption-public-key :password encryption-public-key
:address address :key-uid key-uid
:photo-path photo-path :photo-path photo-path
:name name)) :name name))
@ -1843,22 +1833,22 @@
:password encryption-public-key :password encryption-public-key
:chat-key whisper-private-key}} :chat-key whisper-private-key}}
(when save-keys? (when save-keys?
(keychain/save-hardwallet-keys address encryption-public-key whisper-private-key)) (keychain/save-hardwallet-keys key-uid encryption-public-key whisper-private-key))
(clear-on-card-connected) (clear-on-card-connected)
(clear-on-card-read)))) (clear-on-card-read))))
(fx/defn on-hardwallet-keychain-keys (fx/defn on-hardwallet-keychain-keys
{:events [:multiaccounts.login.callback/get-hardwallet-keys-success]} {:events [:multiaccounts.login.callback/get-hardwallet-keys-success]}
[{:keys [db] :as cofx} address [encryption-public-key whisper-private-key :as creds]] [{:keys [db] :as cofx} key-uid [encryption-public-key whisper-private-key :as creds]]
(if (nil? creds) (if (nil? creds)
(navigation/navigate-to-cofx cofx :keycard-login-pin nil) (navigation/navigate-to-cofx cofx :keycard-login-pin nil)
(let [{:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts address]) (let [{:keys [photo-path name]} (get-in db [:multiaccounts/multiaccounts key-uid])
multiaccount-data (types/clj->json {:name name multiaccount-data (types/clj->json {:name name
:address address :key-uid key-uid
:photo-path photo-path}) :photo-path photo-path})
account-data {:address address account-data {:key-uid key-uid
:encryption-public-key encryption-public-key :encryption-public-key encryption-public-key
:whisper-private-key whisper-private-key}] :whisper-private-key whisper-private-key}]
{:db {:db
(-> db (-> db
(assoc-in [:hardwallet :pin :status] nil) (assoc-in [:hardwallet :pin :status] nil)
@ -1868,7 +1858,7 @@
(assoc-in [:hardwallet :flow] nil) (assoc-in [:hardwallet :flow] nil)
(update :multiaccounts/login assoc (update :multiaccounts/login assoc
:password encryption-public-key :password encryption-public-key
:address address :key-uid key-uid
:photo-path photo-path :photo-path photo-path
:name name :name name
:save-password? true)) :save-password? true))

View File

@ -35,18 +35,18 @@
(let [{{:multiaccounts/keys [multiaccounts] :as db} :db} cofx] (let [{{:multiaccounts/keys [multiaccounts] :as db} :db} cofx]
(if (empty? multiaccounts) (if (empty? multiaccounts)
(navigation/navigate-to-cofx cofx :intro nil) (navigation/navigate-to-cofx cofx :intro nil)
(let [{:keys [address public-key photo-path name]} (first (#(sort-by :last-sign-in > %) (vals multiaccounts)))] (let [{:keys [key-uid public-key photo-path name]} (first (#(sort-by :last-sign-in > %) (vals multiaccounts)))]
(multiaccounts.login/open-login cofx address photo-path name public-key))))) (multiaccounts.login/open-login cofx key-uid photo-path name public-key)))))
(fx/defn initialize-multiaccounts (fx/defn initialize-multiaccounts
{:events [::initialize-multiaccounts]} {:events [::initialize-multiaccounts]}
[{:keys [db] :as cofx} all-multiaccounts] [{:keys [db] :as cofx} all-multiaccounts]
(let [multiaccounts (reduce (fn [acc {:keys [address key-uid keycard-pairing] :as multiaccount}] (let [multiaccounts (reduce (fn [acc {:keys [key-uid keycard-pairing]
(-> (assoc acc address multiaccount) :as multiaccount}]
(assoc-in [address :key-uid] (when-not (string/blank? key-uid) (-> (assoc acc key-uid multiaccount)
key-uid)) (assoc-in [key-uid :keycard-pairing]
(assoc-in [address :keycard-pairing] (when-not (string/blank? keycard-pairing) (when-not (string/blank? keycard-pairing)
keycard-pairing)))) keycard-pairing))))
{} {}
all-multiaccounts)] all-multiaccounts)]
(fx/merge cofx (fx/merge cofx

View File

@ -118,16 +118,16 @@
(authenticate-fx #(cb %) options))) (authenticate-fx #(cb %) options)))
(fx/defn update-biometric [{db :db :as cofx} biometric-auth?] (fx/defn update-biometric [{db :db :as cofx} biometric-auth?]
(let [address (or (get-in db [:multiaccount :address]) (let [key-uid (or (get-in db [:multiaccount :key-uid])
(get-in db [:multiaccounts/login :address]))] (get-in db [:multiaccounts/login :key-uid]))]
(fx/merge cofx (fx/merge cofx
(keychain/save-auth-method (keychain/save-auth-method
address key-uid
(if biometric-auth? (if biometric-auth?
keychain/auth-method-biometric keychain/auth-method-biometric
keychain/auth-method-none)) keychain/auth-method-none))
#(when-not biometric-auth? #(when-not biometric-auth?
{:keychain/clear-user-password address})))) {:keychain/clear-user-password key-uid}))))
(fx/defn biometric-auth-switched (fx/defn biometric-auth-switched
{:events [:multiaccounts.ui/biometric-auth-switched]} {:events [:multiaccounts.ui/biometric-auth-switched]}

View File

@ -50,9 +50,8 @@
(some #(when (= selected-id (:id %)) %) multiaccounts))) (some #(when (= selected-id (:id %)) %) multiaccounts)))
(fx/defn create-multiaccount (fx/defn create-multiaccount
[{:keys [db] :as cofx}] [{:keys [db]}]
(let [{:keys [selected-id address key-code]} (:intro-wizard db) (let [{:keys [selected-id key-code]} (:intro-wizard db)
{:keys [address]} (get-selected-multiaccount cofx)
hashed-password (ethereum/sha3 (security/safe-unmask-data key-code)) hashed-password (ethereum/sha3 (security/safe-unmask-data key-code))
callback (fn [result] callback (fn [result]
(let [derived-data (types/json->clj result) (let [derived-data (types/json->clj result)
@ -66,7 +65,7 @@
(merge derived-whisper {:name name :photo-path photo-path}))] (merge derived-whisper {:name name :photo-path photo-path}))]
(re-frame/dispatch [::store-multiaccount-success (re-frame/dispatch [::store-multiaccount-success
key-code derived-data-extended]))))))] key-code derived-data-extended]))))))]
{::store-multiaccount [selected-id address hashed-password callback]})) {::store-multiaccount [selected-id hashed-password callback]}))
(fx/defn prepare-intro-wizard (fx/defn prepare-intro-wizard
[{:keys [db] :as cofx} first-time-setup?] [{:keys [db] :as cofx} first-time-setup?]
@ -260,12 +259,12 @@
:keycard-pairing keycard-pairing :keycard-pairing keycard-pairing
:keycard-paired-on keycard-paired-on)) :keycard-paired-on keycard-paired-on))
db (assoc db db (assoc db
:multiaccounts/login {:address address :multiaccounts/login {:key-uid keyUid
:name name :name name
:photo-path photo-path :photo-path photo-path
:password password :password password
:creating? true :creating? true
:processing true} :processing true}
:multiaccount new-multiaccount :multiaccount new-multiaccount
:networks/current-network constants/default-network :networks/current-network constants/default-network
:networks/networks constants/default-networks)] :networks/networks constants/default-networks)]
@ -365,7 +364,7 @@
(re-frame/reg-fx (re-frame/reg-fx
::store-multiaccount ::store-multiaccount
(fn [[id address hashed-password callback]] (fn [[id hashed-password callback]]
(status/multiaccount-store-derived (status/multiaccount-store-derived
id id
[constants/path-wallet-root [constants/path-wallet-root

View File

@ -14,6 +14,7 @@
(spec/def :multiaccount/accounts (spec/nilable vector?)) (spec/def :multiaccount/accounts (spec/nilable vector?))
(spec/def :multiaccount/address :global/address) (spec/def :multiaccount/address :global/address)
(spec/def :multiaccount/key-uid string?)
(spec/def :multiaccount/name :global/not-empty-string) (spec/def :multiaccount/name :global/not-empty-string)
(spec/def :multiaccount/public-key :global/public-key) (spec/def :multiaccount/public-key :global/public-key)
(spec/def :multiaccount/signed-up? (spec/nilable boolean?)) (spec/def :multiaccount/signed-up? (spec/nilable boolean?))
@ -67,6 +68,6 @@
;;used during logging ;;used during logging
(spec/def :multiaccounts/login (spec/nilable map?)) (spec/def :multiaccounts/login (spec/nilable map?))
;;before login ;;before login
(spec/def :multiaccounts/multiaccount (spec/keys :req-un [:multiaccount/name :multiaccount/address] (spec/def :multiaccounts/multiaccount (spec/keys :req-un [:multiaccount/name :multiaccount/key-uid]
:opt-un [:multiaccount/timestamp])) :opt-un [:multiaccount/timestamp]))
(spec/def :multiaccounts/multiaccounts (spec/nilable (spec/map-of :multiaccount/address :multiaccounts/multiaccount))) (spec/def :multiaccounts/multiaccounts (spec/nilable (spec/map-of :multiaccount/key-uid :multiaccounts/multiaccount)))

View File

@ -69,13 +69,15 @@
(fx/defn login (fx/defn login
{:events [:multiaccounts.login.ui/password-input-submitted]} {:events [:multiaccounts.login.ui/password-input-submitted]}
[{:keys [db] :as cofx}] [{:keys [db]}]
(let [{:keys [address password name photo-path]} (:multiaccounts/login db)] (let [{:keys [key-uid password name photo-path]} (:multiaccounts/login db)]
{:db (-> db {:db (-> db
(assoc-in [:multiaccounts/login :processing] true) (assoc-in [:multiaccounts/login :processing] true)
(dissoc :intro-wizard) (dissoc :intro-wizard)
(update :hardwallet dissoc :flow)) (update :hardwallet dissoc :flow))
::login [(types/clj->json {:name name :address address :photo-path photo-path}) ::login [(types/clj->json {:name name
:key-uid key-uid
:photo-path photo-path})
(ethereum/sha3 (security/safe-unmask-data password))]})) (ethereum/sha3 (security/safe-unmask-data password))]}))
(fx/defn finish-keycard-setup (fx/defn finish-keycard-setup
@ -185,7 +187,7 @@
keychain/auth-method-none))) keychain/auth-method-none)))
(fx/defn login-only-events (fx/defn login-only-events
[{:keys [db] :as cofx} address password save-password?] [{:keys [db] :as cofx} key-uid password save-password?]
(let [auth-method (:auth-method db) (let [auth-method (:auth-method db)
new-auth-method (get-new-auth-method auth-method save-password?)] new-auth-method (get-new-auth-method auth-method save-password?)]
(log/debug "[login] login-only-events" (log/debug "[login] login-only-events"
@ -208,14 +210,14 @@
:params [["multiaccount" "current-network" "networks"]] :params [["multiaccount" "current-network" "networks"]]
:on-success #(re-frame/dispatch [::get-config-callback %])}]} :on-success #(re-frame/dispatch [::get-config-callback %])}]}
(when save-password? (when save-password?
(keychain/save-user-password address password)) (keychain/save-user-password key-uid password))
(keychain/save-auth-method address (or new-auth-method auth-method)) (keychain/save-auth-method key-uid (or new-auth-method auth-method))
(navigation/navigate-to-cofx :home nil) (navigation/navigate-to-cofx :home nil)
(when platform/desktop? (when platform/desktop?
(chat-model/update-dock-badge-label))))) (chat-model/update-dock-badge-label)))))
(fx/defn create-only-events (fx/defn create-only-events
[{:keys [db] :as cofx} address password] [{:keys [db] :as cofx}]
(let [{:keys [multiaccount :networks/networks :networks/current-network]} db] (let [{:keys [multiaccount :networks/networks :networks/current-network]} db]
(fx/merge cofx (fx/merge cofx
{:db (assoc db {:db (assoc db
@ -254,7 +256,7 @@
(fx/defn multiaccount-login-success (fx/defn multiaccount-login-success
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(let [{:keys [address password save-password? creating?]} (:multiaccounts/login db) (let [{:keys [key-uid password save-password? creating?]} (:multiaccounts/login db)
recovering? (get-in db [:intro-wizard :recovering?]) recovering? (get-in db [:intro-wizard :recovering?])
login-only? (not (or creating? login-only? (not (or creating?
recovering? recovering?
@ -278,8 +280,8 @@
(when nodes (when nodes
(fleet/set-nodes :eth.contract nodes)) (fleet/set-nodes :eth.contract nodes))
(if login-only? (if login-only?
(login-only-events address password save-password?) (login-only-events key-uid password save-password?)
(create-only-events address password)) (create-only-events))
(when recovering? (when recovering?
(navigation/navigate-to-cofx :home nil))))) (navigation/navigate-to-cofx :home nil)))))
@ -296,26 +298,26 @@
(navigation/navigate-to-cofx :keycard-login-pin nil))))) (navigation/navigate-to-cofx :keycard-login-pin nil)))))
(fx/defn open-login (fx/defn open-login
[{:keys [db] :as cofx} address photo-path name public-key] [{:keys [db] :as cofx} key-uid photo-path name public-key]
(fx/merge cofx (fx/merge cofx
{:db (-> db {:db (-> db
(update :multiaccounts/login assoc (update :multiaccounts/login assoc
:public-key public-key :public-key public-key
:address address :key-uid key-uid
:photo-path photo-path :photo-path photo-path
:name name) :name name)
(assoc :profile/photo-added? (= (identicon/identicon public-key) photo-path)) (assoc :profile/photo-added? (= (identicon/identicon public-key) photo-path))
(update :multiaccounts/login dissoc (update :multiaccounts/login dissoc
:error :error
:password))} :password))}
(keychain/get-auth-method address))) (keychain/get-auth-method key-uid)))
(fx/defn open-login-callback (fx/defn open-login-callback
{:events [:multiaccounts.login.callback/get-user-password-success]} {:events [:multiaccounts.login.callback/get-user-password-success]}
[{:keys [db] :as cofx} password] [{:keys [db] :as cofx} password]
(let [address (get-in db [:multiaccounts/login :address]) (let [key-uid (get-in db [:multiaccounts/login :key-uid])
keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts
address key-uid
:keycard-pairing]))] :keycard-pairing]))]
(if password (if password
(fx/merge (fx/merge
@ -334,20 +336,20 @@
nil))))) nil)))))
(fx/defn get-credentials (fx/defn get-credentials
[{:keys [db] :as cofx} address] [{:keys [db] :as cofx} key-uid]
(let [keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts address :keycard-pairing]))] (let [keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))]
(log/debug "[login] get-credentials" (log/debug "[login] get-credentials"
"keycard-multiacc?" keycard-multiaccount?) "keycard-multiacc?" keycard-multiaccount?)
(if keycard-multiaccount? (if keycard-multiaccount?
(keychain/get-hardwallet-keys cofx address) (keychain/get-hardwallet-keys cofx key-uid)
(keychain/get-user-password cofx address)))) (keychain/get-user-password cofx key-uid))))
(fx/defn get-auth-method-success (fx/defn get-auth-method-success
"Auth method: nil - not supported, \"none\" - not selected, \"password\", \"biometric\", \"biometric-prepare\"" "Auth method: nil - not supported, \"none\" - not selected, \"password\", \"biometric\", \"biometric-prepare\""
{:events [:multiaccounts.login/get-auth-method-success]} {:events [:multiaccounts.login/get-auth-method-success]}
[{:keys [db] :as cofx} auth-method] [{:keys [db] :as cofx} auth-method]
(let [address (get-in db [:multiaccounts/login :address]) (let [key-uid (get-in db [:multiaccounts/login :key-uid])
keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts address :keycard-pairing]))] keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))]
(log/debug "[login] get-auth-method-success" (log/debug "[login] get-auth-method-success"
"auth-method" auth-method "auth-method" auth-method
"keycard-multiacc?" keycard-multiaccount?) "keycard-multiacc?" keycard-multiaccount?)
@ -357,7 +359,7 @@
keychain/auth-method-biometric keychain/auth-method-biometric
(biometric/biometric-auth %) (biometric/biometric-auth %)
keychain/auth-method-password keychain/auth-method-password
(get-credentials % address) (get-credentials % key-uid)
;;nil or "none" or "biometric-prepare" ;;nil or "none" or "biometric-prepare"
(if keycard-multiaccount? (if keycard-multiaccount?
@ -367,17 +369,17 @@
(fx/defn biometric-auth-done (fx/defn biometric-auth-done
{:events [:biometric-auth-done]} {:events [:biometric-auth-done]}
[{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}] [{:keys [db] :as cofx} {:keys [bioauth-success bioauth-message bioauth-code]}]
(let [address (get-in db [:multiaccounts/login :address])] (let [key-uid (get-in db [:multiaccounts/login :key-uid])]
(log/debug "[biometric] biometric-auth-done" (log/debug "[biometric] biometric-auth-done"
"bioauth-success" bioauth-success "bioauth-success" bioauth-success
"bioauth-message" bioauth-message "bioauth-message" bioauth-message
"bioauth-code" bioauth-code) "bioauth-code" bioauth-code)
(if bioauth-success (if bioauth-success
(get-credentials cofx address) (get-credentials cofx key-uid)
(fx/merge cofx (fx/merge cofx
{:db (assoc-in db [:multiaccounts/login :save-password?] false)} {:db (assoc-in db [:multiaccounts/login :save-password?] false)}
(biometric/show-message bioauth-message bioauth-code) (biometric/show-message bioauth-message bioauth-code)
(keychain/save-auth-method address keychain/auth-method-none) (keychain/save-auth-method key-uid keychain/auth-method-none)
(open-login-callback nil))))) (open-login-callback nil)))))
(fx/defn save-password (fx/defn save-password

View File

@ -9,12 +9,12 @@
[status-im.utils.keychain.core :as keychain])) [status-im.utils.keychain.core :as keychain]))
(fx/defn logout-method [{:keys [db] :as cofx} auth-method] (fx/defn logout-method [{:keys [db] :as cofx} auth-method]
(let [address (get-in db [:multiaccount :address])] (let [key-uid (get-in db [:multiaccount :key-uid])]
(fx/merge cofx (fx/merge cofx
{::logout nil {::logout nil
:keychain/clear-user-password address :keychain/clear-user-password key-uid
::init/open-multiaccounts #(re-frame/dispatch [::init/initialize-multiaccounts %])} ::init/open-multiaccounts #(re-frame/dispatch [::init/initialize-multiaccounts %])}
(keychain/save-auth-method address auth-method) (keychain/save-auth-method key-uid auth-method)
(transport/stop-whisper) (transport/stop-whisper)
(chaos-mode/stop-checking) (chaos-mode/stop-checking)
(init/initialize-app-db)))) (init/initialize-app-db))))

View File

@ -5,7 +5,7 @@
(get-in cofx [:db :multiaccount]))) (get-in cofx [:db :multiaccount])))
(defn credentials [cofx] (defn credentials [cofx]
(select-keys (get-in cofx [:db :multiaccounts/login]) [:address :password :save-password?])) (select-keys (get-in cofx [:db :multiaccounts/login]) [:key-uid :password :save-password?]))
(defn current-public-key (defn current-public-key
[cofx] [cofx]

View File

@ -19,8 +19,7 @@
(defn existing-account? (defn existing-account?
[root-key multiaccounts] [root-key multiaccounts]
(contains? multiaccounts ((fnil clojure.string/lower-case "") (contains? multiaccounts (:key-uid root-key)))
(:address root-key))))
(defn check-phrase-warnings [recovery-phrase] (defn check-phrase-warnings [recovery-phrase]
(cond (string/blank? recovery-phrase) :required-field (cond (string/blank? recovery-phrase) :required-field
@ -49,11 +48,8 @@
:interceptors [(re-frame/inject-cofx :random-guid-generator) :interceptors [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]} (re-frame/inject-cofx ::multiaccounts.create/get-signing-phrase)]}
[{:keys [db] :as cofx} password] [{:keys [db] :as cofx} password]
(let [multiaccount (get-in db [:intro-wizard :root-key]) (let [{:keys [key-uid] :as multiaccount} (get-in db [:intro-wizard :root-key])
multiaccount-address (-> (:address multiaccount) keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts key-uid :keycard-pairing]))]
(string/lower-case)
(string/replace-first "0x" ""))
keycard-multiaccount? (boolean (get-in db [:multiaccounts/multiaccounts multiaccount-address :keycard-pairing]))]
(if keycard-multiaccount? (if keycard-multiaccount?
;; trying to recover multiaccount created with keycard ;; trying to recover multiaccount created with keycard
{:db (-> db {:db (-> db
@ -70,14 +66,14 @@
(fx/defn store-multiaccount (fx/defn store-multiaccount
{:events [::recover-multiaccount-confirmed]} {:events [::recover-multiaccount-confirmed]}
[{:keys [db] :as cofx}] [{:keys [db]}]
(let [password (get-in db [:intro-wizard :key-code]) (let [password (get-in db [:intro-wizard :key-code])
{:keys [passphrase root-key]} (:intro-wizard db) {:keys [root-key]} (:intro-wizard db)
{:keys [id address]} root-key {:keys [id]} root-key
callback #(re-frame/dispatch [::store-multiaccount-success password]) callback #(re-frame/dispatch [::store-multiaccount-success password])
hashed-password (ethereum/sha3 (security/safe-unmask-data password))] hashed-password (ethereum/sha3 (security/safe-unmask-data password))]
{:db (assoc-in db [:intro-wizard :processing?] true) {:db (assoc-in db [:intro-wizard :processing?] true)
::multiaccounts.create/store-multiaccount [id address hashed-password callback]})) ::multiaccounts.create/store-multiaccount [id hashed-password callback]}))
(fx/defn recover-multiaccount-with-checks (fx/defn recover-multiaccount-with-checks
{:events [::sign-in-button-pressed]} {:events [::sign-in-button-pressed]}
@ -118,19 +114,18 @@
root-data derived-data-extended])))))))))))) root-data derived-data-extended]))))))))))))
(fx/defn show-existing-multiaccount-alert (fx/defn show-existing-multiaccount-alert
[_ address] [_ key-uid]
{:utils/show-confirmation {:utils/show-confirmation
{:title (i18n/label :t/multiaccount-exists-title) {:title (i18n/label :t/multiaccount-exists-title)
:content (i18n/label :t/multiaccount-exists-content) :content (i18n/label :t/multiaccount-exists-content)
:confirm-button-text (i18n/label :t/unlock) :confirm-button-text (i18n/label :t/unlock)
:on-accept #(re-frame/dispatch :on-accept #(re-frame/dispatch
[:multiaccounts.login.ui/multiaccount-selected [:multiaccounts.login.ui/multiaccount-selected key-uid])
(clojure.string/lower-case address)])
:on-cancel #(re-frame/dispatch [:navigate-to :multiaccounts])}}) :on-cancel #(re-frame/dispatch [:navigate-to :multiaccounts])}})
(fx/defn on-import-multiaccount-success (fx/defn on-import-multiaccount-success
{:events [::import-multiaccount-success]} {:events [::import-multiaccount-success]}
[{:keys [db] :as cofx} {:keys [address] :as root-data} derived-data] [{:keys [db] :as cofx} {:keys [key-uid] :as root-data} derived-data]
(let [multiaccounts (:multiaccounts/multiaccounts db)] (let [multiaccounts (:multiaccounts/multiaccounts db)]
(fx/merge (fx/merge
cofx cofx
@ -140,7 +135,7 @@
:step :recovery-success :step :recovery-success
:forward-action :multiaccounts.recover/re-encrypt-pressed)} :forward-action :multiaccounts.recover/re-encrypt-pressed)}
(when (existing-account? root-data multiaccounts) (when (existing-account? root-data multiaccounts)
(show-existing-multiaccount-alert address)) (show-existing-multiaccount-alert key-uid))
(navigation/navigate-to-cofx :recover-multiaccount-success nil)))) (navigation/navigate-to-cofx :recover-multiaccount-success nil))))
(fx/defn enter-phrase-pressed (fx/defn enter-phrase-pressed

View File

@ -46,7 +46,8 @@
(defn save-account-and-login (defn save-account-and-login
"NOTE: beware, the password has to be sha3 hashed" "NOTE: beware, the password has to be sha3 hashed"
[multiaccount-data hashed-password config accounts-data] [multiaccount-data hashed-password config accounts-data]
(log/debug "[native-module] save-account-and-login") (log/debug "[native-module] save-account-and-login"
"multiaccount-data" multiaccount-data)
(clear-web-data) (clear-web-data)
(.saveAccountAndLogin (status) multiaccount-data hashed-password config accounts-data)) (.saveAccountAndLogin (status) multiaccount-data hashed-password config accounts-data))
@ -125,12 +126,12 @@
(defn multiaccount-store-derived (defn multiaccount-store-derived
"NOTE: beware, the password has to be sha3 hashed" "NOTE: beware, the password has to be sha3 hashed"
[account-id paths hashed-password callback] [account-id paths hashed-password callback]
(log/debug "[native-module] multiaccount-store-derived") (log/debug "[native-module] multiaccount-store-derived"
"account-id" account-id)
(.multiAccountStoreDerived (status) (.multiAccountStoreDerived (status)
(types/clj->json {:accountID account-id (types/clj->json {:accountID account-id
:paths paths :paths paths
:password hashed-password}) :password hashed-password})
callback)) callback))
(defn multiaccount-generate-and-derive-addresses (defn multiaccount-generate-and-derive-addresses

View File

@ -42,8 +42,6 @@
(defview toolbar-content-view [] (defview toolbar-content-view []
(letsubs [{:keys [group-chat color online contacts chat-name contact (letsubs [{:keys [group-chat color online contacts chat-name contact
public? chat-id] :as chat} [:chats/current-chat] public? chat-id] :as chat} [:chats/current-chat]
show-actions? [:chats/current-chat-ui-prop :show-actions?]
multiaccounts [:multiaccounts/multiaccounts]
sync-state [:sync-state]] sync-state [:sync-state]]
(let [has-subtitle? (or group-chat (not= :done sync-state))] (let [has-subtitle? (or group-chat (not= :done sync-state))]
[react/view {:style st/toolbar-container} [react/view {:style st/toolbar-container}

View File

@ -366,7 +366,7 @@
status [:hardwallet/pin-status] status [:hardwallet/pin-status]
error-label [:hardwallet/pin-error-label] error-label [:hardwallet/pin-error-label]
multiple-multiaccounts? [:multiple-multiaccounts?] multiple-multiaccounts? [:multiple-multiaccounts?]
{:keys [address name] :as account} [:multiaccounts/login] {:keys [key-uid name] :as account} [:multiaccounts/login]
small-screen? [:dimensions/small-screen?] small-screen? [:dimensions/small-screen?]
retry-counter [:hardwallet/retry-counter]] retry-counter [:hardwallet/retry-counter]]
[react/view styles/container [react/view styles/container
@ -428,7 +428,7 @@
:font-family "monospace"} :font-family "monospace"}
:number-of-lines 1 :number-of-lines 1
:ellipsize-mode :middle} :ellipsize-mode :middle}
(utils.core/truncate-str address 14 true)]]] (utils.core/truncate-str key-uid 14 true)]]]
[pin.views/pin-view [pin.views/pin-view
{:pin pin {:pin pin
:retry-counter retry-counter :retry-counter retry-counter
@ -445,7 +445,7 @@
(defview login-connect-card [] (defview login-connect-card []
(letsubs [status [:hardwallet/pin-status] (letsubs [status [:hardwallet/pin-status]
{:keys [address name] :as account} [:multiaccounts/login]] {:keys [key-uid name] :as account} [:multiaccounts/login]]
(let [in-progress? (= status :verifying)] (let [in-progress? (= status :verifying)]
[react/view styles/container [react/view styles/container
[toolbar/toolbar [toolbar/toolbar
@ -506,7 +506,7 @@
:font-family "monospace"} :font-family "monospace"}
:number-of-lines 1 :number-of-lines 1
:ellipsize-mode :middle} :ellipsize-mode :middle}
(utils.core/truncate-str address 14 true)]]] (utils.core/truncate-str key-uid 14 true)]]]
[react/view {:margin-bottom 12 [react/view {:margin-bottom 12
:flex 1 :flex 1
:align-items :center :align-items :center

View File

@ -16,8 +16,10 @@
[status-im.react-native.resources :as resources])) [status-im.react-native.resources :as resources]))
(defn multiaccount-view (defn multiaccount-view
[{:keys [address photo-path name public-key keycard-pairing]}] [{:keys [key-uid photo-path name keycard-pairing]}]
[react/touchable-highlight {:on-press #(re-frame/dispatch [:multiaccounts.login.ui/multiaccount-selected address])} [react/touchable-highlight
{:on-press #(re-frame/dispatch
[:multiaccounts.login.ui/multiaccount-selected key-uid])}
[react/view styles/multiaccount-view [react/view styles/multiaccount-view
[photos/photo photo-path {:size styles/multiaccount-image-size}] [photos/photo photo-path {:size styles/multiaccount-image-size}]
[react/view styles/multiaccount-badge-text-view [react/view styles/multiaccount-badge-text-view

View File

@ -116,11 +116,11 @@
(re-frame/reg-fx (re-frame/reg-fx
:keychain/get-auth-method :keychain/get-auth-method
(fn [[address callback]] (fn [[key-uid callback]]
(can-save-user-password? (can-save-user-password?
(fn [can-save?] (fn [can-save?]
(if can-save? (if can-save?
(get-credentials (str address "-auth") (get-credentials (str key-uid "-auth")
#(callback (if % #(callback (if %
(.-password %) (.-password %)
auth-method-none))) auth-method-none)))
@ -128,18 +128,18 @@
(re-frame/reg-fx (re-frame/reg-fx
:keychain/get-user-password :keychain/get-user-password
(fn [[address callback]] (fn [[key-uid callback]]
(get-credentials address #(if % (callback (security/mask-data (.-password %))) (callback nil))))) (get-credentials key-uid #(if % (callback (security/mask-data (.-password %))) (callback nil)))))
(re-frame/reg-fx (re-frame/reg-fx
:keychain/get-hardwallet-keys :keychain/get-hardwallet-keys
(fn [[address callback]] (fn [[key-uid callback]]
(get-credentials (get-credentials
address key-uid
(fn [encryption-key-data] (fn [encryption-key-data]
(if encryption-key-data (if encryption-key-data
(get-credentials (get-credentials
(whisper-key-name address) (whisper-key-name key-uid)
(fn [whisper-key-data] (fn [whisper-key-data]
(if whisper-key-data (if whisper-key-data
(callback [(.-password encryption-key-data) (callback [(.-password encryption-key-data)
@ -149,10 +149,10 @@
(re-frame/reg-fx (re-frame/reg-fx
:keychain/save-user-password :keychain/save-user-password
(fn [[address password]] (fn [[key-uid password]]
(save-credentials (save-credentials
address key-uid
address key-uid
(security/safe-unmask-data password) (security/safe-unmask-data password)
#(when-not % #(when-not %
(log/error (log/error
@ -163,12 +163,12 @@
(re-frame/reg-fx (re-frame/reg-fx
:keychain/save-auth-method :keychain/save-auth-method
(fn [[address method]] (fn [[key-uid method]]
(log/debug "[keychain] :keychain/save-auth-method" (log/debug "[keychain] :keychain/save-auth-method"
"method" method) "method" method)
(save-credentials (save-credentials
(str address "-auth") (str key-uid "-auth")
address key-uid
method method
#(when-not % #(when-not %
(log/error (log/error
@ -179,17 +179,17 @@
(re-frame/reg-fx (re-frame/reg-fx
:keychain/save-hardwallet-keys :keychain/save-hardwallet-keys
(fn [[address encryption-public-key whisper-private-key]] (fn [[key-uid encryption-public-key whisper-private-key]]
(save-credentials (save-credentials
address key-uid
address key-uid
encryption-public-key encryption-public-key
#(when-not % #(when-not %
(log/error (log/error
(str "Error while saving encryption-public-key")))) (str "Error while saving encryption-public-key"))))
(save-credentials (save-credentials
(whisper-key-name address) (whisper-key-name key-uid)
address key-uid
whisper-private-key whisper-private-key
#(when-not % #(when-not %
(log/error (log/error
@ -197,40 +197,40 @@
(re-frame/reg-fx (re-frame/reg-fx
:keychain/clear-user-password :keychain/clear-user-password
(fn [address] (fn [key-uid]
(when platform/mobile? (when platform/mobile?
(-> (.resetInternetCredentials rn/keychain (string/lower-case address)) (-> (.resetInternetCredentials rn/keychain (string/lower-case key-uid))
(.then #(when-not % (log/error (str "Error while clearing saved password.")))))))) (.then #(when-not % (log/error (str "Error while clearing saved password."))))))))
(fx/defn get-auth-method (fx/defn get-auth-method
[_ address] [_ key-uid]
{:keychain/get-auth-method {:keychain/get-auth-method
[address #(re-frame/dispatch [:multiaccounts.login/get-auth-method-success % address])]}) [key-uid #(re-frame/dispatch [:multiaccounts.login/get-auth-method-success % key-uid])]})
(fx/defn get-user-password (fx/defn get-user-password
[_ address] [_ key-uid]
{:keychain/get-user-password {:keychain/get-user-password
[address [key-uid
#(re-frame/dispatch #(re-frame/dispatch
[:multiaccounts.login.callback/get-user-password-success % address])]}) [:multiaccounts.login.callback/get-user-password-success % key-uid])]})
(fx/defn get-hardwallet-keys (fx/defn get-hardwallet-keys
[_ address] [_ key-uid]
{:keychain/get-hardwallet-keys {:keychain/get-hardwallet-keys
[address [key-uid
#(re-frame/dispatch #(re-frame/dispatch
[:multiaccounts.login.callback/get-hardwallet-keys-success address %])]}) [:multiaccounts.login.callback/get-hardwallet-keys-success key-uid %])]})
(fx/defn save-user-password (fx/defn save-user-password
[_ address password] [_ key-uid password]
{:keychain/save-user-password [address password]}) {:keychain/save-user-password [key-uid password]})
(fx/defn save-hardwallet-keys (fx/defn save-hardwallet-keys
[_ address encryption-public-key whisper-private-key] [_ key-uid encryption-public-key whisper-private-key]
{:keychain/save-hardwallet-keys [address {:keychain/save-hardwallet-keys [key-uid
encryption-public-key encryption-public-key
whisper-private-key]}) whisper-private-key]})
(fx/defn save-auth-method (fx/defn save-auth-method
[{:keys [db]} address method] [{:keys [db]} key-uid method]
{:db (assoc db :auth-method method) {:db (assoc db :auth-method method)
:keychain/save-auth-method [address method]}) :keychain/save-auth-method [key-uid method]})

View File

@ -153,4 +153,4 @@
:path "" :path ""
:type :watch :type :watch
:color (rand-nth colors/account-colors)})} :color (rand-nth colors/account-colors)})}
(navigation/navigate-to-cofx :account-added nil)))) (navigation/navigate-to-cofx :account-added nil))))

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead", "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.36.1", "version": "v0.36.2",
"commit-sha1": "fd49b0140ebafdcec35b4da84685bcd8559a7dd9", "commit-sha1": "4c0d8dedea10b02bbad476170cc0eef61a92ecbf",
"src-sha256": "1pqnvmldg93vbmmsvpr24pj87d2vx3cfm7rr9rgwdk469pd1hhhy" "src-sha256": "0a13rk9p13s3p1dz3n7wbb3s343dlqsidmphxz57xw6di2s40nzx"
} }

View File

@ -11,14 +11,14 @@
(deftest on-password-input-submitted (deftest on-password-input-submitted
(testing (testing
"handling :multiaccounts.login.ui/password-input-submitted event" "handling :multiaccounts.login.ui/password-input-submitted event"
(let [cofx {:db {:multiaccounts/login {:address "address" (let [cofx {:db {:multiaccounts/login {:key-uid "key-uid"
:password "password" :password "password"
:name "user" :name "user"
:photo-path "photo"}}} :photo-path "photo"}}}
efx (login.core/login cofx)] efx (login.core/login cofx)]
(testing "Change multiaccount." (testing "Change multiaccount."
(is (= (::login.core/login efx) (is (= (::login.core/login efx)
["{\"name\":\"user\",\"address\":\"address\",\"photo-path\":\"photo\"}" (ethereum/sha3 "password")]))) ["{\"name\":\"user\",\"key-uid\":\"key-uid\",\"photo-path\":\"photo\"}" (ethereum/sha3 "password")])))
(testing "start activity indicator" (testing "start activity indicator"
(is (= (get-in efx [:db :multiaccounts/login :processing]) true)))))) (is (= (get-in efx [:db :multiaccounts/login :processing]) true))))))