unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: emacs-devel@gnu.org
Subject: [PATCH] Fix random selection of keyserver
Date: Sun, 30 May 2021 18:36:29 +0000	[thread overview]
Message-ID: <20210530183629.599038-1-philipk@posteo.net> (raw)

* epa-ks.el (epa-keyserver-list): Add new variable
(epa-keyserver): Use epa-keyserver-list to generate type
(epa-ks--fetch-key): Check if epa-keyserver is 'random
(epa-search-keys): Check if epa-keyserver is 'random
---
 lisp/epa-ks.el | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/lisp/epa-ks.el b/lisp/epa-ks.el
index a33025b112..dcdbefc57b 100644
--- a/lisp/epa-ks.el
+++ b/lisp/epa-ks.el
@@ -38,18 +38,23 @@ epa-ks
   :version "28.1"
   :group 'epa)
 
+(defvar epa-keyserver-list
+  '("keyring.debian.org"
+    "keys.gnupg.net"
+    "keyserver.ubuntu.com"
+    "pgp.mit.edu"
+    "pool.sks-keyservers.net"
+    "zimmermann.mayfirst.org")
+  "List of default keyservers.")
+
 (defcustom epa-keyserver "pgp.mit.edu"
   "Domain of keyserver.
 
 This is used by `epa-ks-lookup-key', for looking up public keys."
-  :type '(choice :tag "Keyserver"
+  :type `(choice :tag "Keyserver"
                  (const random)
-                 (const "keyring.debian.org")
-                 (const "keys.gnupg.net")
-                 (const "keyserver.ubuntu.com")
-                 (const "pgp.mit.edu")
-                 (const "pool.sks-keyservers.net")
-                 (const "zimmermann.mayfirst.org")
+                 ,@(mapcar (lambda (server) `(const ,server))
+                           epa-keyserver-list)
                  (string :tag "Custom keyserver"))
   :version "28.1")
 
@@ -145,7 +150,10 @@ epa-ks--fetch-key
   "Send request to import key with specified ID."
   (url-retrieve
    (format "https://%s/pks/lookup?%s"
-           epa-keyserver
+           (if (eq epa-keyserver 'random)
+               (nth (random (length epa-keyserver-list))
+                    epa-keyserver-list)
+               epa-keyserver)
            (url-build-query-string
             `(("search" ,(concat "0x" (url-hexify-string id)))
               ("options" "mr")
@@ -225,7 +233,10 @@ epa-search-keys
       (epa-ks-search-mode))
     (url-retrieve
      (format "https://%s/pks/lookup?%s"
-             epa-keyserver
+             (if (eq epa-keyserver 'random)
+               (nth (random (length epa-keyserver-list))
+                    epa-keyserver-list)
+               epa-keyserver)
              (url-build-query-string
               (append `(("search" ,query)
                         ("options" "mr")
-- 
2.30.2




             reply	other threads:[~2021-05-30 18:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30 18:36 Philip Kaludercic [this message]
2021-05-30 18:57 ` [PATCH] Fix random selection of keyserver Eli Zaretskii
2021-05-30 19:46   ` Philip Kaludercic
2021-05-31  9:00     ` Lars Ingebrigtsen
2021-05-31 11:13       ` Philip Kaludercic
2021-05-31 11:43         ` Andreas Schwab
2021-05-31 12:04           ` Philip Kaludercic
2021-06-01  5:49         ` Lars Ingebrigtsen
2021-05-31 11:45       ` 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=20210530183629.599038-1-philipk@posteo.net \
    --to=philipk@posteo.net \
    --cc=emacs-devel@gnu.org \
    /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).