Subject: bug#31877: [PATCH] nsm.el: Add choice to reshow certificate information

From: Allen Li <[email-masked]>
Date: Wed, 1 Aug 2018 03:09:43 -0700

I have attached a patch to add a choice to reshow the cert, since the
fundamental problem is that the user could get stuck in a situation
where they have to choose to accept a cert they can't see.
From 9b474c7f93fa277ce9b136012c05f43c56a6b498 Mon Sep 17 00:00:00 2001
From: Allen Li <[email-masked]>
Date: Wed, 1 Aug 2018 03:04:26 -0700
Subject: [PATCH] Add choice to reshow certificate information

In various situations, the window displaying the certificate
information can be hidden (such as if the user accidentally presses ?,
which causes the read-multiple-choice help window to replace it).
Instead of leaving the user to make a choice blindly, add a choice to
reshow the certification information.

* lisp/net/nsm.el (nsm-query-user): Add reshow choice.
---
 lisp/net/nsm.el | 51 +++++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/lisp/net/nsm.el b/lisp/net/nsm.el
index dab9003e02..b4721ca7cf 100644
--- a/lisp/net/nsm.el
+++ b/lisp/net/nsm.el
@@ -365,29 +365,34 @@ nsm-query
 	t))))
 
 (defun nsm-query-user (message args cert)
-  (let ((buffer (get-buffer-create "*Network Security Manager*")))
-    (save-window-excursion
-      ;; First format the certificate and warnings.
-      (with-help-window buffer
-        (with-current-buffer buffer
-          (erase-buffer)
-          (when (> (length cert) 0)
-            (insert cert "\n"))
-          (let ((start (point)))
-            (insert (apply #'format-message message args))
-            (goto-char start)
-            ;; Fill the first line of the message, which usually
-            ;; contains lots of explanatory text.
-            (fill-region (point) (line-end-position)))))
-      ;; Then ask the user what to do about it.
-      (unwind-protect
-          (cadr
-           (read-multiple-choice
-            "Continue connecting?"
-            '((?a "always" "Accept this certificate this session and for all future sessions.")
-              (?s "session only" "Accept this certificate this session only.")
-              (?n "no" "Refuse to use this certificate, and close the connection."))))
-        (kill-buffer buffer)))))
+  (catch 'return
+    (while t
+      (let ((buffer (get-buffer-create "*Network Security Manager*")))
+        (save-window-excursion
+          ;; First format the certificate and warnings.
+          (with-help-window buffer
+            (with-current-buffer buffer
+              (erase-buffer)
+              (when (> (length cert) 0)
+                (insert cert "\n"))
+              (let ((start (point)))
+                (insert (apply #'format-message message args))
+                (goto-char start)
+                ;; Fill the first line of the message, which usually
+                ;; contains lots of explanatory text.
+                (fill-region (point) (line-end-position)))))
+          ;; Then ask the user what to do about it.
+          (pcase (unwind-protect
+                     (cadr
+                      (read-multiple-choice
+                       "Continue connecting?"
+                       '((?a "always" "Accept this certificate this session and for all future sessions.")
+                         (?s "session only" "Accept this certificate this session only.")
+                         (?n "no" "Refuse to use this certificate, and close the connection.")
+                         (?r "reshow" "Reshow certificate information."))))
+                   (kill-buffer buffer))
+            ("reshow")
+            (val (throw 'return val))))))))
 
 (defun nsm-save-host (host port status what permanency)
   (let* ((id (nsm-id host port))
-- 
2.18.0