Skip to content

Commit

Permalink
deprecate: on-disk encryption
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tiensonqin committed Nov 7, 2022
1 parent daa2590 commit 2dfac3d
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 417 deletions.
2 changes: 0 additions & 2 deletions deps/db/src/logseq/db/schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
:ast/version {}
:db/type {}
:db/ident {:db/unique :db.unique/identity}
:db/encrypted? {}
:db/encryption-keys {}

:recent/pages {}

Expand Down
131 changes: 0 additions & 131 deletions src/main/frontend/components/encryption.cljs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))))
10 changes: 0 additions & 10 deletions src/main/frontend/components/repo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
[promesa.core :as p]
[electron.ipc :as ipc]
[goog.object :as gobj]
[frontend.components.encryption :as encryption]
[frontend.encrypt :as encrypt]
[cljs.core.async :as async :refer [go <!]]
[frontend.handler.file-sync :as file-sync]
[reitit.frontend.easy :as rfe]))
Expand Down Expand Up @@ -60,14 +58,6 @@
(state/pub-event! [:graph/switch url])))

[:div.controls
(when (encrypt/encrypted-db? url)
[:a.control {:title "Show encryption information about this graph"
:on-click (fn []
(if remote?
(state/pub-event! [:modal/remote-encryption-input-pw-dialog url repo])
(state/set-modal! (encryption/encryption-dialog url))))}
"🔐"])

(let [loading? (state/sub [:ui/loading? :remove/remote-graph GraphUUID])]
[:div.flex.flex-row.items-center
(when loading? [:div.ml-2 (ui/loading "")])
Expand Down
21 changes: 0 additions & 21 deletions src/main/frontend/components/settings.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -410,24 +410,6 @@
;; (let [value (not enable-block-timestamps?)]
;; (config-handler/set-config! :feature/enable-block-timestamps? value)))))

(defn encryption-row [enable-encryption?]
(toggle "enable_encryption"
(t :settings-page/enable-encryption)
enable-encryption?
#(let [value (not enable-encryption?)]
(config-handler/set-config! :feature/enable-encryption? value)
(when value
(state/close-modal!)
;; FIXME: Don't send the `(atom false)` ! Should check multi-window! or internal status error happens
(js/setTimeout (fn [] (state/pub-event! [:graph/ask-for-re-index (atom false) nil]))
100)))
[:p.text-sm.opacity-50 "⚠️ This feature is experimental! "
[:span "You can use "]
[:a {:href "https://github.com/kanru/logseq-encrypt-ui"
:target "_blank"}
"logseq-encrypt-ui"]
[:span " to decrypt your graph."]]))

