aboutsummaryrefslogtreecommitdiffstats
path: root/tools/gpg-wks-client.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2025-06-02 10:42:59 +0000
committerWerner Koch <[email protected]>2025-06-02 10:42:59 +0000
commite6463d7fe097b39c9e8952ef9f5758fa0ee0e4bd (patch)
tree38222b8338276d8de0b92130dd43b003ec46754c /tools/gpg-wks-client.c
parentgpg-mail-tube: Support templates. (diff)
downloadgnupg-e6463d7fe097b39c9e8952ef9f5758fa0ee0e4bd.tar.gz
gnupg-e6463d7fe097b39c9e8952ef9f5758fa0ee0e4bd.zip
wks: Use templates for the server responses.
* common/helpfile.c (gnupg_get_template): Add arg locale_override and adjust all callers. * tools/wks-receive.c (struct receive_ctx_s): Add field ct_language. (get_language): New. (new_part): Call it. (wks_receive): Pass language to the result callback. * tools/gpg-wks-client.c (short_locale): New. (main): Get and store the current locale. (command_create): Fix a glitch for the Posteo hack. Insert the locale into the confirmation request. (send_confirmation_response): Ditto. * tools/gpg-wks-server.c (struct server_ctx_s): Add field language. (only_ascii): New. (struct my_subst_vars_s, my_subst_vars_cb, my_subst_vars): New. (send_confirmation_request): Use a template. (send_congratulation_message): Ditto. (check_and_publish): Pss ctx to send_congratulation_message. (command_receive_cb): Add arg language. * doc/wks-utils.txt, doc/wks-utils.de.txt: New. * doc/Makefile.am (helpfiles): Add them. -- GnuPG-bug-id: 7381 Note that the subject is not yet translated or templated due to a missing header encoding function.
Diffstat (limited to 'tools/gpg-wks-client.c')
-rw-r--r--tools/gpg-wks-client.c70
1 files changed, 49 insertions, 21 deletions
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index ef11a4e3e..2d037faef 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -155,6 +155,8 @@ const char *fake_submission_addr;
static char **blacklist_array;
static size_t blacklist_array_len;
+/* The current locale in the short form (e.g. "de" instead of "de_DE") */
+static char *short_locale;
static void wrong_args (const char *t1, const char *t2) GPGRT_ATTR_NORETURN;
static void add_blacklist (const char *fname);
@@ -168,7 +170,9 @@ static gpg_error_t encrypt_response (estream_t *r_output, estream_t input,
const char *fingerprint);
static gpg_error_t read_confirmation_request (estream_t msg);
static gpg_error_t command_receive_cb (void *opaque,
- const char *mediatype, estream_t fp,
+ const char *mediatype,
+ const char *language,
+ estream_t fp,
unsigned int flags);
static gpg_error_t command_mirror (char *domain[]);
@@ -374,6 +378,20 @@ main (int argc, char **argv)
!opt.no_autostart);
+ /* Get the short form of the current locale. */
+ {
+ const char *locname = gnupg_messages_locale_name ();
+ char *p;
+
+ if (locname && *locname && strcmp (locname, "C"))
+ {
+ short_locale = xstrdup (locname);
+ if ((p = strpbrk (short_locale, "_.@/")))
+ *p = 0;
+ gpgrt_annotate_leaked_object (short_locale);
+ }
+ }
+
/* Check that the top directory exists. */
if (cmd == aInstallKey || cmd == aRemoveKey || cmd == aMirror)
{
@@ -1338,16 +1356,32 @@ command_create (const char *fingerprint, const char *userid)
}
}
+ /* Hack to support posteo but let them disable this by setting the
+ * new policy-version flag. */
+ if (policy->protocol_version < 3
+ && !ascii_strcasecmp (domain, "posteo.de"))
+ {
+ log_info ("Warning: Using draft-1 method for domain '%s'\n", domain);
+ no_encrypt = 1;
+ posteo_hack = 1;
+ }
+
/* Now put the armor around the key. */
{
estream_t newkey;
+ char *prefix;
+
+ prefix = xstrconcat
+ ("Content-Type: application/pgp-keys\n",
+ short_locale && *short_locale? "Content-Language: " : "",
+ short_locale && *short_locale? short_locale : "",
+ short_locale && *short_locale? "\n" : "",
+ "\n", NULL);
es_rewind (key);
- err = wks_armor_key (&newkey, key,
- no_encrypt? NULL
- /* */ : ("Content-Type: application/pgp-keys\n"
- "\n"));
+ err = wks_armor_key (&newkey, key, no_encrypt? NULL : prefix);
+ xfree (prefix);
if (err)
{
log_error ("error armoring key: %s\n", gpg_strerror (err));
@@ -1357,16 +1391,6 @@ command_create (const char *fingerprint, const char *userid)
key = newkey;
}
- /* Hack to support posteo but let them disable this by setting the
- * new policy-version flag. */
- if (policy->protocol_version < 3
- && !ascii_strcasecmp (domain, "posteo.de"))
- {
- log_info ("Warning: Using draft-1 method for domain '%s'\n", domain);
- no_encrypt = 1;
- posteo_hack = 1;
- }
-
/* Encrypt the key part. */
if (!no_encrypt)
{
@@ -1415,8 +1439,10 @@ command_create (const char *fingerprint, const char *userid)
goto leave;
}
- err = mime_maker_add_header (mime, "Content-type",
+ err = mime_maker_add_header (mime, "Content-Type",
"application/pgp-keys");
+ if (!err && short_locale && *short_locale)
+ err = mime_maker_add_header (mime, "Content-Language", short_locale);
if (err)
goto leave;
@@ -1596,10 +1622,11 @@ send_confirmation_response (const char *sender, const char *address,
* only our client will see it. */
if (encrypt)
{
- es_fputs ("Content-Type: application/vnd.gnupg.wks\n"
- "Content-Transfer-Encoding: 8bit\n"
- "\n",
- body);
+ es_fprintf (body,
+ "Content-Type: application/vnd.gnupg.wks\n"
+ "Content-Transfer-Encoding: 8bit\n"
+ "Content-Language: %s\n"
+ "\n", (short_locale && *short_locale)? short_locale : "en");
}
es_fprintf (body, ("type: confirmation-response\n"
@@ -1858,12 +1885,13 @@ read_confirmation_request (estream_t msg)
/* Called from the MIME receiver to process the plain text data in MSG. */
static gpg_error_t
-command_receive_cb (void *opaque, const char *mediatype,
+command_receive_cb (void *opaque, const char *mediatype, const char *language,
estream_t msg, unsigned int flags)
{
gpg_error_t err;
(void)opaque;
+ (void)language;
(void)flags;
if (!strcmp (mediatype, "application/vnd.gnupg.wks"))