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

@@ -1,56 +1,15 @@
(ns frontend.components.encryption
(:require [clojure.string :as string]
[frontend.context.i18n :refer [t]]
[frontend.encrypt :as encrypt]
[frontend.handler.metadata :as metadata-handler]
[frontend.handler.notification :as notification]
[frontend.fs.sync :as sync]
[frontend.state :as state]
[frontend.ui :as ui]
[frontend.util :as util]
[frontend.config :as config]
[promesa.core :as p]
[cljs.core.async :as async]
[rum.core :as rum]))
(rum/defcs encryption-dialog-inner <
(rum/local false ::reveal-secret-phrase?)
[state repo-url close-fn]
(let [reveal-secret-phrase? (get state ::reveal-secret-phrase?)
public-key (encrypt/get-public-key repo-url)
private-key (encrypt/get-secret-key repo-url)]
[:div
[:div.sm:flex.sm:items-start
[:div.mt-3.text-center.sm:mt-0.sm:text-left
[:h3#modal-headline.text-lg.leading-6.font-medium
"This graph is encrypted with " [:a {:href "https://age-encryption.org/" :target "_blank" :rel "noopener"} "age-encryption.org/v1"]]]]
[:div.mt-1
[:div.max-w-2xl.rounded-md.shadow-sm.sm:max-w-xl
[:div.cursor-pointer.block.w-full.rounded-sm.p-2
{:on-click (fn []
(when (not @reveal-secret-phrase?)
(reset! reveal-secret-phrase? true)))}
[:div.font-medium "Public Key:"]
[:div.font-mono.select-all.break-all public-key]
(if @reveal-secret-phrase?
[:div
[:div.mt-1.font-medium "Private Key:"]
[:div.font-mono.select-all.break-all private-key]]
[:div.underline "click to view the private key"])]]]
[:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse
[:span.mt-3.flex.w-full.rounded-md.shadow-sm.sm:mt-0.sm:w-auto
[:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
{:type "button"
:on-click close-fn}
(t :close)]]]]))
(defn encryption-dialog
[repo-url]
(fn [close-fn]
(encryption-dialog-inner repo-url close-fn)))
(rum/defc show-password-cp
[*show-password?]
[:div.flex.flex-row.items-center
@@ -101,12 +60,6 @@
:else
(case type
:local
(p/let [keys (encrypt/generate-key-pair-and-save! repo-url)
db-encrypted-secret (encrypt/encrypt-with-passphrase value keys)]
(metadata-handler/set-db-encrypted-secret! db-encrypted-secret)
(close-fn true))
(:create-pwd-remote :input-pwd-remote)
(do
(state/set-state! [:ui/loading? :set-graph-password] true)
@@ -286,87 +239,3 @@
(close-fn'))
close-fn')]
(input-password-inner repo-url close-fn' opts)))))
(rum/defcs encryption-setup-dialog-inner
[state repo-url close-fn]
[:div
[:div.sm:flex.sm:items-start
[:div.mt-3.text-center.sm:mt-0.sm:text-left
[:h3#modal-headline.text-lg.leading-6.font-medium
"Do you want to create an encrypted graph?"]]]
[:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse
[:span.flex.w-full.rounded-md.shadow-sm.sm:ml-3.sm:w-auto
[:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
{:type "button"
:on-click (fn []
(state/set-modal!
(input-password repo-url close-fn)
{:center? true :close-btn? false}))}
(t :yes)]]
[:span.mt-3.flex.w-full.rounded-md.shadow-sm.sm:mt-0.sm:w-auto
[:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
{:type "button"
:on-click (fn [] (close-fn false))}
(t :no)]]]])
(defn encryption-setup-dialog
[repo-url close-fn]
(fn [close-modal-fn]
(let [close-fn (fn [encrypted?]
(close-fn encrypted?)
(close-modal-fn))]
(encryption-setup-dialog-inner repo-url close-fn))))
(rum/defcs encryption-input-secret-inner <
(rum/local "" ::secret)
(rum/local false ::loading)
(rum/local false ::show-password?)
[state _repo-url db-encrypted-secret close-fn]
(let [secret (::secret state)
loading (::loading state)
*show-password? (::show-password? state)
on-click-fn (fn []
(reset! loading true)
(let [value @secret]
(when-not (string/blank? value) ; TODO: length or other checks
(let [repo (state/get-current-repo)]
(p/do!
(-> (encrypt/decrypt-with-passphrase value db-encrypted-secret)
(p/then (fn [keys]
(encrypt/save-key-pair! repo keys)
(close-fn true)
(state/set-state! :encryption/graph-parsing? false)))
(p/catch #(notification/show! "The password is not matched." :warning true))
(p/finally #(reset! loading false))))))))]
[:div
[:div.sm:flex.sm:items-start
[:div.mt-3.text-center.sm:mt-0.sm:text-left
[:h3#modal-headline.text-lg.leading-6.font-medium
"Enter your password"]]]
[:input.form-input.block.w-full.sm:text-sm.sm:leading-5.my-2
{:type (if @*show-password? "text" "password")
:auto-focus true
:on-change (fn [e]
(reset! secret (util/evalue e)))
:on-key-down (fn [e]
(when (= (.-key e) "Enter")
(on-click-fn)))}]
(show-password-cp *show-password?)
[:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse
[:span.flex.w-full.rounded-md.shadow-sm.sm:ml-3.sm:w-auto
[:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
{:type "button"
:on-click on-click-fn}
(if @loading (ui/loading "Decrypting") "Decrypt")]]]]))
(defn encryption-input-secret-dialog
[repo-url db-encrypted-secret close-fn]
(fn [close-modal-fn]
(let [close-fn (fn [encrypted?]
(close-fn encrypted?)
(close-modal-fn))]
(encryption-input-secret-inner repo-url db-encrypted-secret close-fn))))