NeoMutt  2025-12-11-949-g4870ee
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
pgp.c
Go to the documentation of this file.
1
24
34
35#include "config.h"
36#include <stdbool.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <sys/types.h>
41#include <unistd.h>
42#include "mutt/lib.h"
43#include "address/lib.h"
44#include "config/lib.h"
45#include "email/lib.h"
46#include "core/lib.h"
47#include "gui/lib.h"
48#include "mutt.h"
49#include "lib.h"
50#include "attach/lib.h"
51#include "editor/lib.h"
52#include "history/lib.h"
53#include "hooks/lib.h"
54#include "question/lib.h"
55#include "send/lib.h"
56#include "crypt.h"
57#include "cryptglue.h"
58#include "globals.h"
59#include "module_data.h"
60#include "pgpinvoke.h"
61#include "pgpkey.h"
62#include "pgpmicalg.h"
63#ifdef CRYPT_BACKEND_CLASSIC_PGP
64#include "pgp.h"
65#include "pgplib.h"
66#endif
67
72{
74 memset(mod_data->pgp_pass, 0, sizeof(mod_data->pgp_pass));
75 mod_data->pgp_exptime = 0;
76}
77
82{
85 {
86 *mod_data->pgp_pass = '\0';
87 return true; /* handled by gpg-agent */
88 }
89
90 if (mutt_date_now() < mod_data->pgp_exptime)
91 {
92 /* Use cached copy. */
93 return true;
94 }
95
97
98 struct Buffer *buf = buf_pool_get();
99 const int rc = mw_get_field(_("Enter PGP passphrase:"), buf,
101 mutt_str_copy(mod_data->pgp_pass, buf_string(buf), sizeof(mod_data->pgp_pass));
102 buf_pool_release(&buf);
103
104 if (rc == 0)
105 {
106 const long c_pgp_timeout = cs_subset_long(NeoMutt->sub, "pgp_timeout");
107 mod_data->pgp_exptime = mutt_date_add_timeout(mutt_date_now(), c_pgp_timeout);
108 return true;
109 }
110 else
111 {
112 mod_data->pgp_exptime = 0;
113 }
114
115 return false;
116}
117
125{
126 char *tty = NULL;
127
128 /* GnuPG 2.1 no longer exports GPG_AGENT_INFO */
129 const bool c_pgp_use_gpg_agent = cs_subset_bool(NeoMutt->sub, "pgp_use_gpg_agent");
130 if (!c_pgp_use_gpg_agent)
131 return false;
132
133 tty = ttyname(0);
134 if (tty)
135 {
136 setenv("GPG_TTY", tty, 0);
137 envlist_set(&NeoMutt->env, "GPG_TTY", tty, false);
138 }
139
140 return true;
141}
142
148static struct PgpKeyInfo *key_parent(struct PgpKeyInfo *k)
149{
150 const bool c_pgp_ignore_subkeys = cs_subset_bool(NeoMutt->sub, "pgp_ignore_subkeys");
151 if ((k->flags & KEYFLAG_SUBKEY) && k->parent && c_pgp_ignore_subkeys)
152 k = k->parent;
153
154 return k;
155}
156
163{
164 k = key_parent(k);
165
166 return k->keyid;
167}
168
175{
176 k = key_parent(k);
177
178 return k->keyid + 8;
179}
180
189{
190 const bool c_pgp_long_ids = cs_subset_bool(NeoMutt->sub, "pgp_long_ids");
191 if (c_pgp_long_ids)
192 return k->keyid;
193 return k->keyid + 8;
194}
195
201char *pgp_keyid(struct PgpKeyInfo *k)
202{
203 k = key_parent(k);
204
205 return pgp_this_keyid(k);
206}
207
213static char *pgp_fingerprint(struct PgpKeyInfo *k)
214{
215 k = key_parent(k);
216
217 return k->fingerprint;
218}
219
232{
233 char *fingerprint = pgp_fingerprint(k);
235}
236
237/* ----------------------------------------------------------------------------
238 * Routines for handing PGP input.
239 */
240
248static int pgp_copy_checksig(FILE *fp_in, FILE *fp_out)
249{
250 if (!fp_in || !fp_out)
251 return -1;
252
253 int rc = -1;
254
255 const struct Regex *c_pgp_good_sign = cs_subset_regex(NeoMutt->sub, "pgp_good_sign");
256 if (c_pgp_good_sign && c_pgp_good_sign->regex)
257 {
258 char *line = NULL;
259 size_t linelen;
260
261 while ((line = mutt_file_read_line(line, &linelen, fp_in, NULL, MUTT_RL_NONE)))
262 {
263 if (mutt_regex_match(c_pgp_good_sign, line))
264 {
265 mutt_debug(LL_DEBUG2, "\"%s\" matches regex\n", line);
266 rc = 0;
267 }
268 else
269 {
270 mutt_debug(LL_DEBUG2, "\"%s\" doesn't match regex\n", line);
271 }
272
273 if (mutt_strn_equal(line, "[GNUPG:] ", 9))
274 continue;
275 fputs(line, fp_out);
276 fputc('\n', fp_out);
277 }
278 FREE(&line);
279 }
280 else
281 {
282 mutt_debug(LL_DEBUG2, "No pattern\n");
283 mutt_file_copy_stream(fp_in, fp_out);
284 rc = 1;
285 }
286
287 return rc;
288}
289
301{
302 int rc = -1;
303
304 const struct Regex *c_pgp_decryption_okay = cs_subset_regex(NeoMutt->sub, "pgp_decryption_okay");
305 if (c_pgp_decryption_okay && c_pgp_decryption_okay->regex)
306 {
307 char *line = NULL;
308 size_t linelen;
309
310 while ((line = mutt_file_read_line(line, &linelen, fp_in, NULL, MUTT_RL_NONE)))
311 {
312 if (mutt_regex_match(c_pgp_decryption_okay, line))
313 {
314 mutt_debug(LL_DEBUG2, "\"%s\" matches regex\n", line);
315 rc = 0;
316 break;
317 }
318 else
319 {
320 mutt_debug(LL_DEBUG2, "\"%s\" doesn't match regex\n", line);
321 }
322 }
323 FREE(&line);
324 }
325 else
326 {
327 mutt_debug(LL_DEBUG2, "No pattern\n");
328 rc = 1;
329 }
330
331 return rc;
332}
333
354static int pgp_check_decryption_okay(FILE *fp_in)
355{
356 int rc = -1;
357 char *line = NULL, *s = NULL;
358 size_t linelen;
359 int inside_decrypt = 0;
360
361 const bool c_pgp_check_gpg_decrypt_status_fd = cs_subset_bool(NeoMutt->sub, "pgp_check_gpg_decrypt_status_fd");
362 if (!c_pgp_check_gpg_decrypt_status_fd)
364
365 while ((line = mutt_file_read_line(line, &linelen, fp_in, NULL, MUTT_RL_NONE)))
366 {
367 size_t plen = mutt_str_startswith(line, "[GNUPG:] ");
368 if (plen == 0)
369 continue;
370 s = line + plen;
371 mutt_debug(LL_DEBUG2, "checking \"%s\"\n", line);
372 if (mutt_str_startswith(s, "BEGIN_DECRYPTION"))
373 {
374 inside_decrypt = 1;
375 }
376 else if (mutt_str_startswith(s, "END_DECRYPTION"))
377 {
378 inside_decrypt = 0;
379 }
380 else if (mutt_str_startswith(s, "PLAINTEXT"))
381 {
382 if (!inside_decrypt)
383 {
384 mutt_debug(LL_DEBUG2, " PLAINTEXT encountered outside of DECRYPTION\n");
385 rc = -2;
386 break;
387 }
388 }
389 else if (mutt_str_startswith(s, "DECRYPTION_FAILED"))
390 {
391 mutt_debug(LL_DEBUG2, " DECRYPTION_FAILED encountered. Failure\n");
392 rc = -3;
393 break;
394 }
395 else if (mutt_str_startswith(s, "DECRYPTION_OKAY"))
396 {
397 /* Don't break out because we still have to check for
398 * PLAINTEXT outside of the decryption boundaries. */
399 mutt_debug(LL_DEBUG2, " DECRYPTION_OKAY encountered\n");
400 rc = 0;
401 }
402 }
403 FREE(&line);
404
405 return rc;
406}
407
421static void pgp_copy_clearsigned(FILE *fp_in, struct State *state, char *charset)
422{
423 char buf[8192] = { 0 };
424 bool complete, armor_header;
425
426 rewind(fp_in);
427
428 /* fromcode comes from the MIME Content-Type charset label. It might
429 * be a wrong label, so we want the ability to do corrections via
430 * charset-hooks. Therefore we set flags to MUTT_ICONV_HOOK_FROM. */
431 struct FgetConv *fc = mutt_ch_fgetconv_open(fp_in, charset, cc_charset(), MUTT_ICONV_HOOK_FROM);
432
433 for (complete = true, armor_header = true;
434 mutt_ch_fgetconvs(buf, sizeof(buf), fc); complete = (strchr(buf, '\n')))
435 {
436 if (!complete)
437 {
438 if (!armor_header)
439 state_puts(state, buf);
440 continue;
441 }
442
443 if (mutt_str_equal(buf, "-----BEGIN PGP SIGNATURE-----\n"))
444 break;
445
446 if (armor_header)
447 {
448 char *p = mutt_str_skip_whitespace(buf);
449 if (*p == '\0')
450 armor_header = false;
451 continue;
452 }
453
454 if (state->prefix)
455 state_puts(state, state->prefix);
456
457 if ((buf[0] == '-') && (buf[1] == ' '))
458 state_puts(state, buf + 2);
459 else
460 state_puts(state, buf);
461 }
462
464}
465
469int pgp_class_application_handler(struct Body *b, struct State *state)
470{
472 bool could_not_decrypt = false;
473 int decrypt_okay_rc = 0;
474 int needpass = -1;
475 bool pgp_keyblock = false;
476 bool clearsign = false;
477 int rc = -1;
478 int c = 1;
479 long bytes;
480 LOFF_T last_pos, offset;
481 char buf[8192] = { 0 };
482 FILE *fp_pgp_out = NULL, *fp_pgp_in = NULL, *fp_pgp_err = NULL;
483 FILE *fp_tmp = NULL;
484 pid_t pid;
485 struct Buffer *tempfile = buf_pool_get();
486
487 bool maybe_goodsig = true;
488 bool have_any_sigs = false;
489
490 char *gpgcharset = NULL;
491 char body_charset[256] = { 0 };
492 mutt_body_get_charset(b, body_charset, sizeof(body_charset));
493
494 if (!mutt_file_seek(state->fp_in, b->offset, SEEK_SET))
495 {
496 return -1;
497 }
498 last_pos = b->offset;
499
500 for (bytes = b->length; bytes > 0;)
501 {
502 if (!fgets(buf, sizeof(buf), state->fp_in))
503 break;
504
505 offset = ftello(state->fp_in);
506 bytes -= (offset - last_pos); /* don't rely on mutt_str_len(buf) */
507 last_pos = offset;
508
509 size_t plen = mutt_str_startswith(buf, "-----BEGIN PGP ");
510 if (plen != 0)
511 {
512 needpass = false;
513 clearsign = false;
514 could_not_decrypt = false;
515 decrypt_okay_rc = 0;
516
517 if (mutt_str_startswith(buf + plen, "MESSAGE-----\n"))
518 {
519 needpass = 1;
520 }
521 else if (mutt_str_startswith(buf + plen, "SIGNED MESSAGE-----\n"))
522 {
523 clearsign = true;
524 }
525 else if (mutt_str_startswith(buf + plen, "PUBLIC KEY BLOCK-----\n"))
526 {
527 pgp_keyblock = true;
528 }
529 else
530 {
531 /* XXX we may wish to recode here */
532 if (state->prefix)
533 state_puts(state, state->prefix);
534 state_puts(state, buf);
535 continue;
536 }
537
538 have_any_sigs = have_any_sigs || (clearsign && (state->flags & STATE_VERIFY));
539
540 /* Copy PGP material to temporary file */
541 buf_mktemp(tempfile);
542 fp_tmp = mutt_file_fopen(buf_string(tempfile), "w+");
543 if (!fp_tmp)
544 {
545 mutt_perror("%s", buf_string(tempfile));
546 FREE(&gpgcharset);
547 goto out;
548 }
549
550 fputs(buf, fp_tmp);
551 while ((bytes > 0) && fgets(buf, sizeof(buf) - 1, state->fp_in))
552 {
553 offset = ftello(state->fp_in);
554 bytes -= (offset - last_pos); /* don't rely on mutt_str_len(buf) */
555 last_pos = offset;
556
557 fputs(buf, fp_tmp);
558
559 if ((needpass && mutt_str_equal("-----END PGP MESSAGE-----\n", buf)) ||
560 (!needpass && (mutt_str_equal("-----END PGP SIGNATURE-----\n", buf) ||
561 mutt_str_equal("-----END PGP PUBLIC KEY BLOCK-----\n", buf))))
562 {
563 break;
564 }
565 /* remember optional Charset: armor header as defined by RFC4880 */
566 if (mutt_str_startswith(buf, "Charset: "))
567 {
568 size_t l = 0;
569 FREE(&gpgcharset);
570 gpgcharset = mutt_str_dup(buf + 9);
571 l = mutt_str_len(gpgcharset);
572 if ((l > 0) && (gpgcharset[l - 1] == '\n'))
573 gpgcharset[l - 1] = 0;
574 if (!mutt_ch_check_charset(gpgcharset, false))
575 mutt_str_replace(&gpgcharset, "UTF-8");
576 }
577 }
578
579 /* leave fp_tmp open in case we still need it - but flush it! */
580 fflush(fp_tmp);
581
582 /* Invoke PGP if needed */
583 if (!clearsign || (state->flags & STATE_VERIFY))
584 {
585 fp_pgp_out = mutt_file_mkstemp();
586 if (!fp_pgp_out)
587 {
588 mutt_perror(_("Can't create temporary file"));
589 goto out;
590 }
591
592 fp_pgp_err = mutt_file_mkstemp();
593 if (!fp_pgp_err)
594 {
595 mutt_perror(_("Can't create temporary file"));
596 goto out;
597 }
598
599 pid = pgp_invoke_decode(&fp_pgp_in, NULL, NULL, -1, fileno(fp_pgp_out),
600 fileno(fp_pgp_err), buf_string(tempfile),
601 (needpass != 0));
602 if (pid == -1)
603 {
604 mutt_file_fclose(&fp_pgp_out);
605 maybe_goodsig = false;
606 fp_pgp_in = NULL;
607 state_attach_puts(state, _("[-- Error: unable to create PGP subprocess --]\n"));
608 }
609 else /* PGP started successfully */
610 {
611 if (needpass)
612 {
615 if (pgp_use_gpg_agent())
616 *mod_data->pgp_pass = '\0';
617 fprintf(fp_pgp_in, "%s\n", mod_data->pgp_pass);
618 }
619
620 mutt_file_fclose(&fp_pgp_in);
621
622 int wait_filter_rc = filter_wait(pid);
623
624 fflush(fp_pgp_err);
625 /* If we are expecting an encrypted message, verify status fd output.
626 * Note that BEGIN PGP MESSAGE does not guarantee the content is encrypted,
627 * so we need to be more selective about the value of decrypt_okay_rc.
628 *
629 * -3 indicates we actively found a DECRYPTION_FAILED.
630 * -2 and -1 indicate part or all of the content was plaintext. */
631 if (needpass)
632 {
633 rewind(fp_pgp_err);
634 decrypt_okay_rc = pgp_check_decryption_okay(fp_pgp_err);
635 if (decrypt_okay_rc <= -3)
636 mutt_file_fclose(&fp_pgp_out);
637 }
638
639 if (state->flags & STATE_DISPLAY)
640 {
641 rewind(fp_pgp_err);
642 crypt_current_time(state, "PGP");
643 int checksig_rc = pgp_copy_checksig(fp_pgp_err, state->fp_out);
644
645 if (checksig_rc == 0)
646 have_any_sigs = true;
647 /* Sig is bad if
648 * gpg_good_sign-pattern did not match || pgp_decode_command returned not 0
649 * Sig _is_ correct if
650 * gpg_good_sign="" && pgp_decode_command returned 0 */
651 if (checksig_rc == -1 || (wait_filter_rc != 0))
652 maybe_goodsig = false;
653
654 state_attach_puts(state, _("[-- End of PGP output --]\n\n"));
655 }
656 if (pgp_use_gpg_agent())
657 {
659 }
660 }
661
662 /* treat empty result as sign of failure */
663 /* TODO: maybe on failure neomutt should include the original undecoded text. */
664 if (fp_pgp_out)
665 {
666 rewind(fp_pgp_out);
667 c = fgetc(fp_pgp_out);
668 ungetc(c, fp_pgp_out);
669 }
670 if (!clearsign && (!fp_pgp_out || (c == EOF)))
671 {
672 could_not_decrypt = true;
674 }
675
676 if ((could_not_decrypt || (decrypt_okay_rc <= -3)) && !(state->flags & STATE_DISPLAY))
677 {
678 mutt_error(_("Could not decrypt PGP message"));
679 goto out;
680 }
681 }
682
683 /* Now, copy cleartext to the screen. */
684 if (state->flags & STATE_DISPLAY)
685 {
686 if (needpass)
687 state_attach_puts(state, _("[-- BEGIN PGP MESSAGE --]\n\n"));
688 else if (pgp_keyblock)
689 state_attach_puts(state, _("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"));
690 else
691 state_attach_puts(state, _("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"));
692 }
693
694 if (clearsign)
695 {
696 rewind(fp_tmp);
697 pgp_copy_clearsigned(fp_tmp, state, body_charset);
698 }
699 else if (fp_pgp_out)
700 {
701 struct FgetConv *fc = NULL;
702 int ch;
703 char *expected_charset = (gpgcharset && *gpgcharset) ? gpgcharset : "utf-8";
704
705 mutt_debug(LL_DEBUG3, "pgp: recoding inline from [%s] to [%s]\n",
706 expected_charset, cc_charset());
707
708 rewind(fp_pgp_out);
709 state_set_prefix(state);
710 fc = mutt_ch_fgetconv_open(fp_pgp_out, expected_charset, cc_charset(),
712 while ((ch = mutt_ch_fgetconv(fc)) != EOF)
713 state_prefix_putc(state, ch);
715 }
716
717 /* Multiple PGP blocks can exist, so these need to be closed and
718 * unlinked inside the loop. */
719 mutt_file_fclose(&fp_tmp);
720 mutt_file_unlink(buf_string(tempfile));
721 mutt_file_fclose(&fp_pgp_out);
722 mutt_file_fclose(&fp_pgp_err);
723
724 if (state->flags & STATE_DISPLAY)
725 {
726 state_putc(state, '\n');
727 if (needpass)
728 {
729 state_attach_puts(state, _("[-- END PGP MESSAGE --]\n"));
730 if (could_not_decrypt || (decrypt_okay_rc <= -3))
731 {
732 mutt_error(_("Could not decrypt PGP message"));
733 }
734 else if (decrypt_okay_rc < 0)
735 {
736 /* L10N: You will see this error message if (1) you are decrypting
737 (not encrypting) something and (2) it is a plaintext. So the
738 message does not mean "You failed to encrypt the message." */
739 mutt_error(_("PGP message is not encrypted"));
740 }
741 else
742 {
743 mutt_message(_("PGP message successfully decrypted"));
744 }
745 }
746 else if (pgp_keyblock)
747 {
748 state_attach_puts(state, _("[-- END PGP PUBLIC KEY BLOCK --]\n"));
749 }
750 else
751 {
752 state_attach_puts(state, _("[-- END PGP SIGNED MESSAGE --]\n"));
753 }
754 }
755 }
756 else
757 {
758 /* A traditional PGP part may mix signed and unsigned content */
759 /* XXX we may wish to recode here */
760 if (state->prefix)
761 state_puts(state, state->prefix);
762 state_puts(state, buf);
763 }
764 }
765
766 rc = 0;
767
768out:
769 b->goodsig = (maybe_goodsig && have_any_sigs);
770
771 if (fp_tmp)
772 {
773 mutt_file_fclose(&fp_tmp);
774 mutt_file_unlink(buf_string(tempfile));
775 }
776 mutt_file_fclose(&fp_pgp_out);
777 mutt_file_fclose(&fp_pgp_err);
778
779 buf_pool_release(&tempfile);
780
781 FREE(&gpgcharset);
782
783 if (needpass == -1)
784 {
785 state_attach_puts(state, _("[-- Error: could not find beginning of PGP message --]\n\n"));
786 return -1;
787 }
788
789 return rc;
790}
791
799static bool pgp_check_traditional_one_body(FILE *fp, struct Body *b)
800{
801 struct Buffer *tempfile = NULL;
802 char buf[8192] = { 0 };
803 bool rc = false;
804
805 bool sgn = false;
806 bool enc = false;
807 bool key = false;
808
809 if (b->type != TYPE_TEXT)
810 goto cleanup;
811
812 tempfile = buf_pool_get();
813 buf_mktemp(tempfile);
815 {
816 unlink(buf_string(tempfile));
817 goto cleanup;
818 }
819
820 FILE *fp_tmp = mutt_file_fopen(buf_string(tempfile), "r");
821 if (!fp_tmp)
822 {
823 unlink(buf_string(tempfile));
824 goto cleanup;
825 }
826
827 while (fgets(buf, sizeof(buf), fp_tmp))
828 {
829 size_t plen = mutt_str_startswith(buf, "-----BEGIN PGP ");
830 if (plen != 0)
831 {
832 if (mutt_str_startswith(buf + plen, "MESSAGE-----\n"))
833 enc = true;
834 else if (mutt_str_startswith(buf + plen, "SIGNED MESSAGE-----\n"))
835 sgn = true;
836 else if (mutt_str_startswith(buf + plen, "PUBLIC KEY BLOCK-----\n"))
837 key = true;
838 }
839 }
840 mutt_file_fclose(&fp_tmp);
841 unlink(buf_string(tempfile));
842
843 if (!enc && !sgn && !key)
844 goto cleanup;
845
846 /* fix the content type */
847
848 mutt_param_set(&b->parameter, "format", "fixed");
849 if (enc)
850 mutt_param_set(&b->parameter, "x-action", "pgp-encrypted");
851 else if (sgn)
852 mutt_param_set(&b->parameter, "x-action", "pgp-signed");
853 else if (key)
854 mutt_param_set(&b->parameter, "x-action", "pgp-keys");
855
856 rc = true;
857
858cleanup:
859 buf_pool_release(&tempfile);
860 return rc;
861}
862
866bool pgp_class_check_traditional(FILE *fp, struct Body *b, bool just_one)
867{
868 bool rc = false;
869 int r;
870 for (; b; b = b->next)
871 {
872 if (!just_one && is_multipart(b))
873 {
874 rc = pgp_class_check_traditional(fp, b->parts, false) || rc;
875 }
876 else if (b->type == TYPE_TEXT)
877 {
879 if (r)
880 rc = rc || r;
881 else
882 rc = pgp_check_traditional_one_body(fp, b) || rc;
883 }
884
885 if (just_one)
886 break;
887 }
888
889 return rc;
890}
891
895int pgp_class_verify_one(struct Body *b, struct State *state, const char *tempfile)
896{
897 FILE *fp_pgp_out = NULL;
898 pid_t pid;
899 int badsig = -1;
900 struct Buffer *sigfile = buf_pool_get();
901
902 buf_printf(sigfile, "%s.asc", tempfile);
903
904 FILE *fp_sig = mutt_file_fopen(buf_string(sigfile), "w");
905 if (!fp_sig)
906 {
907 mutt_perror("%s", buf_string(sigfile));
908 goto cleanup;
909 }
910
911 if (!mutt_file_seek(state->fp_in, b->offset, SEEK_SET))
912 {
913 mutt_file_fclose(&fp_sig);
914 goto cleanup;
915 }
916 mutt_file_copy_bytes(state->fp_in, fp_sig, b->length);
917 mutt_file_fclose(&fp_sig);
918
919 FILE *fp_pgp_err = mutt_file_mkstemp();
920 if (!fp_pgp_err)
921 {
922 mutt_perror(_("Can't create temporary file"));
923 unlink(buf_string(sigfile));
924 goto cleanup;
925 }
926
927 crypt_current_time(state, "PGP");
928
929 pid = pgp_invoke_verify(NULL, &fp_pgp_out, NULL, -1, -1, fileno(fp_pgp_err),
930 tempfile, buf_string(sigfile));
931 if (pid != -1)
932 {
933 if (pgp_copy_checksig(fp_pgp_out, state->fp_out) >= 0)
934 badsig = 0;
935
936 mutt_file_fclose(&fp_pgp_out);
937 fflush(fp_pgp_err);
938 rewind(fp_pgp_err);
939
940 if (pgp_copy_checksig(fp_pgp_err, state->fp_out) >= 0)
941 badsig = 0;
942
943 const int rv = filter_wait(pid);
944 if (rv)
945 badsig = -1;
946
947 mutt_debug(LL_DEBUG1, "filter_wait returned %d\n", rv);
948 }
949
950 mutt_file_fclose(&fp_pgp_err);
951
952 state_attach_puts(state, _("[-- End of PGP output --]\n\n"));
953
955
956cleanup:
957 buf_pool_release(&sigfile);
958
959 mutt_debug(LL_DEBUG1, "returning %d\n", badsig);
960 return badsig;
961}
962
968static void pgp_extract_keys_from_attachment(FILE *fp, struct Body *b)
969{
970 struct State state = { 0 };
971 struct Buffer *tempfile = buf_pool_get();
972
973 buf_mktemp(tempfile);
974 FILE *fp_tmp = mutt_file_fopen(buf_string(tempfile), "w");
975 if (!fp_tmp)
976 {
977 mutt_perror("%s", buf_string(tempfile));
978 goto cleanup;
979 }
980
981 state.fp_in = fp;
982 state.fp_out = fp_tmp;
983
984 mutt_body_handler(b, &state);
985
986 mutt_file_fclose(&fp_tmp);
987
990
991 mutt_file_unlink(buf_string(tempfile));
992
993cleanup:
994 buf_pool_release(&tempfile);
995}
996
1001{
1002 if (!fp)
1003 {
1004 mutt_error(_("Internal error. Please submit a bug report."));
1005 return;
1006 }
1007
1008 mutt_endwin();
1009
1010 OptDontHandlePgpKeys = true;
1012 OptDontHandlePgpKeys = false;
1013}
1014
1023static struct Body *pgp_decrypt_part(struct Body *a, struct State *state,
1024 FILE *fp_out, struct Body *p)
1025{
1026 if (!a || !state || !fp_out || !p)
1027 return NULL;
1028
1030 char buf[1024] = { 0 };
1031 FILE *fp_pgp_in = NULL, *fp_pgp_out = NULL, *fp_pgp_tmp = NULL;
1032 struct Body *tattach = NULL;
1033 pid_t pid;
1034 int rv;
1035 struct Buffer *tempfile = buf_pool_get();
1036
1037 FILE *fp_pgp_err = mutt_file_mkstemp();
1038 if (!fp_pgp_err)
1039 {
1040 mutt_perror(_("Can't create temporary file"));
1041 goto cleanup;
1042 }
1043
1044 buf_mktemp(tempfile);
1045 fp_pgp_tmp = mutt_file_fopen(buf_string(tempfile), "w");
1046 if (!fp_pgp_tmp)
1047 {
1048 mutt_perror("%s", buf_string(tempfile));
1049 mutt_file_fclose(&fp_pgp_err);
1050 goto cleanup;
1051 }
1052
1053 /* Position the stream at the beginning of the body, and send the data to
1054 * the temporary file. */
1055
1056 if (!mutt_file_seek(state->fp_in, a->offset, SEEK_SET))
1057 {
1058 mutt_file_fclose(&fp_pgp_tmp);
1059 mutt_file_fclose(&fp_pgp_err);
1060 goto cleanup;
1061 }
1062 mutt_file_copy_bytes(state->fp_in, fp_pgp_tmp, a->length);
1063 mutt_file_fclose(&fp_pgp_tmp);
1064
1065 pid = pgp_invoke_decrypt(&fp_pgp_in, &fp_pgp_out, NULL, -1, -1,
1066 fileno(fp_pgp_err), buf_string(tempfile));
1067 if (pid == -1)
1068 {
1069 mutt_file_fclose(&fp_pgp_err);
1070 unlink(buf_string(tempfile));
1071 if (state->flags & STATE_DISPLAY)
1072 {
1073 state_attach_puts(state, _("[-- Error: could not create a PGP subprocess --]\n\n"));
1074 }
1075 goto cleanup;
1076 }
1077
1078 /* send the PGP passphrase to the subprocess. Never do this if the agent is
1079 * active, because this might lead to a passphrase send as the message. */
1080 if (!pgp_use_gpg_agent())
1081 fputs(mod_data->pgp_pass, fp_pgp_in);
1082 fputc('\n', fp_pgp_in);
1083 mutt_file_fclose(&fp_pgp_in);
1084
1085 /* Read the output from PGP, and make sure to change CRLF to LF, otherwise
1086 * read_mime_header has a hard time parsing the message. */
1087 while (fgets(buf, sizeof(buf) - 1, fp_pgp_out))
1088 {
1089 size_t len = mutt_str_len(buf);
1090 if ((len > 1) && (buf[len - 2] == '\r'))
1091 strcpy(buf + len - 2, "\n");
1092 fputs(buf, fp_out);
1093 }
1094
1095 mutt_file_fclose(&fp_pgp_out);
1096
1097 rv = filter_wait(pid);
1098 const bool c_pgp_use_gpg_agent = cs_subset_bool(NeoMutt->sub, "pgp_use_gpg_agent");
1099 if (c_pgp_use_gpg_agent)
1101
1102 mutt_file_unlink(buf_string(tempfile));
1103
1104 fflush(fp_pgp_err);
1105 rewind(fp_pgp_err);
1106 if (pgp_check_decryption_okay(fp_pgp_err) < 0)
1107 {
1108 mutt_error(_("Decryption failed"));
1110 mutt_file_fclose(&fp_pgp_err);
1111 goto cleanup;
1112 }
1113
1114 if (state->flags & STATE_DISPLAY)
1115 {
1116 rewind(fp_pgp_err);
1117 if ((pgp_copy_checksig(fp_pgp_err, state->fp_out) == 0) && !rv)
1118 p->goodsig = true;
1119 else
1120 p->goodsig = false;
1121 state_attach_puts(state, _("[-- End of PGP output --]\n\n"));
1122 }
1123 mutt_file_fclose(&fp_pgp_err);
1124
1125 fflush(fp_out);
1126 rewind(fp_out);
1127
1128 if (fgetc(fp_out) == EOF)
1129 {
1130 mutt_error(_("Decryption failed"));
1132 goto cleanup;
1133 }
1134
1135 rewind(fp_out);
1136 const long size = mutt_file_get_size_fp(fp_out);
1137 if (size == 0)
1138 {
1139 goto cleanup;
1140 }
1141
1142 tattach = mutt_read_mime_header(fp_out, 0);
1143 if (tattach)
1144 {
1145 /* Need to set the length of this body part. */
1146 tattach->length = size - tattach->offset;
1147
1148 /* See if we need to recurse on this MIME part. */
1149 mutt_parse_part(fp_out, tattach);
1150 }
1151
1152cleanup:
1153 buf_pool_release(&tempfile);
1154 return tattach;
1155}
1156
1160int pgp_class_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
1161{
1162 struct State state = { 0 };
1163 struct Body *p = b;
1164 bool need_decode = false;
1165 LOFF_T saved_offset = 0;
1166 size_t saved_length = 0;
1167 FILE *fp_decoded = NULL;
1168 int rc = 0;
1169
1171 {
1172 b = b->parts->next;
1173 /* Some clients improperly encode the octetstream part. */
1174 if (b->encoding != ENC_7BIT)
1175 need_decode = true;
1176 }
1178 {
1179 b = b->parts->next->next;
1180 need_decode = true;
1181 }
1182 else
1183 {
1184 return -1;
1185 }
1186
1187 state.fp_in = fp_in;
1188
1189 if (need_decode)
1190 {
1191 saved_offset = b->offset;
1192 saved_length = b->length;
1193
1194 fp_decoded = mutt_file_mkstemp();
1195 if (!fp_decoded)
1196 {
1197 mutt_perror(_("Can't create temporary file"));
1198 return -1;
1199 }
1200
1201 if (!mutt_file_seek(state.fp_in, b->offset, SEEK_SET))
1202 {
1203 rc = -1;
1204 goto bail;
1205 }
1206 state.fp_out = fp_decoded;
1207
1208 mutt_decode_attachment(b, &state);
1209
1210 fflush(fp_decoded);
1211 b->length = ftello(fp_decoded);
1212 b->offset = 0;
1213 rewind(fp_decoded);
1214 state.fp_in = fp_decoded;
1215 state.fp_out = 0;
1216 }
1217
1218 *fp_out = mutt_file_mkstemp();
1219 if (!*fp_out)
1220 {
1221 mutt_perror(_("Can't create temporary file"));
1222 rc = -1;
1223 goto bail;
1224 }
1225
1226 *b_dec = pgp_decrypt_part(b, &state, *fp_out, p);
1227 if (!*b_dec)
1228 rc = -1;
1229 rewind(*fp_out);
1230
1231bail:
1232 if (need_decode)
1233 {
1234 b->length = saved_length;
1235 b->offset = saved_offset;
1236 mutt_file_fclose(&fp_decoded);
1237 }
1238
1239 return rc;
1240}
1241
1245int pgp_class_encrypted_handler(struct Body *b, struct State *state)
1246{
1247 FILE *fp_in = NULL;
1248 struct Body *tattach = NULL;
1249 int rc = 0;
1250
1251 FILE *fp_out = mutt_file_mkstemp();
1252 if (!fp_out)
1253 {
1254 mutt_perror(_("Can't create temporary file"));
1255 if (state->flags & STATE_DISPLAY)
1256 {
1257 state_attach_puts(state, _("[-- Error: could not create temporary file --]\n"));
1258 }
1259 return -1;
1260 }
1261
1262 if (state->flags & STATE_DISPLAY)
1263 crypt_current_time(state, "PGP");
1264
1265 tattach = pgp_decrypt_part(b, state, fp_out, b);
1266 if (tattach)
1267 {
1268 if (state->flags & STATE_DISPLAY)
1269 {
1270 state_attach_puts(state, _("[-- The following data is PGP/MIME encrypted --]\n"));
1271 mutt_protected_headers_handler(tattach, state);
1272 }
1273
1274 /* Store any protected headers in the parent so they can be
1275 * accessed for index updates after the handler recursion is done.
1276 * This is done before the handler to prevent a nested encrypted
1277 * handler from freeing the headers. */
1279 b->mime_headers = tattach->mime_headers;
1280 tattach->mime_headers = NULL;
1281
1282 fp_in = state->fp_in;
1283 state->fp_in = fp_out;
1284 rc = mutt_body_handler(tattach, state);
1285 state->fp_in = fp_in;
1286
1287 /* Embedded multipart signed protected headers override the
1288 * encrypted headers. We need to do this after the handler so
1289 * they can be printed in the pager. */
1290 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
1291 {
1293 b->mime_headers = tattach->parts->mime_headers;
1294 tattach->parts->mime_headers = NULL;
1295 }
1296
1297 /* if a multipart/signed is the _only_ sub-part of a
1298 * multipart/encrypted, cache signature verification
1299 * status. */
1300 if (mutt_is_multipart_signed(tattach) && !tattach->next)
1301 b->goodsig |= tattach->goodsig;
1302
1303 if (state->flags & STATE_DISPLAY)
1304 state_attach_puts(state, _("[-- End of PGP/MIME encrypted data --]\n"));
1305
1306 mutt_body_free(&tattach);
1307 /* clear 'Invoking...' message, since there's no error */
1308 mutt_message(_("PGP message successfully decrypted"));
1309 }
1310 else
1311 {
1312 mutt_error(_("Could not decrypt PGP message"));
1313 /* void the passphrase, even if it's not necessarily the problem */
1315 rc = -1;
1316 }
1317
1318 mutt_file_fclose(&fp_out);
1319
1320 return rc;
1321}
1322
1323/* ----------------------------------------------------------------------------
1324 * Routines for sending PGP/MIME messages.
1325 */
1326
1330struct Body *pgp_class_sign_message(struct Body *b, const struct AddressList *from)
1331{
1333 struct Body *b_enc = NULL, *rv = NULL;
1334 char buf[1024] = { 0 };
1335 FILE *fp_pgp_in = NULL, *fp_pgp_out = NULL, *fp_pgp_err = NULL, *fp_signed = NULL;
1336 bool err = false;
1337 bool empty = true;
1338 pid_t pid;
1339 struct Buffer *sigfile = buf_pool_get();
1340 struct Buffer *signedfile = buf_pool_get();
1341
1342 crypt_convert_to_7bit(b); /* Signed data _must_ be in 7-bit format. */
1343
1344 buf_mktemp(sigfile);
1345 FILE *fp_sig = mutt_file_fopen(buf_string(sigfile), "w");
1346 if (!fp_sig)
1347 {
1348 goto cleanup;
1349 }
1350
1351 buf_mktemp(signedfile);
1352 fp_signed = mutt_file_fopen(buf_string(signedfile), "w");
1353 if (!fp_signed)
1354 {
1355 mutt_perror("%s", buf_string(signedfile));
1356 mutt_file_fclose(&fp_sig);
1357 unlink(buf_string(sigfile));
1358 goto cleanup;
1359 }
1360
1361 mutt_write_mime_header(b, fp_signed, NeoMutt->sub);
1362 fputc('\n', fp_signed);
1363 mutt_write_mime_body(b, fp_signed, NeoMutt->sub);
1364 mutt_file_fclose(&fp_signed);
1365
1366 pid = pgp_invoke_sign(&fp_pgp_in, &fp_pgp_out, &fp_pgp_err, -1, -1, -1,
1367 buf_string(signedfile));
1368 if (pid == -1)
1369 {
1370 mutt_perror(_("Can't open PGP subprocess"));
1371 mutt_file_fclose(&fp_sig);
1372 unlink(buf_string(sigfile));
1373 unlink(buf_string(signedfile));
1374 goto cleanup;
1375 }
1376
1377 if (!pgp_use_gpg_agent())
1378 fputs(mod_data->pgp_pass, fp_pgp_in);
1379 fputc('\n', fp_pgp_in);
1380 mutt_file_fclose(&fp_pgp_in);
1381
1382 /* Read back the PGP signature. Also, change MESSAGE=>SIGNATURE as
1383 * recommended for future releases of PGP. */
1384 while (fgets(buf, sizeof(buf) - 1, fp_pgp_out))
1385 {
1386 if (mutt_str_equal("-----BEGIN PGP MESSAGE-----\n", buf))
1387 fputs("-----BEGIN PGP SIGNATURE-----\n", fp_sig);
1388 else if (mutt_str_equal("-----END PGP MESSAGE-----\n", buf))
1389 fputs("-----END PGP SIGNATURE-----\n", fp_sig);
1390 else
1391 fputs(buf, fp_sig);
1392 empty = false; /* got some output, so we're ok */
1393 }
1394
1395 /* check for errors from PGP */
1396 err = false;
1397 while (fgets(buf, sizeof(buf) - 1, fp_pgp_err))
1398 {
1399 err = true;
1400 fputs(buf, stdout);
1401 }
1402
1403 const bool c_pgp_check_exit = cs_subset_bool(NeoMutt->sub, "pgp_check_exit");
1404 if (filter_wait(pid) && c_pgp_check_exit)
1405 empty = true;
1406
1407 mutt_file_fclose(&fp_pgp_err);
1408 mutt_file_fclose(&fp_pgp_out);
1409 unlink(buf_string(signedfile));
1410
1411 if (mutt_file_fclose(&fp_sig) != 0)
1412 {
1413 mutt_perror("fclose");
1414 unlink(buf_string(sigfile));
1415 goto cleanup;
1416 }
1417
1418 if (err)
1420 if (empty)
1421 {
1422 unlink(buf_string(sigfile));
1423 /* most likely error is a bad passphrase, so automatically forget it */
1425 goto cleanup; /* fatal error while signing */
1426 }
1427
1428 b_enc = mutt_body_new();
1429 b_enc->type = TYPE_MULTIPART;
1430 b_enc->subtype = mutt_str_dup("signed");
1431 b_enc->encoding = ENC_7BIT;
1432 b_enc->use_disp = false;
1433 b_enc->disposition = DISP_INLINE;
1434 rv = b_enc;
1435
1437 mutt_param_set(&b_enc->parameter, "protocol", "application/pgp-signature");
1438 mutt_param_set(&b_enc->parameter, "micalg", pgp_micalg(buf_string(sigfile)));
1439
1440 b_enc->parts = b;
1441
1442 b_enc->parts->next = mutt_body_new();
1443 b_enc = b_enc->parts->next;
1444 b_enc->type = TYPE_APPLICATION;
1445 b_enc->subtype = mutt_str_dup("pgp-signature");
1446 b_enc->filename = buf_strdup(sigfile);
1447 b_enc->use_disp = false;
1448 b_enc->disposition = DISP_NONE;
1449 b_enc->encoding = ENC_7BIT;
1450 b_enc->unlink = true; /* ok to remove this file after sending. */
1451 mutt_param_set(&b_enc->parameter, "name", "signature.asc");
1452
1453cleanup:
1454 buf_pool_release(&sigfile);
1455 buf_pool_release(&signedfile);
1456 return rv;
1457}
1458
1462char *pgp_class_find_keys(const struct AddressList *addrlist, bool oppenc_mode)
1463{
1464 struct ListHead crypt_hook_list = STAILQ_HEAD_INITIALIZER(crypt_hook_list);
1465 struct ListNode *crypt_hook = NULL;
1466 const char *keyid = NULL;
1467 char *keylist = NULL;
1468 size_t keylist_size = 0;
1469 size_t keylist_used = 0;
1470 struct Address *p = NULL;
1471 struct PgpKeyInfo *k_info = NULL;
1472 const char *fqdn = mutt_fqdn(true, NeoMutt->sub);
1473 char buf[1024] = { 0 };
1474 bool key_selected;
1475 struct AddressList hookal = TAILQ_HEAD_INITIALIZER(hookal);
1476
1477 struct Address *a = NULL;
1478 const bool c_crypt_confirm_hook = cs_subset_bool(NeoMutt->sub, "crypt_confirm_hook");
1479 /* Iterate through each recipient address to find an encryption key */
1480 TAILQ_FOREACH(a, addrlist, entries)
1481 {
1482 key_selected = false;
1483 /* Check for crypt-hook overrides for this recipient */
1484 mutt_crypt_hook(&crypt_hook_list, a);
1485 crypt_hook = STAILQ_FIRST(&crypt_hook_list);
1486 do
1487 {
1488 p = a;
1489 k_info = NULL;
1490
1491 /* If a crypt-hook provides a key ID, confirm with the user unless
1492 * in opportunistic encryption mode */
1493 if (crypt_hook)
1494 {
1495 keyid = crypt_hook->data;
1496 enum QuadOption ans = MUTT_YES;
1497 if (!oppenc_mode && c_crypt_confirm_hook && isatty(STDIN_FILENO))
1498 {
1499 snprintf(buf, sizeof(buf), _("Use keyID = \"%s\" for %s?"), keyid,
1500 buf_string(p->mailbox));
1501 ans = query_yesorno_help(buf, MUTT_YES, NeoMutt->sub, "crypt_confirm_hook");
1502 }
1503 if (ans == MUTT_YES)
1504 {
1505 if (crypt_is_numerical_keyid(keyid))
1506 {
1507 if (mutt_strn_equal(keyid, "0x", 2))
1508 keyid += 2;
1509 goto bypass_selection; /* you don't see this. */
1510 }
1511
1512 /* check for e-mail address */
1513 mutt_addrlist_clear(&hookal);
1514 if (strchr(keyid, '@') && (mutt_addrlist_parse(&hookal, keyid) != 0))
1515 {
1516 mutt_addrlist_qualify(&hookal, fqdn);
1517 p = TAILQ_FIRST(&hookal);
1518 }
1519 else if (!oppenc_mode)
1520 {
1522 }
1523 }
1524 else if (ans == MUTT_NO)
1525 {
1526 if (key_selected || STAILQ_NEXT(crypt_hook, entries))
1527 {
1528 crypt_hook = STAILQ_NEXT(crypt_hook, entries);
1529 continue;
1530 }
1531 }
1532 else if (ans == MUTT_ABORT)
1533 {
1534 FREE(&keylist);
1535 mutt_addrlist_clear(&hookal);
1536 mutt_list_free(&crypt_hook_list);
1537 return NULL;
1538 }
1539 }
1540
1541 /* If no key found yet, try looking up by address in the keyring */
1542 if (!k_info)
1543 {
1545 k_info = pgp_getkeybyaddr(p, KEYFLAG_CANENCRYPT, PGP_PUBRING, oppenc_mode);
1546 }
1547
1548 /* Last resort: prompt the user to enter a key ID interactively */
1549 if (!k_info && !oppenc_mode && isatty(STDIN_FILENO))
1550 {
1551 snprintf(buf, sizeof(buf), _("Enter keyID for %s: "), buf_string(p->mailbox));
1553 }
1554
1555 if (!k_info)
1556 {
1557 FREE(&keylist);
1558 mutt_addrlist_clear(&hookal);
1559 mutt_list_free(&crypt_hook_list);
1560 return NULL;
1561 }
1562
1563 keyid = pgp_fpr_or_lkeyid(k_info);
1564
1565 bypass_selection:
1566 /* Append the selected key ID to the space-separated keylist string */
1567 keylist_size += mutt_str_len(keyid) + 4;
1568 MUTT_MEM_REALLOC(&keylist, keylist_size, char);
1569 sprintf(keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", keyid);
1570 keylist_used = mutt_str_len(keylist);
1571
1572 key_selected = true;
1573
1574 pgp_key_free(&k_info);
1575 mutt_addrlist_clear(&hookal);
1576
1577 if (crypt_hook)
1578 crypt_hook = STAILQ_NEXT(crypt_hook, entries);
1579
1580 } while (crypt_hook);
1581
1582 mutt_list_free(&crypt_hook_list);
1583 }
1584 return keylist;
1585}
1586
1593struct Body *pgp_class_encrypt_message(struct Body *b, char *keylist, bool sign,
1594 const struct AddressList *from)
1595{
1597 char buf[1024] = { 0 };
1598 FILE *fp_pgp_in = NULL, *fp_tmp = NULL;
1599 struct Body *b_enc = NULL;
1600 bool err = false;
1601 bool empty = false;
1602 pid_t pid;
1603 struct Buffer *tempfile = buf_pool_get();
1604 struct Buffer *pgpinfile = buf_pool_get();
1605
1606 buf_mktemp(tempfile);
1607 FILE *fp_out = mutt_file_fopen(buf_string(tempfile), "w+");
1608 if (!fp_out)
1609 {
1610 mutt_perror("%s", buf_string(tempfile));
1611 goto cleanup;
1612 }
1613
1614 FILE *fp_pgp_err = mutt_file_mkstemp();
1615 if (!fp_pgp_err)
1616 {
1617 mutt_perror(_("Can't create temporary file"));
1618 unlink(buf_string(tempfile));
1619 mutt_file_fclose(&fp_out);
1620 goto cleanup;
1621 }
1622
1623 buf_mktemp(pgpinfile);
1624 fp_tmp = mutt_file_fopen(buf_string(pgpinfile), "w");
1625 if (!fp_tmp)
1626 {
1627 mutt_perror("%s", buf_string(pgpinfile));
1628 unlink(buf_string(tempfile));
1629 mutt_file_fclose(&fp_out);
1630 mutt_file_fclose(&fp_pgp_err);
1631 goto cleanup;
1632 }
1633
1634 if (sign)
1636
1637 mutt_write_mime_header(b, fp_tmp, NeoMutt->sub);
1638 fputc('\n', fp_tmp);
1639 mutt_write_mime_body(b, fp_tmp, NeoMutt->sub);
1640 mutt_file_fclose(&fp_tmp);
1641
1642 pid = pgp_invoke_encrypt(&fp_pgp_in, NULL, NULL, -1, fileno(fp_out),
1643 fileno(fp_pgp_err), buf_string(pgpinfile), keylist, sign);
1644 if (pid == -1)
1645 {
1646 mutt_file_fclose(&fp_out);
1647 mutt_file_fclose(&fp_pgp_err);
1648 unlink(buf_string(pgpinfile));
1649 goto cleanup;
1650 }
1651
1652 if (sign)
1653 {
1654 if (!pgp_use_gpg_agent())
1655 fputs(mod_data->pgp_pass, fp_pgp_in);
1656 fputc('\n', fp_pgp_in);
1657 }
1658 mutt_file_fclose(&fp_pgp_in);
1659
1660 const bool c_pgp_check_exit = cs_subset_bool(NeoMutt->sub, "pgp_check_exit");
1661 if (filter_wait(pid) && c_pgp_check_exit)
1662 empty = true;
1663
1664 unlink(buf_string(pgpinfile));
1665
1666 fflush(fp_out);
1667 rewind(fp_out);
1668 if (!empty)
1669 empty = (fgetc(fp_out) == EOF);
1670 mutt_file_fclose(&fp_out);
1671
1672 fflush(fp_pgp_err);
1673 rewind(fp_pgp_err);
1674 while (fgets(buf, sizeof(buf) - 1, fp_pgp_err))
1675 {
1676 err = true;
1677 fputs(buf, stdout);
1678 }
1679 mutt_file_fclose(&fp_pgp_err);
1680
1681 /* pause if there is any error output from PGP */
1682 if (err)
1684
1685 if (empty)
1686 {
1687 /* fatal error while trying to encrypt message */
1688 if (sign)
1689 pgp_class_void_passphrase(); /* just in case */
1690 unlink(buf_string(tempfile));
1691 goto cleanup;
1692 }
1693
1694 b_enc = mutt_body_new();
1695 b_enc->type = TYPE_MULTIPART;
1696 b_enc->subtype = mutt_str_dup("encrypted");
1697 b_enc->encoding = ENC_7BIT;
1698 b_enc->use_disp = false;
1699 b_enc->disposition = DISP_INLINE;
1700
1702 mutt_param_set(&b_enc->parameter, "protocol", "application/pgp-encrypted");
1703
1704 b_enc->parts = mutt_body_new();
1705 b_enc->parts->type = TYPE_APPLICATION;
1706 b_enc->parts->subtype = mutt_str_dup("pgp-encrypted");
1707 b_enc->parts->encoding = ENC_7BIT;
1708
1709 b_enc->parts->next = mutt_body_new();
1710 b_enc->parts->next->type = TYPE_APPLICATION;
1711 b_enc->parts->next->subtype = mutt_str_dup("octet-stream");
1712 b_enc->parts->next->encoding = ENC_7BIT;
1713 b_enc->parts->next->filename = buf_strdup(tempfile);
1714 b_enc->parts->next->use_disp = true;
1715 b_enc->parts->next->disposition = DISP_ATTACH;
1716 b_enc->parts->next->unlink = true; /* delete after sending the message */
1717 b_enc->parts->next->d_filename = mutt_str_dup("msg.asc"); /* non pgp/mime can save */
1718
1719cleanup:
1720 buf_pool_release(&tempfile);
1721 buf_pool_release(&pgpinfile);
1722 return b_enc;
1723}
1724
1728struct Body *pgp_class_traditional_encryptsign(struct Body *b, SecurityFlags flags, char *keylist)
1729{
1731 struct Body *b_enc = NULL;
1732 char body_charset[256] = { 0 };
1733 const char *from_charset = NULL;
1734 const char *send_charset = NULL;
1735 bool empty = false;
1736 bool err;
1737 char buf[256] = { 0 };
1738 pid_t pid;
1739 struct Buffer *pgpinfile = buf_pool_get();
1740 struct Buffer *pgpoutfile = buf_pool_get();
1741
1742 if (b->type != TYPE_TEXT)
1743 goto cleanup;
1744 if (!mutt_istr_equal(b->subtype, "plain"))
1745 goto cleanup;
1746
1747 FILE *fp_body = mutt_file_fopen(b->filename, "r");
1748 if (!fp_body)
1749 {
1750 mutt_perror("%s", b->filename);
1751 goto cleanup;
1752 }
1753
1754 buf_mktemp(pgpinfile);
1755 FILE *fp_pgp_in = mutt_file_fopen(buf_string(pgpinfile), "w");
1756 if (!fp_pgp_in)
1757 {
1758 mutt_perror("%s", buf_string(pgpinfile));
1759 mutt_file_fclose(&fp_body);
1760 goto cleanup;
1761 }
1762
1763 /* The following code is really correct: If noconv is set,
1764 * b's charset parameter contains the on-disk character set, and
1765 * we have to convert from that to utf-8. If noconv is not set,
1766 * we have to convert from $charset to utf-8. */
1767
1768 mutt_body_get_charset(b, body_charset, sizeof(body_charset));
1769 if (b->noconv)
1770 from_charset = body_charset;
1771 else
1772 from_charset = cc_charset();
1773
1774 if (mutt_ch_is_us_ascii(body_charset))
1775 {
1776 send_charset = "us-ascii";
1777 mutt_file_copy_stream(fp_body, fp_pgp_in);
1778 }
1779 else
1780 {
1781 int c;
1782 struct FgetConv *fc = NULL;
1783
1784 if (flags & SEC_ENCRYPT)
1785 send_charset = "us-ascii";
1786 else
1787 send_charset = "utf-8";
1788
1789 /* fromcode is assumed to be correct: we set flags to 0 */
1790 fc = mutt_ch_fgetconv_open(fp_body, from_charset, "utf-8", MUTT_ICONV_NONE);
1791 while ((c = mutt_ch_fgetconv(fc)) != EOF)
1792 fputc(c, fp_pgp_in);
1793
1795 }
1796 mutt_file_fclose(&fp_body);
1797 mutt_file_fclose(&fp_pgp_in);
1798
1799 buf_mktemp(pgpoutfile);
1800 FILE *fp_pgp_out = mutt_file_fopen(buf_string(pgpoutfile), "w+");
1801 FILE *fp_pgp_err = mutt_file_mkstemp();
1802 if (!fp_pgp_out || !fp_pgp_err)
1803 {
1804 mutt_perror("%s", fp_pgp_out ? "Can't create temporary file" : buf_string(pgpoutfile));
1805 unlink(buf_string(pgpinfile));
1806 if (fp_pgp_out)
1807 {
1808 mutt_file_fclose(&fp_pgp_out);
1809 unlink(buf_string(pgpoutfile));
1810 }
1811 mutt_file_fclose(&fp_pgp_err);
1812 goto cleanup;
1813 }
1814
1815 pid = pgp_invoke_traditional(&fp_pgp_in, NULL, NULL, -1, fileno(fp_pgp_out),
1816 fileno(fp_pgp_err), buf_string(pgpinfile), keylist, flags);
1817 if (pid == -1)
1818 {
1819 mutt_perror(_("Can't invoke PGP"));
1820 mutt_file_fclose(&fp_pgp_out);
1821 mutt_file_fclose(&fp_pgp_err);
1822 mutt_file_unlink(buf_string(pgpinfile));
1823 unlink(buf_string(pgpoutfile));
1824 goto cleanup;
1825 }
1826
1827 if (pgp_use_gpg_agent())
1828 *mod_data->pgp_pass = '\0';
1829 if (flags & SEC_SIGN)
1830 fprintf(fp_pgp_in, "%s\n", mod_data->pgp_pass);
1831 mutt_file_fclose(&fp_pgp_in);
1832
1833 const bool c_pgp_check_exit = cs_subset_bool(NeoMutt->sub, "pgp_check_exit");
1834 if (filter_wait(pid) && c_pgp_check_exit)
1835 empty = true;
1836
1837 mutt_file_unlink(buf_string(pgpinfile));
1838
1839 fflush(fp_pgp_out);
1840 fflush(fp_pgp_err);
1841
1842 rewind(fp_pgp_out);
1843 rewind(fp_pgp_err);
1844
1845 if (!empty)
1846 empty = (fgetc(fp_pgp_out) == EOF);
1847 mutt_file_fclose(&fp_pgp_out);
1848
1849 err = false;
1850
1851 while (fgets(buf, sizeof(buf), fp_pgp_err))
1852 {
1853 err = true;
1854 fputs(buf, stdout);
1855 }
1856
1857 mutt_file_fclose(&fp_pgp_err);
1858
1859 if (err)
1861
1862 if (empty)
1863 {
1864 if (flags & SEC_SIGN)
1865 pgp_class_void_passphrase(); /* just in case */
1866 unlink(buf_string(pgpoutfile));
1867 goto cleanup;
1868 }
1869
1870 b_enc = mutt_body_new();
1871
1872 b_enc->encoding = ENC_7BIT;
1873
1874 b_enc->type = TYPE_TEXT;
1875 b_enc->subtype = mutt_str_dup("plain");
1876
1877 mutt_param_set(&b_enc->parameter, "x-action",
1878 (flags & SEC_ENCRYPT) ? "pgp-encrypted" : "pgp-signed");
1879 mutt_param_set(&b_enc->parameter, "charset", send_charset);
1880
1881 b_enc->filename = buf_strdup(pgpoutfile);
1882
1883 b_enc->disposition = DISP_NONE;
1884 b_enc->unlink = true;
1885
1886 b_enc->noconv = true;
1887 b_enc->use_disp = false;
1888
1889 if (!(flags & SEC_ENCRYPT))
1890 b_enc->encoding = b->encoding;
1891
1892cleanup:
1893 buf_pool_release(&pgpinfile);
1894 buf_pool_release(&pgpoutfile);
1895 return b_enc;
1896}
1897
1902{
1903 struct PgpKeyInfo *p = NULL;
1904 const char *prompt = NULL;
1905 const char *letters = NULL;
1906 const char *choices = NULL;
1907 char promptbuf[1024] = { 0 };
1908 int choice;
1909
1910 if (!(WithCrypto & APPLICATION_PGP))
1911 return e->security;
1912
1913 /* If autoinline and no crypto options set, then set inline. */
1914 const bool c_pgp_auto_inline = cs_subset_bool(NeoMutt->sub, "pgp_auto_inline");
1915 if (c_pgp_auto_inline &&
1916 !((e->security & APPLICATION_PGP) && (e->security & (SEC_SIGN | SEC_ENCRYPT))))
1917 {
1918 e->security |= SEC_INLINE;
1919 }
1920
1922
1923 char *mime_inline = NULL;
1924 if (e->security & SEC_INLINE)
1925 {
1926 /* L10N: The next string MUST have the same highlighted letter
1927 One of them will appear in each of the three strings marked "(inline"), below. */
1928 mime_inline = _("PGP/M(i)ME");
1929 }
1930 else
1931 {
1932 /* L10N: The previous string MUST have the same highlighted letter
1933 One of them will appear in each of the three strings marked "(inline"), below. */
1934 mime_inline = _("(i)nline");
1935 }
1936 /* Opportunistic encrypt is controlling encryption. Allow to toggle
1937 * between inline and mime, but not turn encryption on or off.
1938 * NOTE: "Signing" and "Clearing" only adjust the sign bit, so we have different
1939 * letter choices for those. */
1940 const bool c_crypt_opportunistic_encrypt = cs_subset_bool(NeoMutt->sub, "crypt_opportunistic_encrypt");
1941 if (c_crypt_opportunistic_encrypt && (e->security & SEC_OPPENCRYPT))
1942 {
1943 if (e->security & (SEC_ENCRYPT | SEC_SIGN))
1944 {
1945 snprintf(promptbuf, sizeof(promptbuf),
1946 /* L10N: PGP options (inline) (opportunistic encryption is on) */
1947 _("PGP (s)ign, sign (a)s, %s format, (c)lear, or (o)ppenc mode off?"),
1948 mime_inline);
1949 prompt = promptbuf;
1950 /* L10N: PGP options (inline) (opportunistic encryption is on)
1951 The 'i' is from the "PGP/M(i)ME" or "(i)nline", above. */
1952 letters = _("saico");
1953 choices = "SaiCo";
1954 }
1955 else
1956 {
1957 /* L10N: PGP options (opportunistic encryption is on) */
1958 prompt = _("PGP (s)ign, sign (a)s, (c)lear, or (o)ppenc mode off?");
1959 /* L10N: PGP options (opportunistic encryption is on) */
1960 letters = _("saco");
1961 choices = "SaCo";
1962 }
1963 }
1964 else if (c_crypt_opportunistic_encrypt)
1965 {
1966 /* Opportunistic encryption option is set, but is toggled off
1967 * for this message. */
1968 /* When the message is not selected for signing or encryption, the toggle
1969 * between PGP/MIME and Traditional doesn't make sense. */
1970 if (e->security & (SEC_ENCRYPT | SEC_SIGN))
1971 {
1972 snprintf(promptbuf, sizeof(promptbuf),
1973 /* L10N: PGP options (inline) (opportunistic encryption is off) */
1974 _("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, %s format, (c)lear, or (o)ppenc mode?"),
1975 mime_inline);
1976 prompt = promptbuf;
1977 /* L10N: PGP options (inline) (opportunistic encryption is off)
1978 The 'i' is from the "PGP/M(i)ME" or "(i)nline", above. */
1979 letters = _("esabico");
1980 choices = "esabicO";
1981 }
1982 else
1983 {
1984 /* L10N: PGP options (opportunistic encryption is off) */
1985 prompt = _("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, (c)lear, or (o)ppenc mode?");
1986 /* L10N: PGP options (opportunistic encryption is off) */
1987 letters = _("esabco");
1988 choices = "esabcO";
1989 }
1990 }
1991 else
1992 {
1993 /* Opportunistic encryption is unset */
1994 if (e->security & (SEC_ENCRYPT | SEC_SIGN))
1995 {
1996 snprintf(promptbuf, sizeof(promptbuf),
1997 /* L10N: PGP options (inline) */
1998 _("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, %s format, or (c)lear?"),
1999 mime_inline);
2000 prompt = promptbuf;
2001 /* L10N: PGP options (inline)
2002 The 'i' is from the "PGP/M(i)ME" or "(i)nline", above. */
2003 letters = _("esabic");
2004 choices = "esabic";
2005 }
2006 else
2007 {
2008 /* L10N: PGP options */
2009 prompt = _("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, or (c)lear?");
2010 /* L10N: PGP options */
2011 letters = _("esabc");
2012 choices = "esabc";
2013 }
2014 }
2015
2016 choice = mw_multi_choice(prompt, letters);
2017 if (choice > 0)
2018 {
2019 switch (choices[choice - 1])
2020 {
2021 case 'a': /* sign (a)s */
2022 OptPgpCheckTrust = false;
2023
2024 p = pgp_ask_for_key(_("Sign as: "), NULL, KEYFLAG_NONE, PGP_SECRING);
2025 if (p)
2026 {
2027 char input_signas[128] = { 0 };
2028 snprintf(input_signas, sizeof(input_signas), "0x%s", pgp_fpr_or_lkeyid(p));
2029 cs_subset_str_string_set(NeoMutt->sub, "pgp_sign_as", input_signas, NULL);
2030 pgp_key_free(&p);
2031
2032 e->security |= SEC_SIGN;
2033
2034 crypt_pgp_void_passphrase(); /* probably need a different passphrase */
2035 }
2036 break;
2037
2038 case 'b': /* (b)oth */
2039 e->security |= (SEC_ENCRYPT | SEC_SIGN);
2040 break;
2041
2042 case 'C':
2043 e->security &= ~SEC_SIGN;
2044 break;
2045
2046 case 'c': /* (c)lear */
2047 e->security &= ~(SEC_ENCRYPT | SEC_SIGN);
2048 break;
2049
2050 case 'e': /* (e)ncrypt */
2051 e->security |= SEC_ENCRYPT;
2052 e->security &= ~SEC_SIGN;
2053 break;
2054
2055 case 'i': /* toggle (i)nline */
2056 e->security ^= SEC_INLINE;
2057 break;
2058
2059 case 'O': /* oppenc mode on */
2062 break;
2063
2064 case 'o': /* oppenc mode off */
2066 break;
2067
2068 case 'S': /* (s)ign in oppenc mode */
2069 e->security |= SEC_SIGN;
2070 break;
2071
2072 case 's': /* (s)ign */
2073 e->security &= ~SEC_ENCRYPT;
2074 e->security |= SEC_SIGN;
2075 break;
2076 }
2077 }
2078
2079 return e->security;
2080}
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition address.c:685
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition address.c:1470
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition address.c:480
Email Address Handling.
GUI display the mailboxes in a side panel.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:168
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:577
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition helpers.c:217
long cs_subset_long(const struct ConfigSubset *sub, const char *name)
Get a long config item by name.
Definition helpers.c:95
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
Convenience wrapper for the config headers.
const char * cc_charset(void)
Get the cached value of $charset.
Convenience wrapper for the core headers.
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition crypt.c:1050
bool crypt_is_numerical_keyid(const char *s)
Is this a numerical keyid.
Definition crypt.c:1484
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition crypt.c:408
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
Definition crypt.c:467
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition crypt.c:504
void crypt_current_time(struct State *state, const char *app_name)
Print the current time.
Definition crypt.c:64
void crypt_convert_to_7bit(struct Body *b)
Convert an email to 7bit encoding.
Definition crypt.c:814
SecurityFlags mutt_is_application_pgp(const struct Body *b)
Does the message use PGP?
Definition crypt.c:548
Signing/encryption multiplexor.
void crypt_pgp_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
Definition cryptglue.c:211
Wrapper around crypto functions.
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition curs_lib.c:174
void mutt_need_hard_redraw(void)
Force a hard refresh.
Definition curs_lib.c:101
void mutt_endwin(void)
Shutdown curses.
Definition curs_lib.c:152
Edit a string.
@ MUTT_COMP_UNBUFFERED
Ignore macro buffer.
Definition wdata.h:49
@ MUTT_COMP_PASS
Password mode (no echo)
Definition wdata.h:48
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition body.c:58
struct Body * mutt_body_new(void)
Create a new Body.
Definition body.c:44
char * mutt_body_get_charset(struct Body *b, char *buf, size_t buflen)
Get a body's character set.
Definition body.c:133
Structs that make up an email.
void mutt_parse_part(FILE *fp, struct Body *b)
Parse a MIME part.
Definition parse.c:1947
struct Body * mutt_read_mime_header(FILE *fp, bool digest)
Parse a MIME header.
Definition parse.c:1484
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition envelope.c:125
bool envlist_set(char ***envp, const char *name, const char *value, bool overwrite)
Set an environment variable.
Definition envlist.c:88
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
Definition file.c:224
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
Definition file.c:678
int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size)
Copy some content from one file to another.
Definition file.c:192
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
Definition file.c:1432
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition file.c:648
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition file.c:156
#define mutt_file_fclose(FP)
Definition file.h:144
#define mutt_file_fopen(PATH, MODE)
Definition file.h:143
@ MUTT_RL_NONE
No flags are set.
Definition file.h:43
bool OptDontHandlePgpKeys
(pseudo) used to extract PGP keys
Definition globals.c:46
bool OptPgpCheckTrust
(pseudo) used by dlg_pgp()
Definition globals.c:55
Global variables.
int pgp_class_application_handler(struct Body *b, struct State *state)
Manage the MIME type "application/pgp" or "application/smime" - Implements CryptModuleSpecs::applicat...
Definition pgp.c:469
int pgp_class_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Decrypt an encrypted MIME part - Implements CryptModuleSpecs::decrypt_mime() -.
Definition pgp.c:1160
int pgp_class_encrypted_handler(struct Body *b, struct State *state)
Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.
Definition pgp.c:1245
char * pgp_class_find_keys(const struct AddressList *addrlist, bool oppenc_mode)
Find the keyids of the recipients of a message - Implements CryptModuleSpecs::find_keys() -.
Definition pgp.c:1462
bool pgp_class_check_traditional(FILE *fp, struct Body *b, bool just_one)
Look for inline (non-MIME) PGP content - Implements CryptModuleSpecs::pgp_check_traditional() -.
Definition pgp.c:866
struct Body * pgp_class_encrypt_message(struct Body *b, char *keylist, bool sign, const struct AddressList *from)
PGP encrypt an email - Implements CryptModuleSpecs::pgp_encrypt_message() -.
Definition pgp.c:1593
void pgp_class_extract_key_from_attachment(FILE *fp, struct Body *b)
Extract PGP key from an attachment - Implements CryptModuleSpecs::pgp_extract_key_from_attachment() -...
Definition pgp.c:1000
void pgp_class_invoke_getkeys(struct Address *addr)
Run a command to download a PGP key - Implements CryptModuleSpecs::pgp_invoke_getkeys() -.
Definition pgpinvoke.c:315
void pgp_class_invoke_import(const char *fname)
Import a key from a message into the user's public key ring - Implements CryptModuleSpecs::pgp_invoke...
Definition pgpinvoke.c:287
struct Body * pgp_class_traditional_encryptsign(struct Body *b, SecurityFlags flags, char *keylist)
Create an inline PGP encrypted, signed email - Implements CryptModuleSpecs::pgp_traditional_encryptsi...
Definition pgp.c:1728
SecurityFlags pgp_class_send_menu(struct Email *e)
Ask the user whether to sign and/or encrypt the email - Implements CryptModuleSpecs::send_menu() -.
Definition pgp.c:1901
struct Body * pgp_class_sign_message(struct Body *b, const struct AddressList *from)
Cryptographically sign the Body of a message - Implements CryptModuleSpecs::sign_message() -.
Definition pgp.c:1330
bool pgp_class_valid_passphrase(void)
Ensure we have a valid passphrase - Implements CryptModuleSpecs::valid_passphrase() -.
Definition pgp.c:81
int pgp_class_verify_one(struct Body *b, struct State *state, const char *tempfile)
Check a signed MIME part against a signature - Implements CryptModuleSpecs::verify_one() -.
Definition pgp.c:895
void pgp_class_void_passphrase(void)
Forget the cached passphrase - Implements CryptModuleSpecs::void_passphrase() -.
Definition pgp.c:71
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
Definition window.c:502
int mw_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question -.
Definition question.c:62
int mutt_protected_headers_handler(struct Body *b_email, struct State *state)
Handler for protected headers - Implements handler_t -.
Definition crypt.c:1122
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
#define mutt_perror(...)
Definition logging2.h:95
Convenience wrapper for the gui headers.
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Definition handler.c:1664
void mutt_decode_attachment(const struct Body *b, struct State *state)
Decode an email's attachment.
Definition handler.c:1939
Read/write command history from/to a file.
@ HC_OTHER
Miscellaneous strings.
Definition lib.h:61
void mutt_crypt_hook(struct ListHead *list, struct Address *addr)
Find crypto hooks for an Address.
Definition exec.c:319
Hook Commands.
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition list.c:123
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:55
@ ENC_7BIT
7-bit text
Definition mime.h:49
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition mime.h:37
@ TYPE_APPLICATION
Type: 'application/*'.
Definition mime.h:33
@ TYPE_TEXT
Type: 'text/*'.
Definition mime.h:38
@ DISP_ATTACH
Content is attached.
Definition mime.h:63
@ DISP_INLINE
Content is inline.
Definition mime.h:62
@ DISP_NONE
No preferred disposition.
Definition mime.h:65
#define is_multipart(body)
Check if a body part is multipart or a message container.
Definition mime.h:85
@ MODULE_ID_NCRYPT
ModuleNcrypt, Ncrypt
Definition module_api.h:82
void mutt_generate_boundary(struct ParameterList *pl)
Create a unique boundary id for a MIME part.
Definition multipart.c:93
bool mutt_ch_check_charset(const char *cs, bool strict)
Does iconv understand a character set?
Definition charset.c:880
int mutt_ch_fgetconv(struct FgetConv *fc)
Convert a file's character set.
Definition charset.c:966
struct FgetConv * mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags)
Prepare a file for charset conversion.
Definition charset.c:919
char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
Convert a file's charset into a string buffer.
Definition charset.c:1028
void mutt_ch_fgetconv_close(struct FgetConv **ptr)
Close an fgetconv handle.
Definition charset.c:948
#define MUTT_ICONV_NONE
No flags are set.
Definition charset.h:66
#define MUTT_ICONV_HOOK_FROM
apply charset-hooks to fromcode
Definition charset.h:67
#define mutt_ch_is_us_ascii(str)
Definition charset.h:108
time_t mutt_date_add_timeout(time_t now, time_t timeout)
Safely add a timeout to a given time_t value.
Definition date.c:891
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition filter.c:228
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition regex.c:614
void state_attach_puts(struct State *state, const char *t)
Write a string to the state.
Definition state.c:104
void state_prefix_putc(struct State *state, char c)
Write a prefixed character to the state.
Definition state.c:168
#define state_puts(STATE, STR)
Definition state.h:64
#define state_set_prefix(state)
Definition state.h:62
#define state_putc(STATE, STR)
Definition state.h:65
@ STATE_NONE
No flags are set.
Definition state.h:36
@ STATE_VERIFY
Perform signature verification.
Definition state.h:38
@ STATE_DISPLAY
Output is displayed to the user.
Definition state.h:37
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:677
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition string.c:429
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
Definition string.c:556
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:503
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition string.c:586
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
Many unsorted constants and some structs.
int mutt_decode_save_attachment(FILE *fp, struct Body *b, const char *path, StateFlags flags, enum SaveAttach opt)
Decode, then save an attachment.
@ MUTT_SAVE_NONE
Overwrite existing file (the default)
Definition mutt_attach.h:59
API for encryption/signing of emails.
uint16_t SecurityFlags
Definition lib.h:104
@ SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition lib.h:100
@ SEC_SIGN
Email is signed.
Definition lib.h:93
@ SEC_INLINE
Email has an inline signature.
Definition lib.h:99
@ SEC_ENCRYPT
Email is encrypted.
Definition lib.h:92
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition lib.h:106
#define PGP_ENCRYPT
Email is PGP encrypted.
Definition lib.h:112
@ KEYFLAG_NONE
No flags are set.
Definition lib.h:146
@ KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition lib.h:148
@ KEYFLAG_SUBKEY
Key is a subkey.
Definition lib.h:154
#define WithCrypto
Definition lib.h:132
Ncrypt private Module data.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition parameter.c:111
char * pgp_long_keyid(struct PgpKeyInfo *k)
Get a key's long id.
Definition pgp.c:162
char * pgp_this_keyid(struct PgpKeyInfo *k)
Get the ID of this key.
Definition pgp.c:188
static struct Body * pgp_decrypt_part(struct Body *a, struct State *state, FILE *fp_out, struct Body *p)
Decrypt part of a PGP message.
Definition pgp.c:1023
static char * pgp_fingerprint(struct PgpKeyInfo *k)
Get the key's fingerprint.
Definition pgp.c:213
static int pgp_check_pgp_decryption_okay_regex(FILE *fp_in)
Check PGP output to look for successful outcome.
Definition pgp.c:300
char * pgp_keyid(struct PgpKeyInfo *k)
Get the ID of the main (parent) key.
Definition pgp.c:201
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition pgp.c:231
static struct PgpKeyInfo * key_parent(struct PgpKeyInfo *k)
Find a key's parent (if it's a subkey)
Definition pgp.c:148
static int pgp_copy_checksig(FILE *fp_in, FILE *fp_out)
Copy PGP output and look for signs of a good signature.
Definition pgp.c:248
char * pgp_short_keyid(struct PgpKeyInfo *k)
Get a key's short id.
Definition pgp.c:174
static void pgp_copy_clearsigned(FILE *fp_in, struct State *state, char *charset)
Copy a clearsigned message, stripping the signature.
Definition pgp.c:421
static void pgp_extract_keys_from_attachment(FILE *fp, struct Body *b)
Extract pgp keys from messages/attachments.
Definition pgp.c:968
bool pgp_use_gpg_agent(void)
Does the user want to use the gpg agent?
Definition pgp.c:124
static int pgp_check_decryption_okay(FILE *fp_in)
Check GPG output for status codes.
Definition pgp.c:354
static bool pgp_check_traditional_one_body(FILE *fp, struct Body *b)
Check the body of an inline PGP message.
Definition pgp.c:799
PGP sign, encrypt, check routines.
pid_t pgp_invoke_encrypt(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *fname, const char *uids, bool sign)
Use PGP to encrypt a file.
Definition pgpinvoke.c:229
pid_t pgp_invoke_decode(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *fname, bool need_passphrase)
Use PGP to decode a message.
Definition pgpinvoke.c:132
pid_t pgp_invoke_traditional(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *fname, const char *uids, SecurityFlags flags)
Use PGP to create in inline-signed message.
Definition pgpinvoke.c:264
pid_t pgp_invoke_sign(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *fname)
Use PGP to sign a file.
Definition pgpinvoke.c:204
pid_t pgp_invoke_verify(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *fname, const char *sig_fname)
Use PGP to verify a message.
Definition pgpinvoke.c:157
pid_t pgp_invoke_decrypt(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, const char *fname)
Use PGP to decrypt a file.
Definition pgpinvoke.c:181
Wrapper around calls to external PGP program.
struct PgpKeyInfo * pgp_ask_for_key(char *tag, const char *whatfor, KeyFlags abilities, enum PgpRing keyring)
Ask the user for a PGP key.
Definition pgpkey.c:202
struct PgpKeyInfo * pgp_getkeybyaddr(struct Address *a, KeyFlags abilities, enum PgpRing keyring, bool oppenc_mode)
Find a PGP key by address.
Definition pgpkey.c:379
struct PgpKeyInfo * pgp_getkeybystr(const char *cp, KeyFlags abilities, enum PgpRing keyring)
Find a PGP key by string.
Definition pgpkey.c:518
PGP key management routines.
@ PGP_SECRING
Secret keys.
Definition pgpkey.h:41
@ PGP_PUBRING
Public keys.
Definition pgpkey.h:40
void pgp_key_free(struct PgpKeyInfo **kpp)
Free a PGP key info.
Definition pgplib.c:201
Misc PGP helper routines.
const char * pgp_micalg(const char *fname)
Find the hash algorithm of a file.
Definition pgpmicalg.c:228
Identify the hash algorithm from a PGP signature.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
QuadOption
Possible values for a quad-option.
Definition quad.h:36
@ MUTT_ABORT
User aborted the question (with Ctrl-G)
Definition quad.h:37
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition quad.h:38
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition quad.h:39
Ask the user a question.
enum QuadOption query_yesorno_help(const char *prompt, enum QuadOption def, struct ConfigSubset *sub, const char *name)
Ask the user a Yes/No question offering help.
Definition question.c:357
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
#define STAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
#define STAILQ_FIRST(head)
Definition queue.h:388
#define TAILQ_FIRST(head)
Definition queue.h:780
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:694
#define STAILQ_NEXT(elm, field)
Definition queue.h:439
int mutt_write_mime_body(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Definition body.c:302
int mutt_write_mime_header(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Create a MIME header.
Definition header.c:757
Convenience wrapper for the send headers.
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition sendlib.c:713
An email address.
Definition address.h:35
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
The body of an email.
Definition body.h:36
char * d_filename
filename to be used for the content-disposition header If NULL, filename is used instead.
Definition body.h:56
struct Body * parts
parts of a multipart or message/rfc822
Definition body.h:73
LOFF_T offset
offset where the actual data begins
Definition body.h:52
bool noconv
Don't do character set conversion.
Definition body.h:46
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition body.h:68
struct Envelope * mime_headers
Memory hole protected headers.
Definition body.h:76
LOFF_T length
length (in bytes) of attachment
Definition body.h:53
struct ParameterList parameter
Parameters of the content-type.
Definition body.h:63
bool use_disp
Content-Disposition uses filename= ?
Definition body.h:47
unsigned int disposition
content-disposition, ContentDisposition
Definition body.h:42
struct Body * next
next attachment in the list
Definition body.h:72
char * subtype
content-type subtype
Definition body.h:61
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition body.h:41
bool goodsig
Good cryptographic signature.
Definition body.h:45
unsigned int type
content-type primary type, ContentType
Definition body.h:40
char * filename
When sending a message, this is the file to which this structure refers.
Definition body.h:59
String manipulation buffer.
Definition buffer.h:36
The envelope/body of an email.
Definition email.h:39
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition email.h:43
Cursor for converting a file's encoding.
Definition charset.h:45
FILE * fp
File to read from.
Definition charset.h:46
char * p
Current position in output buffer.
Definition charset.h:50
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
Ncrypt private Module data.
Definition module_data.h:39
char pgp_pass[1024]
Cached PGP Passphrase.
Definition module_data.h:51
time_t pgp_exptime
Unix time when pgp_pass expires.
Definition module_data.h:52
Container for Accounts, Notifications.
Definition neomutt.h:41
char ** env
Private copy of the environment variables.
Definition neomutt.h:57
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
Information about a PGP key.
Definition pgplib.h:49
char * keyid
Key ID.
Definition pgplib.h:50
KeyFlags flags
Key flags.
Definition pgplib.h:53
char * fingerprint
Key fingerprint.
Definition pgplib.h:51
struct PgpKeyInfo * parent
Parent key.
Definition pgplib.h:58
Cached regular expression.
Definition regex3.h:85
regex_t * regex
compiled expression
Definition regex3.h:87
Keep track when processing files.
Definition state.h:54
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition state.h:58
FILE * fp_out
File to write to.
Definition state.h:56
FILE * fp_in
File to read from.
Definition state.h:55
const char * prefix
String to add to the beginning of each output line.
Definition state.h:57
int cs_subset_str_string_set(const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition subset.c:392
#define buf_mktemp(buf)
Definition tmp.h:33
#define mutt_file_mkstemp()
Definition tmp.h:36