Package: gnupg2 / 2.2.12-1+deb10u1

from-2.2.15/wkd-New-command-print-wkd-url-for-gpg-wks-client.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
From: Werner Koch <wk@gnupg.org>
Date: Mon, 25 Mar 2019 15:13:59 +0100
Subject: wkd: New command --print-wkd-url for gpg-wks-client.

* tools/gpg-wks-client.c (aPrintWKDURL): New.
(opts): Add option.
(main): Implement.
* tools/wks-util.c (wks_cmd_print_wkd_url): New.

Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit 2f3eebf1865a85f8c09a1c052513260ed55acec6)
---
 doc/wks.texi           |  8 ++++++--
 tools/gpg-wks-client.c | 19 +++++++++++++++++--
 tools/gpg-wks.h        |  1 +
 tools/wks-util.c       | 27 ++++++++++++++++++++++++++-
 4 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/doc/wks.texi b/doc/wks.texi
index 0c8a59a..ced418a 100644
--- a/doc/wks.texi
+++ b/doc/wks.texi
@@ -101,10 +101,14 @@ fingerprint and the mailbox separated by a space.  The command
 @option{--remove-key} removes a key from that directory, its only
 argument is a user-id.
 
-The command @option{--print-wkd-hash} prints a WKD user id identifier
-and the corresponding mailbox from the user-ids given on the command
+The command @option{--print-wkd-hash} prints the WKD user-id identifiers
+and the corresponding mailboxes from the user-ids given on the command
 line or via stdin (one user-id per line).
 
+The command @option{--print-wkd-url} prints the URLs used to fetch the
+key for the given user-ids from WKD.  The meanwhile preferred format
+with sub-domains is used here.
+
 @command{gpg-wks-client} is not commonly invoked directly and thus it
 is not installed in the bin directory.  Here is an example how it can
 be invoked manually to check for a Web Key Directory entry for
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index f1750bf..050c8aa 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -62,6 +62,7 @@ enum cmd_and_opt_values
     aInstallKey,
     aRemoveKey,
     aPrintWKDHash,
+    aPrintWKDURL,
 
     oGpgProgram,
     oSend,
@@ -93,6 +94,8 @@ static ARGPARSE_OPTS opts[] = {
               "remove a key from a directory"),
   ARGPARSE_c (aPrintWKDHash, "print-wkd-hash",
               "Print the WKD identifier for the given user ids"),
+  ARGPARSE_c (aPrintWKDURL, "print-wkd-url",
+              "Print the WKD URL for the given user id"),
 
   ARGPARSE_group (301, ("@\nOptions:\n ")),
 
@@ -236,6 +239,7 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
         case aInstallKey:
         case aRemoveKey:
         case aPrintWKDHash:
+        case aPrintWKDURL:
           cmd = pargs->r_opt;
           break;
 
@@ -384,13 +388,24 @@ main (int argc, char **argv)
       break;
 
     case aPrintWKDHash:
+    case aPrintWKDURL:
       if (!argc)
-        err = proc_userid_from_stdin (wks_cmd_print_wkd_hash, "printing hash");
+        {
+          if (cmd == aPrintWKDHash)
+            err = proc_userid_from_stdin (wks_cmd_print_wkd_hash,
+                                          "printing WKD hash");
+          else
+            err = proc_userid_from_stdin (wks_cmd_print_wkd_url,
+                                          "printing WKD URL");
+        }
       else
         {
           for (err = delayed_err = 0; !err && argc; argc--, argv++)
             {
-              err = wks_cmd_print_wkd_hash (*argv);
+              if (cmd == aPrintWKDHash)
+                err = wks_cmd_print_wkd_hash (*argv);
+              else
+                err = wks_cmd_print_wkd_url (*argv);
               if (gpg_err_code (err) == GPG_ERR_INV_USER_ID)
                 {
                   /* Diagnostic already printed.  */
diff --git a/tools/gpg-wks.h b/tools/gpg-wks.h
index 99969c1..9acd7c3 100644
--- a/tools/gpg-wks.h
+++ b/tools/gpg-wks.h
@@ -104,6 +104,7 @@ gpg_error_t wks_compute_hu_fname (char **r_fname, const char *addrspec);
 gpg_error_t wks_cmd_install_key (const char *fname, const char *userid);
 gpg_error_t wks_cmd_remove_key (const char *userid);
 gpg_error_t wks_cmd_print_wkd_hash (const char *userid);
+gpg_error_t wks_cmd_print_wkd_url (const char *userid);
 
 
 /*-- wks-receive.c --*/
diff --git a/tools/wks-util.c b/tools/wks-util.c
index fee46d6..29e9248 100644
--- a/tools/wks-util.c
+++ b/tools/wks-util.c
@@ -1104,7 +1104,7 @@ wks_cmd_remove_key (const char *userid)
 }
 
 
-/* Print the WKD hash for the user ids to stdout.  */
+/* Print the WKD hash for the user id to stdout.  */
 gpg_error_t
 wks_cmd_print_wkd_hash (const char *userid)
 {
@@ -1121,3 +1121,28 @@ wks_cmd_print_wkd_hash (const char *userid)
   xfree (addrspec);
   return err;
 }
+
+
+/* Print the WKD URL for the user id to stdout.  */
+gpg_error_t
+wks_cmd_print_wkd_url (const char *userid)
+{
+  gpg_error_t err;
+  char *addrspec, *fname;
+  char *domain;
+
+  err = wks_fname_from_userid (userid, 1, &fname, &addrspec);
+  if (err)
+    return err;
+
+  domain = strchr (addrspec, '@');
+  if (domain)
+    *domain++ = 0;
+
+  es_printf ("https://openpgpkey.%s/.well-known/openpgpkey/%s/hu/%s?l=%s\n",
+             domain, domain, fname, addrspec);
+
+  xfree (fname);
+  xfree (addrspec);
+  return err;
+}