2 * Copyright (C) 2001,2002 Oliver Ehli <elmy@acm.org>
3 * Copyright (C) 2002 Mike Schiraldi <raldi@research.netsol.com>
4 * Copyright (C) 2004 g10 Code GmbH
6 * This program 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 2 of the License, or
9 * (at your option) any later version.
11 * This program 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "mutt_curses.h"
27 #include "mutt_menu.h"
44 #ifdef HAVE_SYS_TIME_H
45 # include <sys/time.h>
48 #ifdef HAVE_SYS_RESOURCE_H
49 # include <sys/resource.h>
52 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
54 #include "mutt_crypt.h"
56 struct smime_command_context {
57 const char *key; /* %k */
58 const char *cryptalg; /* %a */
59 const char *fname; /* %f */
60 const char *sig_fname; /* %s */
61 const char *certificates; /* %c */
62 const char *intermediates; /* %i */
71 char trust; /* i=Invalid r=revoked e=expired u=unverified v=verified t=trusted */
72 short public; /* 1=public 0=private */
76 char SmimePass[STRING];
77 time_t SmimeExptime = 0; /* when does the cached passphrase expire? */
80 static char SmimeKeyToUse[_POSIX_PATH_MAX] = { 0 };
81 static char SmimeCertToUse[_POSIX_PATH_MAX];
82 static char SmimeIntermediateToUse[_POSIX_PATH_MAX];
86 * Queries and passphrase handling.
92 /* these are copies from pgp.c */
95 void smime_void_passphrase (void)
97 memset (SmimePass, 0, sizeof (SmimePass));
101 int smime_valid_passphrase (void)
103 time_t now = time (NULL);
105 if (now < SmimeExptime)
106 /* Use cached copy. */
109 smime_void_passphrase();
111 if (mutt_get_password (_("Enter S/MIME passphrase:"), SmimePass, sizeof (SmimePass)) == 0)
113 SmimeExptime = time (NULL) + SmimeTimeout;
124 * The OpenSSL interface
127 /* This is almost identical to ppgp's invoking interface. */
129 static const char *_mutt_fmt_smime_command (char *dest,
135 const char *ifstring,
136 const char *elsestring,
141 struct smime_command_context *cctx = (struct smime_command_context *) data;
142 int optional = (flags & M_FORMAT_OPTIONAL);
150 char path[_POSIX_PATH_MAX];
151 char buf1[LONG_STRING], buf2[LONG_STRING];
154 strfcpy (path, NONULL (SmimeCALocation), sizeof (path));
155 mutt_expand_path (path, sizeof (path));
156 mutt_quote_filename (buf1, sizeof (buf1), path);
158 if (stat (path, &sb) != 0 || !S_ISDIR (sb.st_mode))
159 snprintf (buf2, sizeof (buf2), "-CAfile %s", buf1);
161 snprintf (buf2, sizeof (buf2), "-CApath %s", buf1);
163 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
164 snprintf (dest, destlen, fmt, buf2);
166 else if (!SmimeCALocation)
172 { /* certificate (list) */
174 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
175 snprintf (dest, destlen, fmt, NONULL(cctx->certificates));
177 else if (!cctx->certificates)
183 { /* intermediate certificates */
185 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
186 snprintf (dest, destlen, fmt, NONULL(cctx->intermediates));
188 else if (!cctx->intermediates)
194 { /* detached signature */
197 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
198 snprintf (dest, destlen, fmt, NONULL (cctx->sig_fname));
200 else if (!cctx->sig_fname)
209 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
210 snprintf (dest, destlen, fmt, NONULL (cctx->key));
218 { /* algorithm for encryption */
220 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
221 snprintf (dest, destlen, fmt, NONULL (cctx->cryptalg));
229 { /* file to process */
232 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
233 snprintf (dest, destlen, fmt, NONULL (cctx->fname));
235 else if (!cctx->fname)
246 mutt_FormatString (dest, destlen, col, ifstring, _mutt_fmt_smime_command,
248 else if (flags & M_FORMAT_OPTIONAL)
249 mutt_FormatString (dest, destlen, col, elsestring, _mutt_fmt_smime_command,
257 static void mutt_smime_command (char *d, size_t dlen,
258 struct smime_command_context *cctx, const char *fmt)
260 mutt_FormatString (d, dlen, 0, NONULL(fmt), _mutt_fmt_smime_command,
261 (unsigned long) cctx, 0);
262 dprint (2,(debugfile, "mutt_smime_command: %s\n", d));
268 static pid_t smime_invoke (FILE **smimein, FILE **smimeout, FILE **smimeerr,
269 int smimeinfd, int smimeoutfd, int smimeerrfd,
271 const char *sig_fname,
272 const char *cryptalg,
274 const char *certificates,
275 const char *intermediates,
278 struct smime_command_context cctx;
279 char cmd[HUGE_STRING];
281 memset (&cctx, 0, sizeof (cctx));
283 if (!format || !*format)
287 cctx.sig_fname = sig_fname;
289 cctx.cryptalg = cryptalg;
290 cctx.certificates = certificates;
291 cctx.intermediates = intermediates;
293 mutt_smime_command (cmd, sizeof (cmd), &cctx, format);
295 return mutt_create_filter_fd (cmd, smimein, smimeout, smimeerr,
296 smimeinfd, smimeoutfd, smimeerrfd);
305 * Key and certificate handling.
311 Search the certificate index for given mailbox.
312 return certificate file name.
315 static void smime_entry (char *s, size_t l, MUTTMENU * menu, int num)
317 smime_id *Table = (smime_id*) menu->data;
318 smime_id this = Table[num];
322 truststate = N_("Trusted ");
325 truststate = N_("Verified ");
328 truststate = N_("Unverified");
331 truststate = N_("Expired ");
334 truststate = N_("Revoked ");
337 truststate = N_("Invalid ");
340 truststate = N_("Unknown ");
343 snprintf(s, l, " 0x%.8X.%i %s %-35.35s %s", this.hash, this.suffix, truststate, this.email, this.nick);
345 snprintf(s, l, " 0x%.8X.%i %-35.35s %s", this.hash, this.suffix, this.email, this.nick);
352 char* smime_ask_for_key (char *prompt, char *mailbox, short public)
357 char index_file[_POSIX_PATH_MAX];
359 char buf[LONG_STRING];
360 char fields[5][STRING];
361 int numFields, hash_suffix, done, cur; /* The current entry */
364 char helpstr[HUGE_STRING*3];
368 if (!prompt) prompt = _("Enter keyID: ");
369 snprintf(index_file, sizeof (index_file), "%s/.index",
370 public ? NONULL(SmimeCertificates) : NONULL(SmimeKeys));
375 if (mutt_get_field(prompt,
376 qry, sizeof(qry), 0))
378 snprintf(title, sizeof(title), _("S/MIME certificates matching \"%s\"."),
382 index = fopen(index_file, "r");
385 mutt_perror (index_file);
391 while (!feof(index)) {
392 numFields = fscanf (index, MUTT_FORMAT(STRING) " %x.%i " MUTT_FORMAT(STRING), fields[0], &hash,
393 &hash_suffix, fields[2]);
395 fscanf (index, MUTT_FORMAT(STRING) " " MUTT_FORMAT(STRING) "\n", fields[3], fields[4]);
397 /* 0=email 1=name 2=nick 3=intermediate 4=trust */
398 if (numFields < 2) continue;
400 /* Check if query matches this certificate */
401 if (!mutt_stristr(fields[0], qry) &&
402 !mutt_stristr(fields[2], qry))
406 safe_realloc(&table, sizeof(smime_id) * table_count);
407 table[cur].hash = hash;
408 table[cur].suffix = hash_suffix;
409 strncpy(table[cur].email, fields[0], sizeof(table[cur].email));
410 strncpy(table[cur].nick, fields[2], sizeof(table[cur].nick));
411 table[cur].trust = *fields[4];
412 table[cur].public = public;
416 safe_fclose (&index);
418 /* Make Helpstring */
420 mutt_make_help (buf, sizeof (buf), _("Exit "), MENU_SMIME, OP_EXIT);
421 strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
422 mutt_make_help (buf, sizeof (buf), _("Select "), MENU_SMIME,
423 OP_GENERIC_SELECT_ENTRY);
424 strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
425 mutt_make_help (buf, sizeof(buf), _("Help"), MENU_SMIME, OP_HELP);
426 strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
428 /* Create the menu */
429 menu = mutt_new_menu(MENU_SMIME);
431 menu->make_entry = smime_entry;
432 menu->help = helpstr;
435 /* sorting keys might be done later - TODO */
442 switch (mutt_menuLoop (menu)) {
443 case OP_GENERIC_SELECT_ENTRY:
454 if (table_count && hash)
455 safe_asprintf(&fname, "%.8x.%i", table[cur].hash, table[cur].suffix);
458 mutt_menuDestroy (&menu);
460 set_option (OPTNEEDREDRAW);
462 if (fname) return fname;
468 char *smime_get_field_from_db (char *mailbox, char *query, short public, short may_ask)
470 int addr_len, query_len, found = 0, ask = 0, choice = 0;
471 char cert_path[_POSIX_PATH_MAX];
472 char buf[LONG_STRING], prompt[STRING];
473 char fields[5][STRING];
477 char key_trust_level = 0;
480 if(!mailbox && !query) return(NULL);
482 addr_len = mailbox ? mutt_strlen (mailbox) : 0;
483 query_len = query ? mutt_strlen (query) : 0;
487 /* index-file format:
488 mailbox certfile label issuer_certfile trust_flags\n
490 certfile is a hash value generated by openssl.
491 Note that this was done according to the OpenSSL
492 specs on their CA-directory.
495 snprintf (cert_path, sizeof (cert_path), "%s/.index",
496 (public ? NONULL(SmimeCertificates) : NONULL(SmimeKeys)));
498 if (!stat (cert_path, &info))
500 if ((fp = safe_fopen (cert_path, "r")) == NULL)
502 mutt_perror (cert_path);
506 while (fgets (buf, sizeof (buf) - 1, fp) != NULL)
507 if (mailbox && !(mutt_strncasecmp (mailbox, buf, addr_len)))
509 numFields = sscanf (buf,
510 MUTT_FORMAT(STRING) " " MUTT_FORMAT(STRING) " "
511 MUTT_FORMAT(STRING) " " MUTT_FORMAT(STRING) " "
512 MUTT_FORMAT(STRING) "\n",
513 fields[0], fields[1],
514 fields[2], fields[3],
518 if (mailbox && public &&
519 (*fields[4] == 'i' || *fields[4] == 'e' || *fields[4] == 'r'))
524 if (public && *fields[4] == 'u' )
525 snprintf (prompt, sizeof (prompt),
526 _("ID %s is unverified. Do you want to use it for %s ?"),
528 else if (public && *fields[4] == 'v' )
529 snprintf (prompt, sizeof (prompt),
530 _("Use (untrusted!) ID %s for %s ?"),
533 snprintf (prompt, sizeof (prompt), _("Use ID %s for %s ?"),
537 if (may_ask && (choice = mutt_yesorno (prompt, M_NO)) == -1)
544 else if (choice == M_NO)
549 else if (choice == M_YES)
551 strfcpy (key, fields[1], sizeof (key));
559 key_trust_level = *fields[4];
560 strfcpy (key, fields[1], sizeof (key));
566 numFields = sscanf (buf,
567 MUTT_FORMAT(STRING) " " MUTT_FORMAT(STRING) " "
568 MUTT_FORMAT(STRING) " " MUTT_FORMAT(STRING) " "
569 MUTT_FORMAT(STRING) "\n",
570 fields[0], fields[1],
571 fields[2], fields[3],
574 /* query = label: return certificate. */
575 if (numFields >= 3 &&
576 !(mutt_strncasecmp (query, fields[2], query_len)))
579 strfcpy (key, fields[1], sizeof (key));
581 /* query = certificate: return intermediate certificate. */
582 else if (numFields >= 4 &&
583 !(mutt_strncasecmp (query, fields[1], query_len)))
586 strfcpy (key, fields[3], sizeof (key));
594 if (public && *fields[4] == 'u' )
595 snprintf (prompt, sizeof (prompt),
596 _("ID %s is unverified. Do you want to use it for %s ?"),
598 else if (public && *fields[4] == 'v' )
599 snprintf (prompt, sizeof (prompt),
600 _("Use (untrusted!) ID %s for %s ?"),
603 snprintf (prompt, sizeof(prompt), _("Use ID %s for %s ?"), key,
605 choice = mutt_yesorno (prompt, M_NO);
606 if (choice == -1 || choice == M_NO)
609 else if (key_trust_level && may_ask)
611 if (key_trust_level == 'u' )
613 snprintf (prompt, sizeof (prompt),
614 _("ID %s is unverified. Do you want to use it for %s ?"),
616 choice = mutt_yesorno (prompt, M_NO);
620 else if (key_trust_level == 'v' )
622 mutt_error (_("Warning: You have not yet decided to trust ID %s. (any key to continue)"), key);
629 /* Note: safe_strdup ("") returns NULL. */
630 return safe_strdup (key);
637 This sets the '*ToUse' variables for an upcoming decryption, where
638 the reuquired key is different from SmimeDefaultKey.
641 void _smime_getkeys (char *mailbox)
646 k = smime_get_field_from_db (mailbox, NULL, 0, 1);
650 snprintf(buf, sizeof(buf), _("Enter keyID for %s: "),
652 k = smime_ask_for_key(buf, mailbox, 0);
657 /* the key used last time. */
658 if (*SmimeKeyToUse &&
659 !mutt_strcasecmp (k, SmimeKeyToUse + mutt_strlen (SmimeKeys)+1))
664 else smime_void_passphrase ();
666 snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s",
667 NONULL(SmimeKeys), k);
669 snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
670 NONULL(SmimeCertificates), k);
672 if (mutt_strcasecmp (k, SmimeDefaultKey))
673 smime_void_passphrase ();
681 if (!mutt_strcasecmp (SmimeDefaultKey,
682 SmimeKeyToUse + mutt_strlen (SmimeKeys)+1))
685 smime_void_passphrase ();
688 snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s",
689 NONULL (SmimeKeys), NONULL (SmimeDefaultKey));
691 snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
692 NONULL (SmimeCertificates), NONULL (SmimeDefaultKey));
695 void smime_getkeys (ENVELOPE *env)
700 if (option (OPTSDEFAULTDECRYPTKEY) && SmimeDefaultKey && *SmimeDefaultKey)
702 snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s",
703 NONULL (SmimeKeys), SmimeDefaultKey);
705 snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
706 NONULL(SmimeCertificates), SmimeDefaultKey);
711 for (t = env->to; !found && t; t = t->next)
712 if (mutt_addr_is_user (t))
715 _smime_getkeys (t->mailbox);
717 for (t = env->cc; !found && t; t = t->next)
718 if (mutt_addr_is_user (t))
721 _smime_getkeys (t->mailbox);
723 if (!found && (t = mutt_default_from()))
725 _smime_getkeys (t->mailbox);
726 rfc822_free_address (&t);
730 /* This routine attempts to find the keyids of the recipients of a message.
731 * It returns NULL if any of the keys can not be found.
734 char *smime_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
736 char *keyID, *keylist = NULL;
737 size_t keylist_size = 0;
738 size_t keylist_used = 0;
739 ADDRESS *tmp = NULL, *addr = NULL;
740 ADDRESS **last = &tmp;
744 const char *fqdn = mutt_fqdn (1);
746 for (i = 0; i < 3; i++)
750 case 0: p = to; break;
751 case 1: p = cc; break;
752 case 2: p = bcc; break;
756 *last = rfc822_cpy_adr (p, 0);
758 last = &((*last)->next);
762 rfc822_qualify (tmp, fqdn);
764 tmp = mutt_remove_duplicates (tmp);
766 for (p = tmp; p ; p = p->next)
768 char buf[LONG_STRING];
772 if ((keyID = smime_get_field_from_db (q->mailbox, NULL, 1, 1)) == NULL)
774 snprintf(buf, sizeof(buf),
775 _("Enter keyID for %s: "),
777 keyID = smime_ask_for_key(buf, q->mailbox, 1);
781 mutt_message (_("No (valid) certificate found for %s."), q->mailbox);
783 rfc822_free_address (&tmp);
784 rfc822_free_address (&addr);
788 keylist_size += mutt_strlen (keyID) + 2;
789 safe_realloc (&keylist, keylist_size);
790 sprintf (keylist + keylist_used, "%s\n", keyID); /* __SPRINTF_CHECKED__ */
791 keylist_used = mutt_strlen (keylist);
793 rfc822_free_address (&addr);
796 rfc822_free_address (&tmp);
805 static int smime_handle_cert_email (char *certificate, char *mailbox,
806 int copy, char ***buffer, int *num)
808 FILE *fpout = NULL, *fperr = NULL;
809 char tmpfname[_POSIX_PATH_MAX];
811 int ret = -1, count = 0;
814 mutt_mktemp (tmpfname, sizeof (tmpfname));
815 if ((fperr = safe_fopen (tmpfname, "w+")) == NULL)
817 mutt_perror (tmpfname);
820 mutt_unlink (tmpfname);
822 mutt_mktemp (tmpfname, sizeof (tmpfname));
823 if ((fpout = safe_fopen (tmpfname, "w+")) == NULL)
825 safe_fclose (&fperr);
826 mutt_perror (tmpfname);
829 mutt_unlink (tmpfname);
831 if ((thepid = smime_invoke (NULL, NULL, NULL,
832 -1, fileno (fpout), fileno (fperr),
833 certificate, NULL, NULL, NULL, NULL, NULL,
834 SmimeGetCertEmailCommand))== -1)
836 mutt_message (_("Error: unable to create OpenSSL subprocess!"));
837 safe_fclose (&fperr);
838 safe_fclose (&fpout);
842 mutt_wait_filter (thepid);
850 while ((fgets (email, sizeof (email), fpout)))
852 *(email + mutt_strlen (email)-1) = '\0';
853 if(mutt_strncasecmp (email, mailbox, mutt_strlen (mailbox)) == 0)
856 ret = ret < 0 ? 0 : ret;
863 mutt_copy_stream (fperr, stdout);
864 mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
871 if(copy && buffer && num)
874 *buffer = safe_calloc(sizeof(char*), count);
878 while ((fgets (email, sizeof (email), fpout)))
880 *(email + mutt_strlen (email) - 1) = '\0';
881 (*buffer)[count] = safe_calloc(1, mutt_strlen (email) + 1);
882 strncpy((*buffer)[count], email, mutt_strlen (email));
886 else if(copy) ret = 2;
888 safe_fclose (&fpout);
889 safe_fclose (&fperr);
896 static char *smime_extract_certificate (char *infile)
898 FILE *fpout = NULL, *fperr = NULL;
899 char pk7out[_POSIX_PATH_MAX], certfile[_POSIX_PATH_MAX];
900 char tmpfname[_POSIX_PATH_MAX];
905 mutt_mktemp (tmpfname, sizeof (tmpfname));
906 if ((fperr = safe_fopen (tmpfname, "w+")) == NULL)
908 mutt_perror (tmpfname);
911 mutt_unlink (tmpfname);
913 mutt_mktemp (pk7out, sizeof (pk7out));
914 if ((fpout = safe_fopen (pk7out, "w+")) == NULL)
916 safe_fclose (&fperr);
917 mutt_perror (pk7out);
921 /* Step 1: Convert the signature to a PKCS#7 structure, as we can't
922 extract the full set of certificates directly.
924 if ((thepid = smime_invoke (NULL, NULL, NULL,
925 -1, fileno (fpout), fileno (fperr),
926 infile, NULL, NULL, NULL, NULL, NULL,
927 SmimePk7outCommand))== -1)
929 mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
930 safe_fclose (&fperr);
931 safe_fclose (&fpout);
932 mutt_unlink (pk7out);
936 mutt_wait_filter (thepid);
943 empty = (fgetc (fpout) == EOF);
946 mutt_perror (pk7out);
947 mutt_copy_stream (fperr, stdout);
948 safe_fclose (&fpout);
949 safe_fclose (&fperr);
950 mutt_unlink (pk7out);
956 safe_fclose (&fpout);
957 mutt_mktemp (certfile, sizeof (certfile));
958 if ((fpout = safe_fopen (certfile, "w+")) == NULL)
960 safe_fclose (&fperr);
961 mutt_unlink (pk7out);
962 mutt_perror (certfile);
966 /* Step 2: Extract the certificates from a PKCS#7 structure.
968 if ((thepid = smime_invoke (NULL, NULL, NULL,
969 -1, fileno (fpout), fileno (fperr),
970 pk7out, NULL, NULL, NULL, NULL, NULL,
971 SmimeGetCertCommand))== -1)
973 mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
974 safe_fclose (&fperr);
975 safe_fclose (&fpout);
976 mutt_unlink (pk7out);
977 mutt_unlink (certfile);
981 mutt_wait_filter (thepid);
983 mutt_unlink (pk7out);
989 empty = (fgetc (fpout) == EOF);
992 mutt_copy_stream (fperr, stdout);
993 safe_fclose (&fpout);
994 safe_fclose (&fperr);
995 mutt_unlink (certfile);
999 safe_fclose (&fpout);
1000 safe_fclose (&fperr);
1002 return safe_strdup (certfile);
1005 static char *smime_extract_signer_certificate (char *infile)
1007 FILE *fpout = NULL, *fperr = NULL;
1008 char pk7out[_POSIX_PATH_MAX], certfile[_POSIX_PATH_MAX];
1009 char tmpfname[_POSIX_PATH_MAX];
1014 mutt_mktemp (tmpfname, sizeof (tmpfname));
1015 if ((fperr = safe_fopen (tmpfname, "w+")) == NULL)
1017 mutt_perror (tmpfname);
1020 mutt_unlink (tmpfname);
1023 mutt_mktemp (certfile, sizeof (certfile));
1024 if ((fpout = safe_fopen (certfile, "w+")) == NULL)
1026 safe_fclose (&fperr);
1027 mutt_perror (certfile);
1031 /* Extract signer's certificate
1033 if ((thepid = smime_invoke (NULL, NULL, NULL,
1034 -1, -1, fileno (fperr),
1035 infile, NULL, NULL, NULL, certfile, NULL,
1036 SmimeGetSignerCertCommand))== -1)
1038 mutt_any_key_to_continue (_("Error: unable to create OpenSSL subprocess!"));
1039 safe_fclose (&fperr);
1040 safe_fclose (&fpout);
1041 mutt_unlink (pk7out);
1042 mutt_unlink (certfile);
1046 mutt_wait_filter (thepid);
1052 empty = (fgetc (fpout) == EOF);
1056 mutt_copy_stream (fperr, stdout);
1057 mutt_any_key_to_continue (NULL);
1058 safe_fclose (&fpout);
1059 safe_fclose (&fperr);
1060 mutt_unlink (certfile);
1064 safe_fclose (&fpout);
1065 safe_fclose (&fperr);
1067 return safe_strdup (certfile);
1073 /* Add a certificate and update index file (externally). */
1075 void smime_invoke_import (char *infile, char *mailbox)
1077 char tmpfname[_POSIX_PATH_MAX], *certfile = NULL, buf[STRING];
1078 FILE *smimein=NULL, *fpout = NULL, *fperr = NULL;
1081 mutt_mktemp (tmpfname, sizeof (tmpfname));
1082 if ((fperr = safe_fopen (tmpfname, "w+")) == NULL)
1084 mutt_perror (tmpfname);
1087 mutt_unlink (tmpfname);
1089 mutt_mktemp (tmpfname, sizeof (tmpfname));
1090 if ((fpout = safe_fopen (tmpfname, "w+")) == NULL)
1092 safe_fclose (&fperr);
1093 mutt_perror (tmpfname);
1096 mutt_unlink (tmpfname);
1100 if (option (OPTASKCERTLABEL))
1101 mutt_get_field ("Label for certificate:", buf, sizeof (buf), 0);
1104 if ((certfile = smime_extract_certificate(infile)))
1108 if ((thepid = smime_invoke (&smimein, NULL, NULL,
1109 -1, fileno(fpout), fileno(fperr),
1110 certfile, NULL, NULL, NULL, NULL, NULL,
1111 SmimeImportCertCommand))== -1)
1113 mutt_message (_("Error: unable to create OpenSSL subprocess!"));
1116 fputs (buf, smimein);
1117 fputc ('\n', smimein);
1118 safe_fclose (&smimein);
1120 mutt_wait_filter (thepid);
1122 mutt_unlink (certfile);
1131 mutt_copy_stream (fpout, stdout);
1132 mutt_copy_stream (fperr, stdout);
1134 safe_fclose (&fpout);
1135 safe_fclose (&fperr);
1141 int smime_verify_sender(HEADER *h)
1143 char *mbox = NULL, *certfile, tempfname[_POSIX_PATH_MAX];
1147 mutt_mktemp (tempfname, sizeof (tempfname));
1148 if (!(fpout = safe_fopen (tempfname, "w")))
1150 mutt_perror (tempfname);
1154 if(h->security & ENCRYPT)
1155 mutt_copy_message (fpout, Context, h,
1156 M_CM_DECODE_CRYPT & M_CM_DECODE_SMIME,
1157 CH_MIME|CH_WEED|CH_NONEWLINE);
1159 mutt_copy_message (fpout, Context, h, 0, 0);
1162 safe_fclose (&fpout);
1166 h->env->from = mutt_expand_aliases (h->env->from);
1167 mbox = h->env->from->mailbox;
1169 else if (h->env->sender)
1171 h->env->sender = mutt_expand_aliases (h->env->sender);
1172 mbox = h->env->sender->mailbox;
1177 if ((certfile = smime_extract_signer_certificate(tempfname)))
1179 mutt_unlink(tempfname);
1180 if (smime_handle_cert_email (certfile, mbox, 0, NULL, NULL))
1183 mutt_any_key_to_continue(NULL);
1187 mutt_unlink(certfile);
1191 mutt_any_key_to_continue(_("no certfile"));
1194 mutt_any_key_to_continue(_("no mbox"));
1196 mutt_unlink(tempfname);
1209 * Creating S/MIME - bodies.
1216 pid_t smime_invoke_encrypt (FILE **smimein, FILE **smimeout, FILE **smimeerr,
1217 int smimeinfd, int smimeoutfd, int smimeerrfd,
1218 const char *fname, const char *uids)
1220 return smime_invoke (smimein, smimeout, smimeerr,
1221 smimeinfd, smimeoutfd, smimeerrfd,
1222 fname, NULL, SmimeCryptAlg, NULL, uids, NULL,
1223 SmimeEncryptCommand);
1228 pid_t smime_invoke_sign (FILE **smimein, FILE **smimeout, FILE **smimeerr,
1229 int smimeinfd, int smimeoutfd, int smimeerrfd,
1232 return smime_invoke (smimein, smimeout, smimeerr, smimeinfd, smimeoutfd,
1233 smimeerrfd, fname, NULL, NULL, SmimeKeyToUse,
1234 SmimeCertToUse, SmimeIntermediateToUse,
1241 BODY *smime_build_smime_entity (BODY *a, char *certlist)
1243 char buf[LONG_STRING], certfile[LONG_STRING];
1244 char tempfile[_POSIX_PATH_MAX], smimeerrfile[_POSIX_PATH_MAX];
1245 char smimeinfile[_POSIX_PATH_MAX];
1246 char *cert_start = certlist, *cert_end = certlist;
1247 FILE *smimein = NULL, *smimeerr = NULL, *fpout = NULL, *fptmp = NULL;
1252 mutt_mktemp (tempfile, sizeof (tempfile));
1253 if ((fpout = safe_fopen (tempfile, "w+")) == NULL)
1255 mutt_perror (tempfile);
1259 mutt_mktemp (smimeerrfile, sizeof (smimeerrfile));
1260 if ((smimeerr = safe_fopen (smimeerrfile, "w+")) == NULL)
1262 mutt_perror (smimeerrfile);
1263 safe_fclose (&fpout);
1264 mutt_unlink (tempfile);
1267 mutt_unlink (smimeerrfile);
1269 mutt_mktemp (smimeinfile, sizeof (smimeinfile));
1270 if ((fptmp = safe_fopen (smimeinfile, "w+")) == NULL)
1272 mutt_perror (smimeinfile);
1273 mutt_unlink (tempfile);
1274 safe_fclose (&fpout);
1275 safe_fclose (&smimeerr);
1282 int off = mutt_strlen (certfile);
1283 while (*++cert_end && *cert_end != '\n');
1284 if (!*cert_end) break;
1286 snprintf (certfile+off, sizeof (certfile)-off, " %s/%s",
1287 NONULL(SmimeCertificates), cert_start);
1289 cert_start = cert_end;
1293 /* write a MIME entity */
1294 mutt_write_mime_header (a, fptmp);
1295 fputc ('\n', fptmp);
1296 mutt_write_mime_body (a, fptmp);
1297 safe_fclose (&fptmp);
1300 smime_invoke_encrypt (&smimein, NULL, NULL, -1,
1301 fileno (fpout), fileno (smimeerr),
1302 smimeinfile, certfile)) == -1)
1304 safe_fclose (&smimeerr);
1305 mutt_unlink (smimeinfile);
1306 mutt_unlink (certfile);
1310 safe_fclose (&smimein);
1312 mutt_wait_filter (thepid);
1313 mutt_unlink (smimeinfile);
1314 mutt_unlink (certfile);
1318 empty = (fgetc (fpout) == EOF);
1319 safe_fclose (&fpout);
1323 while (fgets (buf, sizeof (buf) - 1, smimeerr) != NULL)
1326 fputs (buf, stdout);
1328 safe_fclose (&smimeerr);
1330 /* pause if there is any error output from SMIME */
1332 mutt_any_key_to_continue (NULL);
1336 /* fatal error while trying to encrypt message */
1337 if (!err) mutt_any_key_to_continue _("No output from OpenSSL..");
1338 mutt_unlink (tempfile);
1342 t = mutt_new_body ();
1343 t->type = TYPEAPPLICATION;
1344 t->subtype = safe_strdup ("x-pkcs7-mime");
1345 mutt_set_parameter ("name", "smime.p7m", &t->parameter);
1346 mutt_set_parameter ("smime-type", "enveloped-data", &t->parameter);
1347 t->encoding = ENCBASE64; /* The output of OpenSSL SHOULD be binary */
1349 t->disposition = DISPATTACH;
1350 t->d_filename = safe_strdup ("smime.p7m");
1351 t->filename = safe_strdup (tempfile);
1352 t->unlink = 1; /*delete after sending the message */
1362 BODY *smime_sign_message (BODY *a )
1365 char buffer[LONG_STRING];
1366 char signedfile[_POSIX_PATH_MAX], filetosign[_POSIX_PATH_MAX];
1367 FILE *smimein = NULL, *smimeout = NULL, *smimeerr = NULL, *sfp = NULL;
1371 char *intermediates = smime_get_field_from_db(NULL, SmimeDefaultKey, 1, 1);
1373 if (!SmimeDefaultKey)
1375 mutt_error _("Can't sign: No key specified. Use Sign As.");
1376 FREE (&intermediates);
1382 mutt_message(_("Warning: Intermediate certificate not found."));
1383 intermediates = SmimeDefaultKey; /* so openssl won't complain in any case */
1386 convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */
1388 mutt_mktemp (filetosign, sizeof (filetosign));
1389 if ((sfp = safe_fopen (filetosign, "w+")) == NULL)
1391 mutt_perror (filetosign);
1392 if (intermediates != SmimeDefaultKey)
1393 FREE (&intermediates);
1397 mutt_mktemp (signedfile, sizeof (signedfile));
1398 if ((smimeout = safe_fopen (signedfile, "w+")) == NULL)
1400 mutt_perror (signedfile);
1402 mutt_unlink (filetosign);
1403 if (intermediates != SmimeDefaultKey)
1404 FREE (&intermediates);
1408 mutt_write_mime_header (a, sfp);
1410 mutt_write_mime_body (a, sfp);
1415 snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s",
1416 NONULL(SmimeKeys), SmimeDefaultKey);
1418 snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
1419 NONULL(SmimeCertificates), SmimeDefaultKey);
1421 snprintf (SmimeIntermediateToUse, sizeof (SmimeIntermediateToUse), "%s/%s",
1422 NONULL(SmimeCertificates), intermediates);
1426 if ((thepid = smime_invoke_sign (&smimein, NULL, &smimeerr,
1427 -1, fileno (smimeout), -1, filetosign)) == -1)
1429 mutt_perror _("Can't open OpenSSL subprocess!");
1430 safe_fclose (&smimeout);
1431 mutt_unlink (signedfile);
1432 mutt_unlink (filetosign);
1433 if (intermediates != SmimeDefaultKey)
1434 FREE (&intermediates);
1437 fputs (SmimePass, smimein);
1438 fputc ('\n', smimein);
1439 safe_fclose (&smimein);
1442 mutt_wait_filter (thepid);
1444 /* check for errors from OpenSSL */
1448 while (fgets (buffer, sizeof (buffer) - 1, smimeerr) != NULL)
1451 fputs (buffer, stdout);
1453 safe_fclose (&smimeerr);
1458 empty = (fgetc (smimeout) == EOF);
1459 safe_fclose (&smimeout);
1461 mutt_unlink (filetosign);
1465 mutt_any_key_to_continue (NULL);
1469 mutt_any_key_to_continue _("No output from OpenSSL...");
1470 mutt_unlink (signedfile);
1471 return (NULL); /* fatal error while signing */
1474 t = mutt_new_body ();
1475 t->type = TYPEMULTIPART;
1476 t->subtype = safe_strdup ("signed");
1477 t->encoding = ENC7BIT;
1479 t->disposition = DISPINLINE;
1481 mutt_generate_boundary (&t->parameter);
1482 /* check if this can be extracted from private key somehow.... */
1483 mutt_set_parameter ("micalg", "sha1", &t->parameter);
1484 mutt_set_parameter ("protocol", "application/x-pkcs7-signature",
1490 t->parts->next = mutt_new_body ();
1492 t->type = TYPEAPPLICATION;
1493 t->subtype = safe_strdup ("x-pkcs7-signature");
1494 t->filename = safe_strdup (signedfile);
1495 t->d_filename = safe_strdup ("smime.p7s");
1497 t->disposition = DISPATTACH;
1498 t->encoding = ENCBASE64;
1499 t->unlink = 1; /* ok to remove this file after sending. */
1511 * Handling S/MIME - bodies.
1520 pid_t smime_invoke_verify (FILE **smimein, FILE **smimeout, FILE **smimeerr,
1521 int smimeinfd, int smimeoutfd, int smimeerrfd,
1522 const char *fname, const char *sig_fname, int opaque)
1524 return smime_invoke (smimein, smimeout, smimeerr, smimeinfd, smimeoutfd,
1525 smimeerrfd, fname, sig_fname, NULL, NULL, NULL, NULL,
1526 (opaque ? SmimeVerifyOpaqueCommand : SmimeVerifyCommand));
1531 pid_t smime_invoke_decrypt (FILE **smimein, FILE **smimeout, FILE **smimeerr,
1532 int smimeinfd, int smimeoutfd, int smimeerrfd,
1535 return smime_invoke (smimein, smimeout, smimeerr, smimeinfd, smimeoutfd,
1536 smimeerrfd, fname, NULL, NULL, SmimeKeyToUse,
1537 SmimeCertToUse, NULL, SmimeDecryptCommand);
1542 int smime_verify_one (BODY *sigbdy, STATE *s, const char *tempfile)
1544 char signedfile[_POSIX_PATH_MAX], smimeerrfile[_POSIX_PATH_MAX];
1545 FILE *fp=NULL, *smimeout=NULL, *smimeerr=NULL;
1550 size_t tmplength = 0;
1551 int origType = sigbdy->type;
1552 char *savePrefix = NULL;
1555 snprintf (signedfile, sizeof (signedfile), "%s.sig", tempfile);
1557 /* decode to a tempfile, saving the original destination */
1559 if ((s->fpout = safe_fopen (signedfile, "w")) == NULL)
1561 mutt_perror (signedfile);
1564 /* decoding the attachment changes the size and offset, so save a copy
1565 * of the "real" values now, and restore them after processing
1567 tmplength = sigbdy->length;
1568 tmpoffset = sigbdy->offset;
1570 /* if we are decoding binary bodies, we don't want to prefix each
1571 * line with the prefix or else the data will get corrupted.
1573 savePrefix = s->prefix;
1576 mutt_decode_attachment (sigbdy, s);
1578 sigbdy->length = ftello (s->fpout);
1580 safe_fclose (&s->fpout);
1582 /* restore final destination and substitute the tempfile for input */
1585 s->fpin = fopen (signedfile, "r");
1587 /* restore the prefix */
1588 s->prefix = savePrefix;
1590 sigbdy->type = origType;
1593 mutt_mktemp (smimeerrfile, sizeof (smimeerrfile));
1594 if (!(smimeerr = safe_fopen (smimeerrfile, "w+")))
1596 mutt_perror (smimeerrfile);
1597 mutt_unlink (signedfile);
1601 crypt_current_time (s, "OpenSSL");
1603 if ((thepid = smime_invoke_verify (NULL, &smimeout, NULL,
1604 -1, -1, fileno (smimeerr),
1605 tempfile, signedfile, 0)) != -1)
1608 safe_fclose (&smimeout);
1610 if (mutt_wait_filter (thepid))
1621 line = mutt_read_line (line, &linelen, smimeerr, &lineno, 0);
1622 if (linelen && !ascii_strcasecmp (line, "verification successful"))
1631 mutt_copy_stream (smimeerr, s->fpout);
1632 safe_fclose (&smimeerr);
1634 state_attach_puts (_("[-- End of OpenSSL output --]\n\n"), s);
1636 mutt_unlink (signedfile);
1637 mutt_unlink (smimeerrfile);
1639 sigbdy->length = tmplength;
1640 sigbdy->offset = tmpoffset;
1642 /* restore the original source stream */
1643 safe_fclose (&s->fpin);
1655 This handles application/pkcs7-mime which can either be a signed
1656 or an encrypted message.
1659 static BODY *smime_handle_entity (BODY *m, STATE *s, FILE *outFile)
1664 char buf[HUGE_STRING];
1665 char outfile[_POSIX_PATH_MAX], errfile[_POSIX_PATH_MAX];
1666 char tmpfname[_POSIX_PATH_MAX];
1667 char tmptmpfname[_POSIX_PATH_MAX];
1668 FILE *smimeout = NULL, *smimein=NULL, *smimeerr=NULL;
1669 FILE *tmpfp=NULL, *tmpfp_buffer=NULL, *fpout=NULL;
1673 unsigned int type = mutt_is_application_smime (m);
1675 if (!(type & APPLICATION_SMIME)) return NULL;
1677 mutt_mktemp (outfile, sizeof (outfile));
1678 if ((smimeout = safe_fopen (outfile, "w+")) == NULL)
1680 mutt_perror (outfile);
1684 mutt_mktemp (errfile, sizeof (errfile));
1685 if ((smimeerr = safe_fopen (errfile, "w+")) == NULL)
1687 mutt_perror (errfile);
1688 safe_fclose (&smimeout); smimeout = NULL;
1691 mutt_unlink (errfile);
1694 mutt_mktemp (tmpfname, sizeof (tmpfname));
1695 if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL)
1697 mutt_perror (tmpfname);
1698 safe_fclose (&smimeout); smimeout = NULL;
1699 safe_fclose (&smimeerr); smimeerr = NULL;
1703 fseeko (s->fpin, m->offset, 0);
1704 last_pos = m->offset;
1706 mutt_copy_bytes (s->fpin, tmpfp, m->length);
1709 safe_fclose (&tmpfp);
1711 if ((type & ENCRYPT) &&
1712 (thepid = smime_invoke_decrypt (&smimein, NULL, NULL, -1,
1713 fileno (smimeout), fileno (smimeerr), tmpfname)) == -1)
1715 safe_fclose (&smimeout); smimeout = NULL;
1716 mutt_unlink (tmpfname);
1717 if (s->flags & M_DISPLAY)
1718 state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s);
1721 else if ((type & SIGNOPAQUE) &&
1722 (thepid = smime_invoke_verify (&smimein, NULL, NULL, -1,
1723 fileno (smimeout), fileno (smimeerr), NULL,
1724 tmpfname, SIGNOPAQUE)) == -1)
1726 safe_fclose (&smimeout); smimeout = NULL;
1727 mutt_unlink (tmpfname);
1728 if (s->flags & M_DISPLAY)
1729 state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s);
1736 if (!smime_valid_passphrase ())
1737 smime_void_passphrase ();
1738 fputs (SmimePass, smimein);
1739 fputc ('\n', smimein);
1742 safe_fclose (&smimein);
1744 mutt_wait_filter (thepid);
1745 mutt_unlink (tmpfname);
1748 if (s->flags & M_DISPLAY)
1753 if ((c = fgetc (smimeerr)) != EOF)
1755 ungetc (c, smimeerr);
1757 crypt_current_time (s, "OpenSSL");
1758 mutt_copy_stream (smimeerr, s->fpout);
1759 state_attach_puts (_("[-- End of OpenSSL output --]\n\n"), s);
1763 state_attach_puts (_("[-- The following data is S/MIME"
1764 " encrypted --]\n"), s);
1766 state_attach_puts (_("[-- The following data is S/MIME signed --]\n"), s);
1774 if (outFile) fpout = outFile;
1777 mutt_mktemp (tmptmpfname, sizeof (tmptmpfname));
1778 if ((fpout = safe_fopen (tmptmpfname, "w+")) == NULL)
1780 mutt_perror(tmptmpfname);
1781 safe_fclose (&smimeout); smimeout = NULL;
1785 while (fgets (buf, sizeof (buf) - 1, smimeout) != NULL)
1787 len = mutt_strlen (buf);
1788 if (len > 1 && buf[len - 2] == '\r')
1799 if ((p = mutt_read_mime_header (fpout, 0)) != NULL)
1801 fstat (fileno (fpout), &info);
1802 p->length = info.st_size - p->offset;
1804 mutt_parse_part (fpout, p);
1808 tmpfp_buffer = s->fpin;
1810 mutt_body_handler (p, s);
1811 s->fpin = tmpfp_buffer;
1815 safe_fclose (&smimeout);
1817 mutt_unlink (outfile);
1821 safe_fclose (&fpout);
1822 mutt_unlink (tmptmpfname);
1827 if (s->flags & M_DISPLAY)
1830 state_attach_puts (_("\n[-- End of S/MIME encrypted data. --]\n"), s);
1832 state_attach_puts (_("\n[-- End of S/MIME signed data. --]\n"), s);
1835 if (type & SIGNOPAQUE)
1843 line = mutt_read_line (line, &linelen, smimeerr, &lineno, 0);
1844 if (linelen && !ascii_strcasecmp (line, "verification successful"))
1850 m->goodsig = p->goodsig;
1851 m->badsig = p->badsig;
1853 safe_fclose (&smimeerr);
1862 int smime_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur)
1866 char tempfile[_POSIX_PATH_MAX];
1868 long tmpoffset = b->offset;
1869 size_t tmplength = b->length;
1870 int origType = b->type;
1874 if (!mutt_is_application_smime (b))
1880 memset (&s, 0, sizeof (s));
1882 fseeko (s.fpin, b->offset, 0);
1884 mutt_mktemp (tempfile, sizeof (tempfile));
1885 if ((tmpfp = safe_fopen (tempfile, "w+")) == NULL)
1887 mutt_perror (tempfile);
1891 mutt_unlink (tempfile);
1893 mutt_decode_attachment (b, &s);
1895 b->length = ftello (s.fpout);
1901 mutt_mktemp (tempfile, sizeof (tempfile));
1902 if ((*fpout = safe_fopen (tempfile, "w+")) == NULL)
1904 mutt_perror (tempfile);
1908 mutt_unlink (tempfile);
1910 if (!(*cur = smime_handle_entity (b, &s, *fpout)))
1916 (*cur)->goodsig = b->goodsig;
1917 (*cur)->badsig = b->badsig;
1921 b->length = tmplength;
1922 b->offset = tmpoffset;
1923 safe_fclose (&tmpfp);
1931 int smime_application_smime_handler (BODY *m, STATE *s)
1933 return smime_handle_entity (m, s, NULL) ? 0 : -1;
1936 int smime_send_menu (HEADER *msg, int *redraw)
1940 if (!(WithCrypto & APPLICATION_SMIME))
1941 return msg->security;
1943 switch (mutt_multi_choice (_("S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, or (c)lear? "),
1946 case 1: /* (e)ncrypt */
1947 msg->security |= ENCRYPT;
1948 msg->security &= ~SIGN;
1951 case 3: /* encrypt (w)ith */
1955 msg->security |= ENCRYPT;
1958 /* I use "dra" because "123" is recognized anyway */
1959 switch (mutt_multi_choice (_("Choose algorithm family:"
1960 " 1: DES, 2: RC2, 3: AES,"
1965 switch (choice = mutt_multi_choice (_("1: DES, 2: Triple-DES "),
1969 mutt_str_replace (&SmimeCryptAlg, "des");
1972 mutt_str_replace (&SmimeCryptAlg, "des3");
1978 switch (choice = mutt_multi_choice (_("1: RC2-40, 2: RC2-64, 3: RC2-128 "),
1982 mutt_str_replace (&SmimeCryptAlg, "rc2-40");
1985 mutt_str_replace (&SmimeCryptAlg, "rc2-64");
1988 mutt_str_replace (&SmimeCryptAlg, "rc2-128");
1994 switch (choice = mutt_multi_choice (_("1: AES128, 2: AES192, 3: AES256 "),
1998 mutt_str_replace (&SmimeCryptAlg, "aes128");
2001 mutt_str_replace (&SmimeCryptAlg, "aes192");
2004 mutt_str_replace (&SmimeCryptAlg, "aes256");
2009 case 4: /* (c)lear */
2010 FREE (&SmimeCryptAlg);
2012 case -1: /* Ctrl-G or Enter */
2016 } while (choice == -1);
2020 case 2: /* (s)ign */
2022 if(!SmimeDefaultKey)
2024 *redraw = REDRAW_FULL;
2026 if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0)))
2027 mutt_str_replace (&SmimeDefaultKey, p);
2032 msg->security |= SIGN;
2033 msg->security &= ~ENCRYPT;
2036 case 4: /* sign (a)s */
2038 if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0)))
2040 mutt_str_replace (&SmimeDefaultKey, p);
2042 msg->security |= SIGN;
2044 /* probably need a different passphrase */
2045 crypt_smime_void_passphrase ();
2049 msg->security &= ~SIGN;
2052 *redraw = REDRAW_FULL;
2055 case 5: /* (b)oth */
2056 msg->security |= (ENCRYPT | SIGN);
2059 case 6: /* (f)orget it */
2060 case 7: /* (c)lear */
2065 if (msg->security && msg->security != APPLICATION_SMIME)
2066 msg->security |= APPLICATION_SMIME;
2070 return (msg->security);
2074 #endif /* CRYPT_BACKEND_CLASSIC_SMIME */