unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jens Schmidt via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 63627@debbugs.gnu.org
Subject: bug#63627: Improve plstore.el and fix various issues of it
Date: Thu, 14 Sep 2023 23:24:54 +0200	[thread overview]
Message-ID: <ee7ab862-c912-0681-36b1-737ccb7e4abe@vodafonemail.de> (raw)
In-Reply-To: <837cp0yk3q.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 685 bytes --]

On 2023-09-08  13:34, Eli Zaretskii wrote:
>> Date: Fri, 8 Sep 2023 11:16:50 +0200
>> From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
>> Cc: 63627@debbugs.gnu.org
>>
>> Independently of the tests, I'll do the Emacs 29 bugs next, also on this
>> bug.
> 
> Thanks.

After some consideration actually only one Emacs 29 bug requires fixing.
Namely that the sequence:

    (setq plstore (plstore-open plstore-test-file))
    (plstore-save plstore)
    (plstore-close plstore)

silently drops any encrypted data in PLSTORE.  Verified in my local
master with the new ERT tests, and also verified that the attached patch
fixes the issue.

Please consider for committing on emacs-29.

Thanks

[-- Attachment #2: 0001-Fix-loss-of-encrypted-data-in-plstore.el.patch --]
[-- Type: text/x-patch, Size: 2353 bytes --]

From 70ebdcee78202070a59cc9dbb1fe96eabefd93c1 Mon Sep 17 00:00:00 2001
From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
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


  parent reply	other threads:[~2023-09-14 21:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-21 15:45 bug#63627: Improve plstore.el and fix various issues of it Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22 20:11 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-31 12:54   ` Eli Zaretskii
2023-06-16 19:43     ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-30 19:28     ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-31  4:46       ` Eli Zaretskii
2023-08-31 10:21         ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-02  7:41           ` Eli Zaretskii
2023-09-03 22:22             ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07  9:12               ` Eli Zaretskii
2023-09-07 19:27                 ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08  5:40                   ` Eli Zaretskii
2023-09-08  9:16                     ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 11:34                       ` Eli Zaretskii
2023-09-08 21:24                         ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-14 21:24                         ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-09-16 10:13                           ` Eli Zaretskii
2023-09-16 10:35                             ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-16 11:07                               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee7ab862-c912-0681-36b1-737ccb7e4abe@vodafonemail.de \
    --to=bug-gnu-emacs@gnu.org \
    --cc=63627@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=jschmidt4gnu@vodafonemail.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).