1 /* gpg-wks-client.c - A client for the Web Key Service protocols.
2 * Copyright (C) 2016 Werner Koch
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
34 #include "mbox-util.h"
35 #include "name-value.h"
36 #include "call-dirmngr.h"
37 #include "mime-maker.h"
38 #include "send-mail.h"
42 /* Constants to identify the commands and options. */
43 enum cmd_and_opt_values
68 /* The list of commands and options. */
69 static ARGPARSE_OPTS opts[] = {
70 ARGPARSE_group (300, ("@Commands:\n ")),
72 ARGPARSE_c (aSupported, "supported",
73 ("check whether provider supports WKS")),
74 ARGPARSE_c (aCheck, "check",
75 ("check whether a key is available")),
76 ARGPARSE_c (aCreate, "create",
77 ("create a publication request")),
78 ARGPARSE_c (aReceive, "receive",
79 ("receive a MIME confirmation request")),
80 ARGPARSE_c (aRead, "read",
81 ("receive a plain text confirmation request")),
83 ARGPARSE_group (301, ("@\nOptions:\n ")),
85 ARGPARSE_s_n (oVerbose, "verbose", ("verbose")),
86 ARGPARSE_s_n (oQuiet, "quiet", ("be somewhat more quiet")),
87 ARGPARSE_s_s (oDebug, "debug", "@"),
88 ARGPARSE_s_s (oGpgProgram, "gpg", "@"),
89 ARGPARSE_s_n (oSend, "send", "send the mail using sendmail"),
90 ARGPARSE_s_s (oOutput, "output", "|FILE|write the mail to FILE"),
91 ARGPARSE_s_i (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
93 ARGPARSE_s_s (oFakeSubmissionAddr, "fake-submission-addr", "@"),
99 /* The list of supported debug flags. */
100 static struct debug_flags_s debug_flags [] =
102 { DBG_MIME_VALUE , "mime" },
103 { DBG_PARSER_VALUE , "parser" },
104 { DBG_CRYPTO_VALUE , "crypto" },
105 { DBG_MEMORY_VALUE , "memory" },
106 { DBG_MEMSTAT_VALUE, "memstat" },
107 { DBG_IPC_VALUE , "ipc" },
108 { DBG_EXTPROG_VALUE, "extprog" },
114 /* Value of the option --fake-submission-addr. */
115 const char *fake_submission_addr;
118 static void wrong_args (const char *text) GPGRT_ATTR_NORETURN;
119 static gpg_error_t command_supported (char *userid);
120 static gpg_error_t command_check (char *userid);
121 static gpg_error_t command_send (const char *fingerprint, char *userid);
122 static gpg_error_t encrypt_response (estream_t *r_output, estream_t input,
123 const char *addrspec,
124 const char *fingerprint);
125 static gpg_error_t read_confirmation_request (estream_t msg);
126 static gpg_error_t command_receive_cb (void *opaque,
127 const char *mediatype, estream_t fp,
132 /* Print usage information and and provide strings for help. */
134 my_strusage( int level )
140 case 11: p = "gpg-wks-client (@GNUPG@)";
142 case 13: p = VERSION; break;
143 case 17: p = PRINTABLE_OS_NAME; break;
144 case 19: p = ("Please report bugs to <@EMAIL@>.\n"); break;
148 p = ("Usage: gpg-wks-client [command] [options] [args] (-h for help)");
151 p = ("Syntax: gpg-wks-client [command] [options] [args]\n"
152 "Client for the Web Key Service\n");
155 default: p = NULL; break;
162 wrong_args (const char *text)
164 es_fprintf (es_stderr, _("usage: %s [options] %s\n"), strusage (11), text);
170 /* Command line parsing. */
171 static enum cmd_and_opt_values
172 parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
174 enum cmd_and_opt_values cmd = 0;
175 int no_more_options = 0;
177 while (!no_more_options && optfile_parse (NULL, NULL, NULL, pargs, popts))
179 switch (pargs->r_opt)
181 case oQuiet: opt.quiet = 1; break;
182 case oVerbose: opt.verbose++; break;
184 if (parse_debug_flag (pargs->r.ret_str, &opt.debug, debug_flags))
186 pargs->r_opt = ARGPARSE_INVALID_ARG;
187 pargs->err = ARGPARSE_PRINT_ERROR;
192 opt.gpg_program = pargs->r.ret_str;
195 opt.use_sendmail = 1;
198 opt.output = pargs->r.ret_str;
200 case oFakeSubmissionAddr:
201 fake_submission_addr = pargs->r.ret_str;
204 wks_set_status_fd (translate_sys2libc_fd_int (pargs->r.ret_int, 1));
215 default: pargs->err = 2; break;
224 /* gpg-wks-client main. */
226 main (int argc, char **argv)
230 enum cmd_and_opt_values cmd;
232 gnupg_reopen_std ("gpg-wks-client");
233 set_strusage (my_strusage);
234 log_set_prefix ("gpg-wks-client", GPGRT_LOG_WITH_PREFIX);
236 /* Make sure that our subsystems are ready. */
238 init_common_subsystems (&argc, &argv);
240 assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
241 setup_libassuan_logging (&opt.debug, NULL);
243 /* Parse the command line. */
246 pargs.flags = ARGPARSE_FLAG_KEEP;
247 cmd = parse_arguments (&pargs, opts);
249 if (log_get_errorcount (0))
252 /* Print a warning if an argument looks like an option. */
253 if (!opt.quiet && !(pargs.flags & ARGPARSE_FLAG_STOP_SEEN))
257 for (i=0; i < argc; i++)
258 if (argv[i][0] == '-' && argv[i][1] == '-')
259 log_info (("NOTE: '%s' is not considered an option\n"), argv[i]);
262 /* Set defaults for non given options. */
263 if (!opt.gpg_program)
264 opt.gpg_program = gnupg_module_name (GNUPG_MODULE_NAME_GPG);
266 /* Tell call-dirmngr what options we want. */
267 set_dirmngr_options (opt.verbose, (opt.debug & DBG_IPC_VALUE), 1);
269 /* Run the selected command. */
274 wrong_args ("--supported USER-ID");
275 err = command_supported (argv[0]);
276 if (err && gpg_err_code (err) != GPG_ERR_FALSE)
277 log_error ("checking support failed: %s\n", gpg_strerror (err));
282 wrong_args ("--create FINGERPRINT USER-ID");
283 err = command_send (argv[0], argv[1]);
285 log_error ("creating request failed: %s\n", gpg_strerror (err));
290 wrong_args ("--receive < MIME-DATA");
291 err = wks_receive (es_stdin, command_receive_cb, NULL);
293 log_error ("processing mail failed: %s\n", gpg_strerror (err));
298 wrong_args ("--read < WKS-DATA");
299 err = read_confirmation_request (es_stdin);
301 log_error ("processing mail failed: %s\n", gpg_strerror (err));
306 wrong_args ("--check USER-ID");
307 err = command_check (argv[0]);
317 wks_write_status (STATUS_FAILURE, "- %u", err);
318 else if (log_get_errorcount (0))
319 wks_write_status (STATUS_FAILURE, "- %u", GPG_ERR_GENERAL);
321 wks_write_status (STATUS_SUCCESS, NULL);
322 return log_get_errorcount (0)? 1:0;
327 struct get_key_status_parm_s
335 get_key_status_cb (void *opaque, const char *keyword, char *args)
337 struct get_key_status_parm_s *parm = opaque;
339 /*log_debug ("%s: %s\n", keyword, args);*/
340 if (!strcmp (keyword, "EXPORTED"))
343 if (!ascii_strcasecmp (args, parm->fpr))
349 /* Get a key by fingerprint from gpg's keyring and make sure that the
350 * mail address ADDRSPEC is included in the key. The key is returned
351 * as a new memory stream at R_KEY.
353 * Fixme: After we have implemented import and export filters for gpg
354 * this function shall only return a key with just this user id. */
356 get_key (estream_t *r_key, const char *fingerprint, const char *addrspec)
360 const char **argv = NULL;
361 estream_t key = NULL;
362 struct get_key_status_parm_s parm;
363 char *filterexp = NULL;
365 memset (&parm, 0, sizeof parm);
369 key = es_fopenmem (0, "w+b");
372 err = gpg_error_from_syserror ();
373 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
376 /* Prefix the key with the MIME content type. */
377 es_fputs ("Content-Type: application/pgp-keys\n"
380 filterexp = es_bsprintf ("keep-uid=mbox = %s", addrspec);
383 err = gpg_error_from_syserror ();
384 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
388 ccparray_init (&ccp, 0);
390 ccparray_put (&ccp, "--no-options");
392 ccparray_put (&ccp, "--quiet");
393 else if (opt.verbose > 1)
394 ccparray_put (&ccp, "--verbose");
395 ccparray_put (&ccp, "--batch");
396 ccparray_put (&ccp, "--status-fd=2");
397 ccparray_put (&ccp, "--always-trust");
398 ccparray_put (&ccp, "--armor");
399 ccparray_put (&ccp, "--export-options=export-minimal");
400 ccparray_put (&ccp, "--export-filter");
401 ccparray_put (&ccp, filterexp);
402 ccparray_put (&ccp, "--export");
403 ccparray_put (&ccp, "--");
404 ccparray_put (&ccp, fingerprint);
406 ccparray_put (&ccp, NULL);
407 argv = ccparray_get (&ccp, NULL);
410 err = gpg_error_from_syserror ();
413 parm.fpr = fingerprint;
414 err = gnupg_exec_tool_stream (opt.gpg_program, argv, NULL,
416 get_key_status_cb, &parm);
417 if (!err && parm.count > 1)
418 err = gpg_error (GPG_ERR_TOO_MANY);
419 else if (!err && !parm.found)
420 err = gpg_error (GPG_ERR_NOT_FOUND);
423 log_error ("export failed: %s\n", gpg_strerror (err));
441 decrypt_stream_status_cb (void *opaque, const char *keyword, char *args)
446 log_debug ("gpg status: %s %s\n", keyword, args);
450 /* Decrypt the INPUT stream to a new stream which is stored at success
453 decrypt_stream (estream_t *r_output, estream_t input)
462 output = es_fopenmem (0, "w+b");
465 err = gpg_error_from_syserror ();
466 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
470 ccparray_init (&ccp, 0);
472 ccparray_put (&ccp, "--no-options");
473 /* We limit the output to 64 KiB to avoid DoS using compression
474 * tricks. A regular client will anyway only send a minimal key;
475 * that is one w/o key signatures and attribute packets. */
476 ccparray_put (&ccp, "--max-output=0x10000");
478 ccparray_put (&ccp, "--quiet");
479 else if (opt.verbose > 1)
480 ccparray_put (&ccp, "--verbose");
481 ccparray_put (&ccp, "--batch");
482 ccparray_put (&ccp, "--status-fd=2");
483 ccparray_put (&ccp, "--decrypt");
484 ccparray_put (&ccp, "--");
486 ccparray_put (&ccp, NULL);
487 argv = ccparray_get (&ccp, NULL);
490 err = gpg_error_from_syserror ();
493 err = gnupg_exec_tool_stream (opt.gpg_program, argv, input,
495 decrypt_stream_status_cb, NULL);
498 log_error ("decryption failed: %s\n", gpg_strerror (err));
501 else if (opt.verbose)
502 log_info ("decryption succeeded\n");
517 /* Check whether the provider supports the WKS protocol. */
519 command_supported (char *userid)
522 char *addrspec = NULL;
523 char *submission_to = NULL;
525 addrspec = mailbox_from_userid (userid);
528 log_error (_("\"%s\" is not a proper mail address\n"), userid);
529 err = gpg_error (GPG_ERR_INV_USER_ID);
533 /* Get the submission address. */
534 err = wkd_get_submission_address (addrspec, &submission_to);
537 if (gpg_err_code (err) == GPG_ERR_NO_DATA
538 || gpg_err_code (err) == GPG_ERR_UNKNOWN_HOST)
541 log_info ("provider for '%s' does NOT support WKS (%s)\n",
542 addrspec, gpg_strerror (err));
543 err = gpg_error (GPG_ERR_FALSE);
544 log_inc_errorcount ();
549 log_info ("provider for '%s' supports WKS\n", addrspec);
552 xfree (submission_to);
559 /* Check whether the key for USERID is available in the WKD. */
561 command_check (char *userid)
564 char *addrspec = NULL;
565 estream_t key = NULL;
567 strlist_t mboxes = NULL;
571 addrspec = mailbox_from_userid (userid);
574 log_error (_("\"%s\" is not a proper mail address\n"), userid);
575 err = gpg_error (GPG_ERR_INV_USER_ID);
579 /* Get the submission address. */
580 err = wkd_get_key (addrspec, &key);
581 switch (gpg_err_code (err))
585 log_info ("public key for '%s' found via WKD\n", addrspec);
586 /* Fixme: Check that the key contains the user id. */
589 case GPG_ERR_NO_DATA: /* No such key. */
591 log_info ("public key for '%s' NOT found via WKD\n", addrspec);
592 err = gpg_error (GPG_ERR_NO_PUBKEY);
593 log_inc_errorcount ();
596 case GPG_ERR_UNKNOWN_HOST:
598 log_info ("error looking up '%s' via WKD: %s\n",
599 addrspec, gpg_strerror (err));
600 err = gpg_error (GPG_ERR_NOT_SUPPORTED);
604 log_error ("error looking up '%s' via WKD: %s\n",
605 addrspec, gpg_strerror (err));
612 /* Look closer at the key. */
613 err = wks_list_key (key, &fpr, &mboxes);
616 log_error ("error parsing key: %s\n",
617 err? gpg_strerror (err) : "no fingerprint found");
618 err = gpg_error (GPG_ERR_NO_PUBKEY);
623 log_info ("fingerprint: %s\n", fpr);
625 for (sl = mboxes; sl; sl = sl->next)
627 if (!strcmp (sl->d, addrspec))
630 log_info (" addr-spec: %s\n", sl->d);
634 log_error ("public key for '%s' has no user id with the mail address\n",
636 err = gpg_error (GPG_ERR_CERT_REVOKED);
641 free_strlist (mboxes);
649 /* Locate the key by fingerprint and userid and send a publication
652 command_send (const char *fingerprint, char *userid)
655 KEYDB_SEARCH_DESC desc;
656 char *addrspec = NULL;
657 estream_t key = NULL;
658 estream_t keyenc = NULL;
659 char *submission_to = NULL;
660 mime_maker_t mime = NULL;
661 struct policy_flags_s policy;
663 memset (&policy, 0, sizeof policy);
665 if (classify_user_id (fingerprint, &desc, 1)
666 || !(desc.mode == KEYDB_SEARCH_MODE_FPR
667 || desc.mode == KEYDB_SEARCH_MODE_FPR20))
669 log_error (_("\"%s\" is not a fingerprint\n"), fingerprint);
670 err = gpg_error (GPG_ERR_INV_NAME);
673 addrspec = mailbox_from_userid (userid);
676 log_error (_("\"%s\" is not a proper mail address\n"), userid);
677 err = gpg_error (GPG_ERR_INV_USER_ID);
680 err = get_key (&key, fingerprint, addrspec);
684 /* Get the submission address. */
685 if (fake_submission_addr)
687 submission_to = xstrdup (fake_submission_addr);
691 err = wkd_get_submission_address (addrspec, &submission_to);
694 char *domain = strchr (addrspec, '@');
697 log_error (_("looking up WKS submission address for %s: %s\n"),
698 domain ? domain : addrspec, gpg_strerror (err));
699 if (gpg_err_code (err) == GPG_ERR_NO_DATA)
700 log_error (_("this domain probably doesn't support WKS.\n"));
703 log_info ("submitting request to '%s'\n", submission_to);
705 /* Get the policy flags. */
706 if (!fake_submission_addr)
710 err = wkd_get_policy_flags (addrspec, &mbuf);
711 if (err && gpg_err_code (err) != GPG_ERR_NO_DATA)
713 log_error ("error reading policy flags for '%s': %s\n",
714 submission_to, gpg_strerror (err));
719 err = wks_parse_policy (&policy, mbuf, 1);
726 if (policy.auth_submit)
727 log_info ("no confirmation required for '%s'\n", addrspec);
729 /* Encrypt the key part. */
731 err = encrypt_response (&keyenc, key, submission_to, fingerprint);
739 err = mime_maker_new (&mime, NULL);
742 err = mime_maker_add_header (mime, "From", addrspec);
745 err = mime_maker_add_header (mime, "To", submission_to);
748 err = mime_maker_add_header (mime, "Subject", "Key publishing request");
752 /* Tell server that we support draft version 3. */
753 err = mime_maker_add_header (mime, "Wks-Draft-Version", "3");
757 err = mime_maker_add_header (mime, "Content-Type",
758 "multipart/encrypted; "
759 "protocol=\"application/pgp-encrypted\"");
762 err = mime_maker_add_container (mime);
766 err = mime_maker_add_header (mime, "Content-Type",
767 "application/pgp-encrypted");
770 err = mime_maker_add_body (mime, "Version: 1\n");
773 err = mime_maker_add_header (mime, "Content-Type",
774 "application/octet-stream");
778 err = mime_maker_add_stream (mime, &keyenc);
782 err = wks_send_mime (mime);
785 mime_maker_release (mime);
786 xfree (submission_to);
796 encrypt_response_status_cb (void *opaque, const char *keyword, char *args)
798 gpg_error_t *failure = opaque;
802 log_debug ("gpg status: %s %s\n", keyword, args);
804 if (!strcmp (keyword, "FAILURE"))
806 if (split_fields (args, fields, DIM (fields)) >= 2
807 && !strcmp (fields[0], "encrypt"))
808 *failure = strtoul (fields[1], NULL, 10);
814 /* Encrypt the INPUT stream to a new stream which is stored at success
815 * at R_OUTPUT. Encryption is done for ADDRSPEC and for FINGERPRINT
816 * (so that the sent message may later be inspected by the user). We
817 * currently retrieve that key from the WKD, DANE, or from "local".
818 * "local" is last to prefer the latest key version but use a local
819 * copy in case we are working offline. It might be useful for the
820 * server to send the fingerprint of its encryption key - or even the
821 * entire key back. */
823 encrypt_response (estream_t *r_output, estream_t input, const char *addrspec,
824 const char *fingerprint)
830 gpg_error_t gpg_err = 0;
834 output = es_fopenmem (0, "w+b");
837 err = gpg_error_from_syserror ();
838 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
842 ccparray_init (&ccp, 0);
844 ccparray_put (&ccp, "--no-options");
846 ccparray_put (&ccp, "--quiet");
847 else if (opt.verbose > 1)
848 ccparray_put (&ccp, "--verbose");
849 ccparray_put (&ccp, "--batch");
850 ccparray_put (&ccp, "--status-fd=2");
851 ccparray_put (&ccp, "--always-trust");
852 ccparray_put (&ccp, "--armor");
853 if (fake_submission_addr)
854 ccparray_put (&ccp, "--auto-key-locate=clear,local");
856 ccparray_put (&ccp, "--auto-key-locate=clear,wkd,dane,local");
857 ccparray_put (&ccp, "--recipient");
858 ccparray_put (&ccp, addrspec);
859 ccparray_put (&ccp, "--recipient");
860 ccparray_put (&ccp, fingerprint);
861 ccparray_put (&ccp, "--encrypt");
862 ccparray_put (&ccp, "--");
864 ccparray_put (&ccp, NULL);
865 argv = ccparray_get (&ccp, NULL);
868 err = gpg_error_from_syserror ();
871 err = gnupg_exec_tool_stream (opt.gpg_program, argv, input,
873 encrypt_response_status_cb, &gpg_err);
878 log_error ("encryption failed: %s\n", gpg_strerror (err));
894 send_confirmation_response (const char *sender, const char *address,
895 const char *nonce, int encrypt,
896 const char *fingerprint)
899 estream_t body = NULL;
900 estream_t bodyenc = NULL;
901 mime_maker_t mime = NULL;
903 body = es_fopenmem (0, "w+b");
906 err = gpg_error_from_syserror ();
907 log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
911 /* It is fine to use 8 bit encoding because that is encrypted and
912 * only our client will see it. */
915 es_fputs ("Content-Type: application/vnd.gnupg.wks\n"
916 "Content-Transfer-Encoding: 8bit\n"
921 es_fprintf (body, ("type: confirmation-response\n"
932 err = encrypt_response (&bodyenc, body, sender, fingerprint);
939 err = mime_maker_new (&mime, NULL);
942 err = mime_maker_add_header (mime, "From", address);
945 err = mime_maker_add_header (mime, "To", sender);
948 err = mime_maker_add_header (mime, "Subject", "Key publication confirmation");
954 err = mime_maker_add_header (mime, "Content-Type",
955 "multipart/encrypted; "
956 "protocol=\"application/pgp-encrypted\"");
959 err = mime_maker_add_container (mime);
963 err = mime_maker_add_header (mime, "Content-Type",
964 "application/pgp-encrypted");
967 err = mime_maker_add_body (mime, "Version: 1\n");
970 err = mime_maker_add_header (mime, "Content-Type",
971 "application/octet-stream");
975 err = mime_maker_add_stream (mime, &bodyenc);
981 err = mime_maker_add_header (mime, "Content-Type",
982 "application/vnd.gnupg.wks");
985 err = mime_maker_add_stream (mime, &body);
990 err = wks_send_mime (mime);
993 mime_maker_release (mime);
1000 /* Reply to a confirmation request. The MSG has already been
1001 * decrypted and we only need to send the nonce back. */
1003 process_confirmation_request (estream_t msg)
1008 const char *value, *sender, *address, *fingerprint, *nonce;
1010 err = nvc_parse (&nvc, NULL, msg);
1013 log_error ("parsing the WKS message failed: %s\n", gpg_strerror (err));
1019 log_debug ("request follows:\n");
1020 nvc_write (nvc, log_get_stream ());
1023 /* Check that this is a confirmation request. */
1024 if (!((item = nvc_lookup (nvc, "type:")) && (value = nve_value (item))
1025 && !strcmp (value, "confirmation-request")))
1028 log_error ("received unexpected wks message '%s'\n", value);
1030 log_error ("received invalid wks message: %s\n", "'type' missing");
1031 err = gpg_error (GPG_ERR_UNEXPECTED_MSG);
1035 /* Get the fingerprint. */
1036 if (!((item = nvc_lookup (nvc, "fingerprint:"))
1037 && (value = nve_value (item))
1038 && strlen (value) >= 40))
1040 log_error ("received invalid wks message: %s\n",
1041 "'fingerprint' missing or invalid");
1042 err = gpg_error (GPG_ERR_INV_DATA);
1045 fingerprint = value;
1047 /* FIXME: Check that the fingerprint matches the key used to decrypt the
1050 /* Get the address. */
1051 if (!((item = nvc_lookup (nvc, "address:")) && (value = nve_value (item))
1052 && is_valid_mailbox (value)))
1054 log_error ("received invalid wks message: %s\n",
1055 "'address' missing or invalid");
1056 err = gpg_error (GPG_ERR_INV_DATA);
1060 /* FIXME: Check that the "address" matches the User ID we want to
1061 * publish. Also get the "fingerprint" and compare that to our to
1062 * be published key. Further we should make sure that we actually
1063 * decrypted using that fingerprint (which is a bit problematic if
1064 * --read is used). */
1066 /* Get the sender. */
1067 if (!((item = nvc_lookup (nvc, "sender:")) && (value = nve_value (item))
1068 && is_valid_mailbox (value)))
1070 log_error ("received invalid wks message: %s\n",
1071 "'sender' missing or invalid");
1072 err = gpg_error (GPG_ERR_INV_DATA);
1076 /* FIXME: Check that the "sender" matches the From: address. */
1078 /* Get the nonce. */
1079 if (!((item = nvc_lookup (nvc, "nonce:")) && (value = nve_value (item))
1080 && strlen (value) > 16))
1082 log_error ("received invalid wks message: %s\n",
1083 "'nonce' missing or too short");
1084 err = gpg_error (GPG_ERR_INV_DATA);
1089 /* Send the confirmation. If no key was found, try again without
1091 err = send_confirmation_response (sender, address, nonce, 1, fingerprint);
1092 if (gpg_err_code (err) == GPG_ERR_NO_PUBKEY)
1094 log_info ("no encryption key found - sending response in the clear\n");
1095 err = send_confirmation_response (sender, address, nonce, 0, NULL);
1104 /* Read a confirmation request and decrypt it if needed. This
1105 * function may not be used with a mail or MIME message but only with
1106 * the actual encrypted or plaintext WKS data. */
1108 read_confirmation_request (estream_t msg)
1112 estream_t plaintext = NULL;
1114 /* We take a really simple approach to check whether MSG is
1115 * encrypted: We know that an encrypted message is always armored
1116 * and thus starts with a few dashes. It is even sufficient to
1117 * check for a single dash, because that can never be a proper first
1118 * WKS data octet. We need to skip leading spaces, though. */
1119 while ((c = es_fgetc (msg)) == ' ' || c == '\t' || c == '\r' || c == '\n')
1123 log_error ("can't process an empty message\n");
1124 return gpg_error (GPG_ERR_INV_DATA);
1126 if (es_ungetc (c, msg) != c)
1128 log_error ("error ungetting octet from message\n");
1129 return gpg_error (GPG_ERR_INTERNAL);
1133 err = process_confirmation_request (msg);
1136 err = decrypt_stream (&plaintext, msg);
1138 log_error ("decryption failed: %s\n", gpg_strerror (err));
1140 err = process_confirmation_request (plaintext);
1143 es_fclose (plaintext);
1148 /* Called from the MIME receiver to process the plain text data in MSG. */
1150 command_receive_cb (void *opaque, const char *mediatype,
1151 estream_t msg, unsigned int flags)
1158 if (!strcmp (mediatype, "application/vnd.gnupg.wks"))
1159 err = read_confirmation_request (msg);
1162 log_info ("ignoring unexpected message of type '%s'\n", mediatype);
1163 err = gpg_error (GPG_ERR_UNEXPECTED_MSG);