dirmngr: Do not rewrite the redirection for the "openpgpkey" subdomain.
authorWerner Koch <wk@gnupg.org>
Wed, 3 Jul 2019 14:20:00 +0000 (16:20 +0200)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 1 Jul 2022 16:06:43 +0000 (17:06 +0100)
* dirmngr/http.c (same_host_p): Consider certain subdomains to be the
same.
--

GnuPG-bug-id: 4603
Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit 37f0c55c7be3fc4912237f2bc72466aef6f8aa36)
(cherry picked from commit c9b133a54e93b7f2365b5d6b1c39ec2cc6dac8f9)

Gbp-Pq: Topic from-2.2.17
Gbp-Pq: Name dirmngr-Do-not-rewrite-the-redirection-for-the-openpgpkey.patch

dirmngr/http.c

index 384f2569d77f69635476113d440154af3a3d101c..d2456c6dc912623a057dceb37fc93ebc6661b065 100644 (file)
@@ -3533,6 +3533,10 @@ same_host_p (parsed_uri_t a, parsed_uri_t b)
     { NULL,             "api.protonmail.ch"  },
     { "pm.me",          "api.protonmail.ch"  }
   };
+  static const char *subdomains[] =
+    {
+      "openpgpkey."
+    };
   int i;
   const char *from;
 
@@ -3554,6 +3558,22 @@ same_host_p (parsed_uri_t a, parsed_uri_t b)
         return 1;
     }
 
+  /* Also consider hosts the same if they differ only in a subdomain;
+   * in both direction.  This allows to have redirection between the
+   * WKD advanced and direct lookup methods. */
+  for (i=0; i < DIM (subdomains); i++)
+    {
+      const char *subdom = subdomains[i];
+      size_t subdomlen = strlen (subdom);
+
+      if (!ascii_strncasecmp (a->host, subdom, subdomlen)
+          && !ascii_strcasecmp (a->host + subdomlen, b->host))
+        return 1;
+      if (!ascii_strncasecmp (b->host, subdom, subdomlen)
+          && !ascii_strcasecmp (b->host + subdomlen, a->host))
+        return 1;
+    }
+
   return 0;
 }