From 70ebdcee78202070a59cc9dbb1fe96eabefd93c1 Mon Sep 17 00:00:00 2001 From: Jens Schmidt Date: Tue, 30 May 2023 23:00:56 +0200 Subject: [PATCH] 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) --- lisp/plstore.el | 24 +++++++++++++++--------- 1 file 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 @@ plstore-delete (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 @@ plstore--insert-buffer 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. -- 2.30.2