From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Fix random selection of keyserver Date: Mon, 31 May 2021 11:13:41 +0000 Message-ID: <87pmx7noka.fsf@icterid> References: <20210530183629.599038-1-philipk@posteo.net> <83mtsc2gor.fsf@gnu.org> <87sg243szf.fsf@icterid> <875yyzgtvk.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10185"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon May 31 13:14:40 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lnfsW-0002Q1-BH for ged-emacs-devel@m.gmane-mx.org; Mon, 31 May 2021 13:14:40 +0200 Original-Received: from localhost ([::1]:45518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lnfsU-0001kO-79 for ged-emacs-devel@m.gmane-mx.org; Mon, 31 May 2021 07:14:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnfrg-00011A-PX for emacs-devel@gnu.org; Mon, 31 May 2021 07:13:48 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:52929) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lnfrd-0007rj-BP for emacs-devel@gnu.org; Mon, 31 May 2021 07:13:48 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 13CD2240027 for ; Mon, 31 May 2021 13:13:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1622459623; bh=8eZ4gmx33Nic1ba7DP3cPwGyoPpNiOWOlq2wytCnGss=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=EKbDCT8CC+oO8N1IDG7e7fFc6aAX0e3NJE9iCBqiQC++7PN+EpV1erhyh6rtqfI79 OvZac3kVKdgm//plWec5OS6jLUUmzUwbGX39lK4JPthlh50PTZDh1l4Eg/UOe1/2V1 ukEjsossu5RbyXBdahuuDU+waen8wOXzJF01/6rrT2clGQo50MGU6tVmSQXwg43v48 qBqxfA97kI2uIxeR+8zUKIO98DDrGG4tggpEY8G0yvReLY/5Y/ND1HF4aZ1HzeAjZW lnNKyuJZTTZ9GIcNj/YOhLcd9IhCwberFghL0biXxDDkm9JQ4LYgD+xSF83AveUjso hFfE15iUH7Ing== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Ftt2Z3qBrz6tmb; Mon, 31 May 2021 13:13:42 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=mutual; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB In-Reply-To: <875yyzgtvk.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 31 May 2021 11:00:47 +0200") Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:270164 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > Philip Kaludercic writes: > >> Perhaps, the intent of this patch was just to fix the currently broken >> behaviour suggested by epa-keyserver's type. >> >> I am not sure if a :set function could be used to randomize the >> keyserver for every request. Then again, is might not even really be >> necessary to provide such a feature. > > I wonder whether it might make sense instead to allow `epa-keyserver' to > be a list, and if so, then choose a random server from that list. > That'd give users control over what servers to use when randomising. That does seem to be a better approach, how does the patch below look like? -- Philip K. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Improve-random-selection-of-keyservers.patch >From fdbb17539a465c49aad93cef4e0b8b4b76699561 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Sun, 30 May 2021 20:34:54 +0200 Subject: [PATCH] Improve random selection of keyservers * epa-ks.el (epa-keyserver): Interpret a list as a pool (epa-ks--query-url): Add new auxiliary function (epa-ks--fetch-key): Use epa-ks--query-url (epa-search-keys): Use epa-ks--query-url --- lisp/epa-ks.el | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/lisp/epa-ks.el b/lisp/epa-ks.el index a33025b112..1d17c1399c 100644 --- a/lisp/epa-ks.el +++ b/lisp/epa-ks.el @@ -42,8 +42,9 @@ epa-keyserver "Domain of keyserver. This is used by `epa-ks-lookup-key', for looking up public keys." - :type '(choice :tag "Keyserver" - (const random) + :type `(choice :tag "Keyserver" + (repeat :tag "Random pool" + (string :tag "Keyserver address")) (const "keyring.debian.org") (const "keys.gnupg.net") (const "keyserver.ubuntu.com") @@ -141,20 +142,33 @@ epa-ks-do-key-to-fetch (epa-ks--fetch-key id)))) (tabulated-list-clear-all-tags)) +(defun epa-ks--query-url (query exact) + "Return URL for QUERY. +If EXACT is non-nil, don't accept approximate matches." + (format "https://%s/pks/lookup?%s" + (cond ((null epa-keyserver) + (user-error "Empty keyserver pool")) + ((listp epa-keyserver) + (nth (random (length epa-keyserver)) + epa-keyserver)) + ((stringp epa-keyserver) + epa-keyserver) + ((error "Invalid type for `epa-keyserver'"))) + (url-build-query-string + (append `(("search" ,query) + ("options" "mr") + ("op" "index")) + (and exact '(("exact" "on"))))))) + (defun epa-ks--fetch-key (id) "Send request to import key with specified ID." (url-retrieve - (format "https://%s/pks/lookup?%s" - epa-keyserver - (url-build-query-string - `(("search" ,(concat "0x" (url-hexify-string id))) - ("options" "mr") - ("op" "get")))) + (epa-ks--query-url (concat "0x" (url-hexify-string id)) t) (lambda (status) (when (plist-get status :error) (error "Request failed: %s" - (caddr (assq (caddr (plist-get status :error)) - url-http-codes)))) + (caddr (assq (caddr (plist-get status :error)) + url-http-codes)))) (forward-paragraph) (save-excursion (goto-char (point-max)) @@ -224,13 +238,7 @@ epa-search-keys (erase-buffer)) (epa-ks-search-mode)) (url-retrieve - (format "https://%s/pks/lookup?%s" - epa-keyserver - (url-build-query-string - (append `(("search" ,query) - ("options" "mr") - ("op" "index")) - (and exact '(("exact" "on")))))) + (epa-ks--query-url query exact) (lambda (status) (when (plist-get status :error) (when buf -- 2.30.2 --=-=-=--