Allow user to access account on invalid key
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
fafd50775b
commit
5935d29d7d
|
@ -41,14 +41,22 @@
|
|||
[file-name]
|
||||
(.deleteFile rn-dependencies/realm (clj->js {:path file-name})))
|
||||
|
||||
(defn- default-realm-dir [path]
|
||||
(string/replace path #"default\.realm$" ""))
|
||||
|
||||
(defn- is-realm-file? [n]
|
||||
(or (re-matches #".*/default\.realm$" n)
|
||||
(re-matches #".*/new-account$" n)
|
||||
(re-matches #".*/[0-9a-f]{40}$" n)))
|
||||
|
||||
(defn- delete-realms []
|
||||
(log/warn "realm: deleting all realms")
|
||||
(try
|
||||
(do
|
||||
(delete-realm (.-defaultPath rn-dependencies/realm))
|
||||
(delete-realm new-account-filename))
|
||||
(catch :default ex
|
||||
(log/warn "failed to delete realm" ex))))
|
||||
(..
|
||||
(fs/read-dir (default-realm-dir (.-defaultPath rn-dependencies/realm)))
|
||||
(then #(->> (js->clj % :keywordize-keys true)
|
||||
(map :path)
|
||||
(filter is-realm-file?)
|
||||
(run! delete-realm)))))
|
||||
|
||||
(defn- close [realm]
|
||||
(when realm
|
||||
|
|
|
@ -682,9 +682,9 @@
|
|||
|
||||
;; invalid-key
|
||||
|
||||
:invalid-key-title "Invalid key detected"
|
||||
:invalid-key-content "The key used to encrypt your data is invalid. Clicking on 'Reset database' will delete any existing realm and create a new one with a stronger key. If you would like to backup you data please click on cancel and the app will quit. Ensure the data directory of the app is clean and make sure no data is backed up by your cloud provider."
|
||||
:invalid-key-confirm "Reset database"
|
||||
:invalid-key-title "We detected a problem with the encryption key"
|
||||
:invalid-key-content "To protect yourself, you need to create new account and erase your old data by tapping “Apply”. If you have an existing account and would like to save your seed phrase then choose “Cancel”, back it up, and restart the app. We strongly recommend creating new account because the old one is stored unencrypted."
|
||||
:invalid-key-confirm "Apply"
|
||||
|
||||
;; browser
|
||||
:browser "Browser"
|
||||
|
|
|
@ -198,4 +198,4 @@
|
|||
(handlers-macro/merge-fx
|
||||
cofx
|
||||
(wallet-set-up-passed db)
|
||||
(accounts.utils/account-update {:wallet-set-up-passed? true}))))
|
||||
(accounts.utils/account-update {:wallet-set-up-passed? true}))))
|
||||
|
|
|
@ -44,8 +44,7 @@
|
|||
(catch (fn [{:keys [error key]}]
|
||||
;; no need of further error handling as already taken care
|
||||
;; when starting the app
|
||||
(when (= error :weak-key)
|
||||
(change-account address key)))))))
|
||||
(change-account address (or key "")))))))
|
||||
|
||||
;;;; Handlers
|
||||
|
||||
|
|
|
@ -223,22 +223,30 @@
|
|||
(fn [_ _]
|
||||
{:get-encryption-key [:initialize-app]}))
|
||||
|
||||
(def handle-invalid-key-parameters
|
||||
(defn- reset-keychain []
|
||||
(.. (keychain/reset)
|
||||
(then
|
||||
#(re-frame/dispatch [:initialize-keychain]))))
|
||||
|
||||
(defn handle-invalid-key-parameters [encryption-key]
|
||||
{:title (i18n/label :invalid-key-title)
|
||||
:content (i18n/label :invalid-key-content)
|
||||
:confirm-button-text (i18n/label :invalid-key-confirm)
|
||||
:on-cancel #(.exitApp react/back-handler)
|
||||
;; On cancel we initialize the app with the invalid key, to allow the user
|
||||
;; to recover the seed phrase
|
||||
:on-cancel #(do
|
||||
(log/warn "initializing app with invalid key")
|
||||
(re-frame/dispatch [:initialize-app encryption-key]))
|
||||
:on-accept (fn []
|
||||
(realm/delete-realms)
|
||||
(.. (keychain/reset)
|
||||
(then
|
||||
#(re-frame/dispatch [:initialize-keychain]))))})
|
||||
(.. (realm/delete-realms)
|
||||
(then reset-keychain)
|
||||
(catch reset-keychain)))})
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:initialize-app
|
||||
(fn [_ [_ encryption-key error]]
|
||||
(if (= error :invalid-key)
|
||||
{:show-confirmation handle-invalid-key-parameters}
|
||||
(if (= :invalid-key error)
|
||||
{:show-confirmation (handle-invalid-key-parameters encryption-key)}
|
||||
{::init-device-UUID nil
|
||||
::testfairy-alert nil
|
||||
:dispatch-n [[:initialize-db encryption-key]
|
||||
|
|
|
@ -10,3 +10,6 @@
|
|||
(-> (.readFile rn-dependencies/fs path encoding)
|
||||
(.then on-read)
|
||||
(.catch on-error)))
|
||||
|
||||
(defn read-dir [path]
|
||||
(.readDir rn-dependencies/fs path))
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
(defn handle-key-error [event {:keys [error key]}]
|
||||
(if (= :weak-key error)
|
||||
(log/warn "weak key used, database might not be encrypted properly")
|
||||
(log/error "invalid key detected"))
|
||||
(re-frame/dispatch (into [] (concat event [key error]))))
|
||||
(log/warn "invalid key detected"))
|
||||
(re-frame/dispatch (into [] (concat event [(or key "")
|
||||
(or error :invalid-key)]))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:get-encryption-key
|
||||
|
|
Loading…
Reference in New Issue