From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Philip K Newsgroups: gmane.emacs.bugs Subject: bug#40354: [PATCH] Fix Libravatar federation handling Date: Tue, 31 Mar 2020 20:03:24 +0200 Message-ID: <20200331180324.2943-1-philip@warpmail.net> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="56605"; mail-complaints-to="usenet@ciao.gmane.io" To: 40354@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 31 20:04:16 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1jJLFH-000Eb4-O2 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 31 Mar 2020 20:04:16 +0200 Original-Received: from localhost ([::1]:42602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJLFG-0000N1-G6 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 31 Mar 2020 14:04:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57231) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJLF5-0000MA-Eq for bug-gnu-emacs@gnu.org; Tue, 31 Mar 2020 14:04:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJLF4-0001AE-5S for bug-gnu-emacs@gnu.org; Tue, 31 Mar 2020 14:04:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53671) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJLF4-0001A3-2h for bug-gnu-emacs@gnu.org; Tue, 31 Mar 2020 14:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jJLF3-0005Pd-SU for bug-gnu-emacs@gnu.org; Tue, 31 Mar 2020 14:04:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip K Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 Mar 2020 18:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 40354 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.158567781820758 (code B ref -1); Tue, 31 Mar 2020 18:04:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Mar 2020 18:03:38 +0000 Original-Received: from localhost ([127.0.0.1]:36979 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jJLEf-0005Oj-Sv for submit@debbugs.gnu.org; Tue, 31 Mar 2020 14:03:38 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:49404) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jJLEd-0005Ob-V1 for submit@debbugs.gnu.org; Tue, 31 Mar 2020 14:03:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57159) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJLEc-00007u-0q for bug-gnu-emacs@gnu.org; Tue, 31 Mar 2020 14:03:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJLEa-00010Z-Lr for bug-gnu-emacs@gnu.org; Tue, 31 Mar 2020 14:03:33 -0400 Original-Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:52827) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJLEY-0000zb-Ts for bug-gnu-emacs@gnu.org; Tue, 31 Mar 2020 14:03:32 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 4E1075BD for ; Tue, 31 Mar 2020 14:03:29 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 31 Mar 2020 14:03:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=warpmail.net; h= from:to:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=M+VJr+i9Y9nxysvxxo3jXSAhNj i+J/Gaq78Pzbz3KHU=; b=rJsjgcJamCJxOSjswAbiaI114OB0D5T+sqSEuZ2kBv VY2I1qyUX/sA9jObKENqGscdYbwVx8QgVRAi8sOc5rGjg0yFr/++R80Q1gICORHt CI4h1K2dSP1xYL9R6+EJqIdXbWkQM/grK5mOXLPG45/lhqXRkXXYB9lhZU08Ah1E s8eZkkp3MTs4vHeEFX/kl+JSU4l5pvfHKqAN1Wxvew+TwYqMcjGnHpVccVz6efry LXJ2jr+KQh9nilC4zImy+6RVqZDjlpk0RelYkEVFtTJ5flz8+PX6YWy3FCGmjVWk /g7yUU9/N46kqCpALefQaW4YUeZqnZgeaQ9F0kiHIZhA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=M+VJr+i9Y9nxysvxx o3jXSAhNji+J/Gaq78Pzbz3KHU=; b=McwaCuiox7DS3PEzEOnWmD3qc89twB3zB M3AFL2NdpSYt3dV9WPrnxgBlobApodhmwzDvhbIw7kWQXCLsU1/A4ZpJiz8bxTUD Z1ZDlgpJRzBjcaD/Fez0cqq+27fZ6A2N0mCPBn9FClVWI1hr/cuA0S6Ja/LKhbBI SqsYthPBpG+CE2RxQ0o4cV5n4T37pgmT5z9eOYCDuAfIa575GmJBIe7P00rjwyA5 IqI5pmJJx/zV8e3Gjp6FlLS2yxqZJNJZrhbamTrr2OsVTRgOQ6YhMyA+/p93souk y4t4dz+3lrfRwvMEKJ7UQEEam0bWMuR9dzUhMNIX1xM2ie8tvHgJA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrtddtgdekjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffoggfgsedtkeertdertd dtnecuhfhrohhmpefrhhhilhhiphcumfcuoehphhhilhhiphesfigrrhhpmhgrihhlrdhn vghtqeenucffohhmrghinheplhhisghrrghvrghtrghrrdhorhhgnecukfhppeejledrvd duledrudelledrudeftdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpehphhhilhhiphesfigrrhhpmhgrihhlrdhnvght X-ME-Proxy: Original-Received: from localhost (p4fdbc782.dip0.t-ipconnect.de [79.219.199.130]) by mail.messagingengine.com (Postfix) with ESMTPA id 7C074306CBCC for ; Tue, 31 Mar 2020 14:03:28 -0400 (EDT) X-Mailer: git-send-email 2.20.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177926 Archived-At: Previous implementation didn't correctly handle the result of dns-query, and didn't implement the necessary record selection algorithm as specified on the wiki (https://wiki.libravatar.org/api/, "Federated servers"). * lisp/image/gravatar.el (gravatar--service-libravatar): Fix libravatar image host resolver algorithm. --- lisp/image/gravatar.el | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lisp/image/gravatar.el b/lisp/image/gravatar.el index ff59a72ac8..a2207af962 100644 --- a/lisp/image/gravatar.el +++ b/lisp/image/gravatar.el @@ -149,13 +149,36 @@ gravatar--service-libravatar (dolist (record '(("_avatars-sec" . "https") ("_avatars" . "http"))) (let* ((query (concat (car record) "._tcp." domain)) - (result (dns-query query 'SRV))) + (result (dns-query query 'SRV t))) (when result - (throw 'found (format "%s://%s/avatar" - (cdr record) - result))))) - "https://seccdn.libravatar.org/avatar"))))) + (let* ((res (mapcar (lambda (rec) + (dns-get 'data (cdr rec))) + (dns-get 'answers result))) + (prio + (mapcar (lambda (r) (dns-get 'priority r)) res)) + (max (apply #'max prio)) + (sum 0) top) + ;; Attempt to find all records with the same maximal + ;; priority, and calculate the sum of their weights. + (dolist (rec res) + (when (= max (dns-get 'priority rec)) + (setq sum (+ sum (dns-get 'weight rec))) + (push rec top))) + ;; In case there is more than one maximal priority + ;; record, choose one at random, while taking the + ;; individual record weights into consideration. + (dolist (rec top) + (when (and (<= (if (= 0 sum) -1 (random sum)) + (dns-get 'weight rec)) + (<= 1 (dns-get 'port rec) 65535) + (string-match-p "\\`[-.0-9A-Za-z]+\\'" + (dns-get 'target rec))) + (throw 'found (format "%s://%s:%s/avatar" + (cdr record) + (dns-get 'target rec) + (dns-get 'port rec)))) + (setq sum (- sum (dns-get 'weight rec))))))) + "https://seccdn.libravatar.org/avatar")))))) (defun gravatar-hash (mail-address) "Return the Gravatar hash for MAIL-ADDRESS." -- 2.20.1