unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: stepnem@gmail.com, 40118@debbugs.gnu.org
Subject: bug#40118: 27.0.90; Signing emails with gpg
Date: Wed, 30 Sep 2020 18:44:52 +0200	[thread overview]
Message-ID: <m2y2kr2ozf.fsf@gmail.com> (raw)
In-Reply-To: <87v9fv48im.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 30 Sep 2020 16:57:37 +0200")

>>>>> On Wed, 30 Sep 2020 16:57:37 +0200, Lars Ingebrigtsen <larsi@gnus.org> said:

    Lars> Robert Pluim <rpluim@gmail.com> writes:
    >> * lisp/gnus/mml-sec.el (mml-secure-epg-sign): Partially revert
    >> "Make mml-secure-epg-sign bug out if we can't find an identity".
    >> It causes signing to fail for people who have not set up
    >> mml-secure-{smime,openpgp}-sign-with-sender, which is a regression
    >> from Emacs-26 (Bug#40118).

    Lars> OK, this was applied to Emacs 27, but the general problem is still
    Lars> present on the trunk, I think?

I donʼt think it was applied to emacs-27.

    Lars> Robert, did you have any thoughts about how to fix this in general, or
    Lars> is the error-ing out in mml-secure-epg-sign just misguided? 

This is what I came up with at the time. master-only, I think.

diff --git a/lisp/gnus/mml-sec.el b/lisp/gnus/mml-sec.el
index 740e1d2b72..8abe83b937 100644
--- a/lisp/gnus/mml-sec.el
+++ b/lisp/gnus/mml-sec.el
@@ -937,6 +937,47 @@ mml-secure-epg-encrypt
        (signal (car error) (cdr error))))
     cipher))
 
+(defun mml-secure-sender-sign-query (protocol sender)
+  "Query whether to use SENDER to sign when using PROTOCOL.
+PROTOCOL will be `OpenPGP' or `CMS' (smime).
+This can also save the resulting value of
+`mml-secure-smime-sign-with-sender' or
+`mml-secure-openpgp-sign-with-sender' via Customize.
+Returns non-nil if the user has chosen to use SENDER."
+  (let ((buffer (get-buffer-create "*MML sender signing options*"))
+        (options '((?a "always" "Sign using this sender now and sign with message sender in future.")
+                   (?s "session only" "Sign using this sender now, and sign with message sender for this session only.")
+                   (?n "no" "Do not sign this message (and error out)")))
+        answer done val)
+    (save-window-excursion
+      (pop-to-buffer buffer)
+      (erase-buffer)
+      (insert (format "No %s signing key was found for this message.\nThe sender of this message is \"%s\".\nWould you like to attempt looking up a signing key based on it?"
+                      (if (eq protocol 'OpenPGP)
+                          "openpgp" "smime")
+                      sender))
+      (while (not done)
+        (setq answer (read-multiple-choice "Sign this message using the sender?" options))
+        (cl-case (car answer)
+          (?a
+           (if (eq protocol 'OpenPGP)
+               (progn
+                 (setq mml-secure-openpgp-sign-with-sender t)
+                 (customize-save-variable 'mml-secure-openpgp-sign-with-sender t))
+             (setq mml-secure-smime-sign-with-sender t)
+             (customize-save-variable 'mml-secure-smime-sign-with-sender t))
+           (setq done t
+                 val t))
+          (?s
+           (if (eq protocol 'OpenPGP)
+               (setq mml-secure-openpgp-sign-with-sender t)
+             (setq mml-secure-smime-sign-with-sender t))
+           (setq done t
+                 val t))
+          (?n
+           (setq done t)))))
+    val))
+
 (defun mml-secure-epg-sign (protocol mode)
   ;; Based on code appearing inside mml2015-epg-sign.
   (let* ((context (epg-make-context protocol))
@@ -945,15 +986,21 @@ mml-secure-epg-sign
 	 (signers (mml-secure-signers context signer-names))
 	 signature micalg)
     (unless signers
-      (let ((maybe-msg
-             (if mml-secure-smime-sign-with-sender
-                 "."
-               "; try setting `mml-secure-smime-sign-with-sender'.")))
-        ;; If `mml-secure-smime-sign-with-sender' is already non-nil
-        ;; then there's no point advising the user to examine it.  If
-        ;; there are any other variables worth examining, please
-        ;; improve this error message by having it mention them.
-        (error "Couldn't find any signer names%s" maybe-msg)))
+      (if (mml-secure-sender-sign-query protocol sender)
+          (setq signer-names (mml-secure-signer-names protocol sender)
+                signers (mml-secure-signers context signer-names)))
+      (unless signers
+        (let ((maybe-msg
+               (if (or mml-secure-smime-sign-with-sender
+                       mml-secure-openpgp-sign-with-sender)
+                   "."
+                 "; try setting `mml-secure-smime-sign-with-sender' or 'mml-secure-openpgp-sign-with-sender'.")))
+          ;; If `mml-secure-smime-sign-with-sender' or
+          ;; `mml-secure-openpgp-sign-with-sender' are already non-nil
+          ;; then there's no point advising the user to examine them.
+          ;; If there are any other variables worth examining, please
+          ;; improve this error message by having it mention them.
+          (error "Couldn't find any signer names%s" maybe-msg))))
     (when (eq 'OpenPGP protocol)
       (setf (epg-context-armor context) t)
       (setf (epg-context-textmode context) t)

Robert
-- 





  reply	other threads:[~2020-09-30 16:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18 14:51 bug#40118: 27.0.90; Signing emails with gpg Sharon Kimble
2020-04-14 11:10 ` Štěpán Němec
2020-04-15 16:37   ` Robert Pluim
2020-04-15 16:45     ` Eli Zaretskii
2020-04-16  9:44       ` Robert Pluim
2020-04-16 10:15         ` Eli Zaretskii
2020-04-16 10:38           ` Robert Pluim
2020-04-17 15:11             ` Robert Pluim
2020-04-20 10:52               ` Robert Pluim
2020-04-20 16:24                 ` Eli Zaretskii
2020-04-20 16:58                   ` Robert Pluim
2020-04-30  4:33             ` Lars Ingebrigtsen
2020-04-30  7:37               ` Robert Pluim
2020-04-30 22:03                 ` Lars Ingebrigtsen
2020-05-05 12:46                   ` Robert Pluim
2020-05-05 15:06                     ` Eli Zaretskii
2020-05-05 15:23                       ` Robert Pluim
2020-05-05 16:07                         ` Eli Zaretskii
2020-09-30 14:57                         ` Lars Ingebrigtsen
2020-09-30 16:44                           ` Robert Pluim [this message]
2020-10-01  0:16                             ` Lars Ingebrigtsen
2020-10-01 17:41                               ` Robert Pluim
2020-10-01 17:43                                 ` Lars Ingebrigtsen
2020-10-02  8:49                                   ` Robert Pluim

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=m2y2kr2ozf.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=40118@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=stepnem@gmail.com \
    /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).