diff options
author | Jens Schmidt <jschmidt4gnu@vodafonemail.de> | 2023-05-30 23:00:56 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2023-09-16 14:05:36 +0300 |
commit | 89fa204b706ada02884a5d35c30efd03275bd747 (patch) | |
tree | 38f13eff1bf4a595fe15b2405a4e263257e4f4e5 | |
parent | d9a1175a611876b5e1625e982720360b5c3a5b6f (diff) | |
download | emacs-89fa204b706.tar.gz |
Fix loss of encrypted data in plstore.el
* lisp/plstore.el (plstore--insert-buffer): Fix loss of encrypted
data when a plstore gets opened and saved without being decrypted
between these steps. (Bug#63627)
-rw-r--r-- | lisp/plstore.el | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lisp/plstore.el b/lisp/plstore.el index 7dc991aeec7..758f9fc7292 100644 --- a/lisp/plstore.el +++ b/lisp/plstore.el @@ -570,18 +570,23 @@ SECRET-KEYS is a plist containing secret data." (defvar pp-escape-newlines) (defun plstore--insert-buffer (plstore) - "Insert the file representation of PLSTORE at point. -Assumes that PLSTORE has been decrypted." + "Insert the file representation of PLSTORE at point." (insert ";;; public entries -*- mode: plstore -*- \n" (pp-to-string (plstore--get-alist plstore))) - (if (plstore--get-secret-alist plstore) + (let ((pp-escape-newlines nil) + (cipher nil)) + (cond + ;; Reuse the encrypted data as cipher text if this store has not + ;; been decrypted yet. + ((plstore--get-encrypted-data plstore) + (setq cipher (plstore--get-encrypted-data plstore))) + ;; Encrypt the secret alist to generate the cipher text. + ((plstore--get-secret-alist plstore) (let ((context (epg-make-context 'OpenPGP)) - (pp-escape-newlines nil) (recipients (cond ((listp plstore-encrypt-to) plstore-encrypt-to) - ((stringp plstore-encrypt-to) (list plstore-encrypt-to)))) - cipher) + ((stringp plstore-encrypt-to) (list plstore-encrypt-to))))) (setf (epg-context-armor context) t) (epg-context-set-passphrase-callback context @@ -601,9 +606,10 @@ Assumes that PLSTORE has been decrypted." If no one is selected, symmetric encryption will be performed. " recipients) (if plstore-encrypt-to - (epg-list-keys context recipients))))) - (goto-char (point-max)) - (insert ";;; secret entries\n" (pp-to-string cipher))))) + (epg-list-keys context recipients)))))))) + (when cipher + (goto-char (point-max)) + (insert ";;; secret entries\n" (pp-to-string cipher))))) (defun plstore-save (plstore) "Save PLSTORE to its associated file. |