deprecate: on-disk encryption

Why?
1. there're still a lot issues on it and there's no resource to
maintain and develop it considering we need to support it on all the
platforms.
2. it creates more bugs with Logseq Sync.
This commit is contained in:
Tienson Qin
2022-11-04 22:28:23 +08:00
parent daa2590cc9
commit 2dfac3d774
18 changed files with 61 additions and 417 deletions

View File

@@ -6,7 +6,6 @@
[goog.string :as gstring]
[frontend.config :as config]
[frontend.db :as db]
[frontend.encrypt :as encrypt]
[frontend.fs.protocol :as protocol]
[frontend.mobile.util :as mobile-util]
[frontend.state :as state]
@@ -105,10 +104,7 @@
(defn- contents-matched?
[disk-content db-content]
(when (and (string? disk-content) (string? db-content))
(if (encrypt/encrypted-db? (state/get-current-repo))
(p/let [decrypted-content (encrypt/decrypt disk-content)]
(= (string/trim decrypted-content) (string/trim db-content)))
(p/resolved (= (string/trim disk-content) (string/trim db-content))))))
(p/resolved (= (string/trim disk-content) (string/trim db-content)))))
(def backup-dir "logseq/bak")
(def version-file-dir "logseq/version-files/local")
@@ -195,7 +191,7 @@
(not contents-matched?)
(not (contains? #{"excalidraw" "edn" "css"} ext))
(not (string/includes? path "/.recycle/")))
(p/let [disk-content (encrypt/decrypt disk-content)]
(p/let [disk-content disk-content]
(state/pub-event! [:file/not-matched-from-disk path disk-content content]))
:else
@@ -206,9 +202,7 @@
(when-not contents-matched?
(backup-file repo-dir :backup-dir path disk-content))
(db/set-file-last-modified-at! repo path mtime)
(p/let [content (if (encrypt/encrypted-db? (state/get-current-repo))
(encrypt/decrypt content)
content)]
(p/let [content content]
(db/set-file-content! repo path content))
(when ok-handler
(ok-handler repo path result))

View File

@@ -10,8 +10,7 @@
[frontend.config :as config]
[frontend.state :as state]
[frontend.handler.notification :as notification]
["/frontend/utils" :as utils]
[frontend.encrypt :as encrypt]))
["/frontend/utils" :as utils]))
;; We need to cache the file handles in the memory so that
;; the browser will not keep asking permissions.
@@ -58,10 +57,7 @@
(defn- contents-matched?
[disk-content db-content]
(when (and (string? disk-content) (string? db-content))
(if (encrypt/encrypted-db? (state/get-current-repo))
(p/let [decrypted-content (encrypt/decrypt disk-content)]
(= (string/trim decrypted-content) (string/trim db-content)))
(p/resolved (= (string/trim disk-content) (string/trim db-content))))))
(p/resolved (= (string/trim disk-content) (string/trim db-content)))))
(defrecord ^:large-vars/cleanup-todo Nfs []
protocol/Fs
@@ -173,16 +169,12 @@
(not contents-matched?)
(not (contains? #{"excalidraw" "edn" "css"} ext))
(not (string/includes? path "/.recycle/")))
(p/let [local-content (encrypt/decrypt local-content)]
(state/pub-event! [:file/not-matched-from-disk path local-content content]))
(state/pub-event! [:file/not-matched-from-disk path local-content content])
(p/let [_ (verify-permission repo file-handle true)
_ (utils/writeFile file-handle content)
file (.getFile file-handle)]
(when file
(p/let [content (if (encrypt/encrypted-db? (state/get-current-repo))
(encrypt/decrypt content)
content)]
(db/set-file-content! repo path content))
(db/set-file-content! repo path content)
(nfs-saved-handler repo path file))))))
(p/catch (fn [e]
(js/console.error e))))

View File

@@ -9,8 +9,7 @@
[frontend.util :as util]
[goog.object :as gobj]
[lambdaisland.glogi :as log]
[promesa.core :as p]
[frontend.encrypt :as encrypt]))
[promesa.core :as p]))
(defn concat-path
[dir path]
@@ -29,10 +28,7 @@
(defn- contents-matched?
[disk-content db-content]
(when (and (string? disk-content) (string? db-content))
(if (encrypt/encrypted-db? (state/get-current-repo))
(p/let [decrypted-content (encrypt/decrypt disk-content)]
(= (string/trim decrypted-content) (string/trim db-content)))
(p/resolved (= (string/trim disk-content) (string/trim db-content))))))
(p/resolved (= (string/trim disk-content) (string/trim db-content)))))
(defn- write-file-impl!
[this repo dir path content {:keys [ok-handler error-handler old-content skip-compare?]} stat]
@@ -61,8 +57,7 @@
(not contents-matched?)
(not (contains? #{"excalidraw" "edn" "css"} ext))
(not (string/includes? path "/.recycle/")))
(p/let [disk-content (encrypt/decrypt disk-content)]
(state/pub-event! [:file/not-matched-from-disk path disk-content content]))
(state/pub-event! [:file/not-matched-from-disk path disk-content content])
:else
(->
@@ -71,10 +66,7 @@
(when-not contents-matched?
(ipc/ipc "backupDbFile" (config/get-local-dir repo) path disk-content content))
(db/set-file-last-modified-at! repo path mtime)
(p/let [content (if (encrypt/encrypted-db? (state/get-current-repo))
(encrypt/decrypt content)
content)]
(db/set-file-content! repo path content))
(db/set-file-content! repo path content)
(when ok-handler
(ok-handler repo path result))
result)

View File

@@ -15,7 +15,6 @@
[lambdaisland.glogi :as log]
[promesa.core :as p]
[frontend.state :as state]
[frontend.encrypt :as encrypt]
[frontend.fs :as fs]))
;; all IPC paths must be normalized! (via gp-util/path-normalize)
@@ -56,9 +55,7 @@
pages-metadata-path (config/get-pages-metadata-path)
{:keys [mtime]} stat
db-content (or (db/get-file repo path) "")]
(when (and (or content (contains? #{"unlink" "unlinkDir" "addDir"} type))
(not (encrypt/content-encrypted? content))
(not (:encryption/graph-parsing? @state/state)))
(when (or content (contains? #{"unlink" "unlinkDir" "addDir"} type))
(cond
(and (= "unlinkDir" type) dir)
(state/pub-event! [:graph/dir-gone dir])