(rum/defc keyboard-shortcuts-row [t]
(row-with-button-action
{:left-label (t :settings-page/customize-shortcuts)
Expand Down Expand Up @@ -660,7 +642,6 @@
[]
(let [current-repo (state/get-current-repo)
enable-journals? (state/enable-journals? current-repo)
enable-encryption? (state/enable-encryption? current-repo)
enable-flashcards? (state/enable-flashcards? current-repo)
enable-sync? (state/enable-sync?)
enable-whiteboards? (state/enable-whiteboards? current-repo)
Expand All @@ -683,8 +664,6 @@
(when (and (util/electron?) config/enable-plugins?) (plugin-system-switcher-row))
(flashcards-switcher-row enable-flashcards?)
(zotero-settings-row)
(encryption-row enable-encryption?)

(when-not web-platform?
[:div.mt-1.sm:mt-0.sm:col-span-2
[:hr]
Expand Down
15 changes: 0 additions & 15 deletions src/main/frontend/dicts.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@
:settings-page/enable-tooltip "Tooltips"
:settings-page/enable-journals "Journals"
:settings-page/enable-all-pages-public "All pages public when publishing"
:settings-page/enable-encryption "Encryption"
:settings-page/customize-shortcuts "Keyboard shortcuts"
:settings-page/shortcut-settings "Customize shortcuts"
:settings-page/home-default-page "Set the default home page"
Expand Down Expand Up @@ -672,7 +671,6 @@
:settings-page/customize-shortcuts "Tastaturbefehle"
:settings-page/disable-sentry "Nutzungs- und Diagnostik-Daten an Logseq senden"
:settings-page/edit-custom-css "custom.css bearbeiten"
:settings-page/enable-encryption "Verschlüsselung"
:settings-page/enable-shortcut-tooltip "Tooltips für Verknüpfungen aktivieren"
:settings-page/enable-tooltip "Tooltips"
:settings-page/shortcut-settings "Verknüpfungen anpassen"
Expand Down Expand Up @@ -998,7 +996,6 @@
:settings-page/enable-all-pages-public "Alle pagina's openbaar bij publiceren"
:settings-page/enable-block-time "Tijdstempel voor blokken inschakelen"
:settings-page/enable-developer-mode "Ontwikkelaar modus"
:settings-page/enable-encryption "Encryptie"
:settings-page/enable-flashcards "Flashcards"
:settings-page/enable-journals "Journaals"
:settings-page/enable-shortcut-tooltip "Snelkoppeling tooltip inschakelen"
Expand Down Expand Up @@ -1402,7 +1399,6 @@
:settings-page/edit-setting "Modifier"
:settings-page/enable-all-pages-public "Toutes les pages publiques lors de la publication"
:settings-page/enable-block-time "Horodatage de bloc"
:settings-page/enable-encryption "Chiffrement"
:settings-page/enable-flashcards "Cartes-mémoire"
:settings-page/enable-journals "Journals"
:settings-page/enable-shortcut-tooltip "Activer les astuces sur les raccourcis"
Expand Down Expand Up @@ -1649,7 +1645,6 @@
:settings-page/enable-tooltip "开启提示框"
:settings-page/enable-journals "开启日记"
:settings-page/enable-all-pages-public "发布所有页面"
:settings-page/enable-encryption "激活加密功能"
:settings-page/enable-whiteboards "激活白板功能"
:settings-page/customize-shortcuts "自定义快捷键"
:settings-page/shortcut-settings "快捷键设置"
Expand Down Expand Up @@ -2313,7 +2308,6 @@
:settings-page/enable-tooltip "Habilitar descripción emergente"
:settings-page/enable-journals "Habilitar diarios"
:settings-page/enable-all-pages-public "Hacer todas las páginas públicas al publicar"
:settings-page/enable-encryption "Habilitar función de cifrado"
:settings-page/customize-shortcuts "Atajos de teclado"
:settings-page/shortcut-settings "Personalizar atajos"
:settings-page/home-default-page "Establecer página de inicio"
Expand Down Expand Up @@ -2627,7 +2621,6 @@
:settings-page/preferred-workflow "Foretrukket arbeidslflyt"
:settings-page/enable-shortcut-tooltip "Skru på tooltip for snarveier"
:settings-page/enable-timetracking "Aktiver tidssporing"
:settings-page/enable-encryption "Aktiver kryptering"
:settings-page/enable-tooltip "Aktiver verktøytips"
:settings-page/enable-journals "Aktiver dagbøker"
:settings-page/enable-all-pages-public "Aktiver alle sider som offentlige ved publisering"
Expand Down Expand Up @@ -2951,7 +2944,6 @@
:settings-page/enable-tooltip "Ativar dicas de ferramentas"
:settings-page/enable-journals "Ativar diários"
:settings-page/enable-all-pages-public "Ativar todas as páginas públicas ao publicar"
:settings-page/enable-encryption "Ativar funcionalidade de criptografia"
:settings-page/customize-shortcuts "Atalhos de teclado"
:settings-page/shortcut-settings "Personalizar atalhos"
:settings-page/home-default-page "Definir a página inicial padrão"
Expand Down Expand Up @@ -3299,7 +3291,6 @@
:settings-page/enable-tooltip "Dicas de atalhos"
:settings-page/enable-journals "Diários"
:settings-page/enable-all-pages-public "Todas as páginas públicas ao publicar"
:settings-page/enable-encryption "Encriptação"
:settings-page/customize-shortcuts "Atalhos de teclado"
:settings-page/shortcut-settings "Personalizar atalhos"
:settings-page/home-default-page "Definir a página inicial predefinida"
Expand Down Expand Up @@ -3652,7 +3643,6 @@
:settings-page/enable-shortcut-tooltip "Всплывающие подсказки горячих клавиш"
:settings-page/enable-journals "Включить Дневники"
:settings-page/enable-all-pages-public "Все страницы общедоступны при публикации"
:settings-page/enable-encryption "Функции шифрования"
:settings-page/enable-flashcards "Карточки"
:settings-page/custom-configuration "Настройки пользователя"
:settings-page/custom-theme "Тема пользователя"
Expand Down Expand Up @@ -3981,7 +3971,6 @@
:settings-page/enable-tooltip "ツールチップ"
:settings-page/enable-journals "日誌"
:settings-page/enable-all-pages-public "パブリッシュ時には全てのページを公開する"
:settings-page/enable-encryption "暗号化"
:settings-page/customize-shortcuts "キーボードショートカット"
:settings-page/shortcut-settings "ショートカットをカスタマイズ"
:settings-page/home-default-page "デフォルトのホームページを設定"
Expand Down Expand Up @@ -4466,7 +4455,6 @@

:file-sync/other-user-graph "Il grafo locale attuale è associato al grafo remoto di un altro utente. Non è quindi possibile avviare la sincronizzazione."
:file-sync/graph-deleted "Il grafo attuale è stato eliminato"
:settings-page/enable-encryption "Crittografia"
:settings-page/edit-export-css "Modificare export.css"
:settings-page/enable-flashcards "Flashcard"
:settings-page/export-theme "Esporta tema"}
Expand Down Expand Up @@ -4640,7 +4628,6 @@
:settings-page/enable-tooltip "Araç ipuçları"
:settings-page/enable-journals "Günlük"
:settings-page/enable-all-pages-public "Yayımlanan tüm sayfaları herkese açık yap"
:settings-page/enable-encryption "Şifreleme"
:settings-page/customize-shortcuts "Klavye kısayolları"
:settings-page/shortcut-settings "Kısayolları özelleştir"
:settings-page/home-default-page "Varsayılan ana sayfayı ayarla"
Expand Down Expand Up @@ -4972,7 +4959,6 @@
:settings-page/enable-tooltip "툴팁 활성화"
:settings-page/enable-journals "일지 활성화"
:settings-page/enable-all-pages-public "출판할 때 모든 페이지 공개로 설정"
:settings-page/enable-encryption "암호화"
:settings-page/customize-shortcuts "키보드 단축키"
:settings-page/shortcut-settings "단축키 설정"
:settings-page/home-default-page "기본 홈 페이지 설정"
Expand Down Expand Up @@ -5300,7 +5286,6 @@
:settings-page/enable-tooltip "Podpowiedzi"
:settings-page/enable-journals "Dzienniki"
:settings-page/enable-all-pages-public "Publikuj wszystkie strony"
:settings-page/enable-encryption "Szyfrowanie"
:settings-page/customize-shortcuts "Skróty klawiszowe"
:settings-page/shortcut-settings "Zmień skróty"
:settings-page/home-default-page "Ustaw domyślną stronę startową"
Expand Down
Loading

0 comments on commit 2dfac3d

Please sign in to comment.